I'd like to get this:
.property instance class [WorldTool.Core]WorldTool.IInputPort SomePort
{
.get instance class [WorldTool.Core]WorldTool.IInputPort WorldTool.Core.Tests.SomeOperatorInstance::get_SomePort()
}
But I'm getting this:
.property class class [WorldTool.Core]WorldTool.IInputPort SomePort
{
.get instance class [WorldTool.Core]WorldTool.IInputPort SomeOperatorInstanceProxy::get_SomePort()
}
Why am I getting ".property class class" and not ".property instance class"? Here's what I'm using to generate it:
private void CreateProperty(TypeBuilder typeBuilder, PropertyInfo propertyInfo)
{
var propertyBuilder = typeBuilder.DefineProperty(propertyInfo.Name,
PropertyAttributes.HasDefault,
propertyInfo.PropertyType,
Type.EmptyTypes);
var methodBuilder = typeBuilder.DefineMethod(GET_PREFIX + propertyInfo.Name,
MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.NewSlot | MethodAttributes.Virtual | MethodAttributes.Final,
propertyInfo.PropertyType,
Type.EmptyTypes);
var methodGenerator = methodBuilder.GetILGenerator();
methodGenerator.DeclareLocal(propertyInfo.PropertyType);
methodGenerator.Emit(OpCodes.Nop);
methodGenerator.Emit(OpCodes.Ldarg_0);
methodGenerator.Emit(OpCodes.Ldstr, propertyInfo.Name);
methodGenerator.Emit(OpCodes.Call, typeof(IInputPort).IsAssignableFrom(propertyInfo.PropertyType) ? GetNamedInputPort : GetNamedOutputPort);
methodGenerator.Emit(OpCodes.Stloc_0);
var targetInstruction = methodGenerator.DefineLabel();
methodGenerator.Emit(OpCodes.Br_S, targetInstruction);
methodGenerator.MarkLabel(targetInstruction);
methodGenerator.Emit(OpCodes.Ldloc_0);
methodGenerator.Emit(OpCodes.Ret);
propertyBuilder.SetGetMethod(methodBuilder);
}
You need to specify the calling conventions when defining the property.
You have:
You need:
And to anybody wishing to repeat my findings, here's the test code I was using:
}