Jan,
On Tue, Apr 20, 2010 at 1:34 PM, Jan <[email protected]> wrote:
> I only have a TypeReference, not the System.Type.
Ah ok, I thought you had as you used typeof. Nevermind then, we can
make it work too. What you have to emit in the end is this:
callvirt instance !0 class BaseClass`1<int32>::GetKey()
But that's not hard. All you have to do is to get a MethodReference or
a MethodDefinition to the open GetKey method, and do something like:
TypeReference int32_ref = ...;
TypeReference open_base_class = ...;
MethodReference open_get_key = ...;
TypeReference base_class_of_int = open_base_class.MakeGenericType (int32_ref);
MethodReference get_key_on_base_class_of_int =
open_get_key.MakeGeneric (base_class_of_int);
And callvirt get_key_ob_base_class_of_int.
MakeGenericType would be defined as:
public static TypeReference MakeGenericType (this TypeReference
self, params TypeReference [] arguments)
{
if (self.GenericParameters.Count != arguments.Length)
throw new ArgumentException ();
var instance = new GenericInstanceType (self);
foreach (var argument in arguments)
instance.GenericArguments.Add (argument);
return instance;
}
and MakeGeneric would be defined as:
public static MethodReference MakeGeneric (this MethodReference
self, TypeReference declaringType)
{
var reference = new MethodReference {
Name = self.Name,
DeclaringType = declaringType,
HasThis = self.HasThis,
ExplicitThis = self.ExplicitThis,
ReturnType = self.ReturnType,
CallingConvention =
MethodCallingConvention.Generic,
};
foreach (var parameter in self.Parameters)
reference.Parameters.Add (new
ParameterDefinition
(parameter.ParameterType));
foreach (var generic_parameter in
self.GenericParameters)
reference.GenericParameters.Add (new
GenericParameter (reference));
return reference;
}
--
Jb Evain <[email protected]>
--
--
mono-cecil
Subscription settings: http://groups.google.com/group/mono-cecil/subscribe?hl=en