Using Mono.Cecil, given this method
private Instruction LoadOnStack(MetadataType type, object value)
{
switch (type)
{
case MetadataType.String:
return _processor.Create(OpCodes.Ldstr, (string) value);
case MetadataType.Int32:
return _processor.Create(OpCodes.Ldc_I4, (Int32) value);
case MetadataType.Int64:
return _processor.Create(OpCodes.Ldc_I8, (Int64) value);
case MetadataType.Boolean:
return _processor.Create(OpCodes.Ldc_I4, (bool) value ? 1 : 0);
}
throw new NotSupportedException("Not a supported primitve parameter type: " + type);
}
How can I create an Instruction
that can load value
, when value
is of type Type
?
I notice when value
is of type Type
that I can test it for it like so :
if (value is TypeReference)
return _processor.Create(???, ???);
But I can not figure out what I need to pass to Create
to get the value to load correctly.
EDIT:
Using this :
if (value is TypeReference)
return _processor.Create(OpCodes.Ldobj, type.Resolve());
Gets me one step closer. It seems to to accept the type. But then when I try to write the assembly, it errors out saying :
System.ArgumentException : Member 'System.Type' is declared in another module and needs to be imported