Re: DefinePropery with instance keyword... by GhostInAK
GhostInAK
Tue Jun 06 17:01:23 CDT 2006
Hello Patrick,
I seem to get my properties defined with the instance keyword (though I dont
know what it leans in IL).
I do:
Dim tFieldBuilder As FieldBuilder = Nothing
Dim tPropertyBuilder As PropertyBuilder = Nothing
Dim tMethodBuilder As MethodBuilder = Nothing
tFieldBuilder = tTypeBuilder.DefineField("sSomeString", tType, FieldAttributes.Private)
tPropertyBuilder = tTypeBuilder.DefineProperty("SomeString", System.Reflection.PropertyAttributes.None,
tType, Nothing)
tMethodBuilder = tTypeBuilder.DefineMethod("get_SomeString", MethodAttributes.Public
Or MethodAttributes.SpecialName, tPropertyBuilder.PropertyType, New Type()
{})
tILGenerator = tMethodBuilder.GetILGenerator
With tILGenerator
.DeclareLocal(tPropertyBuilder.PropertyType)
.Emit(OpCodes.Nop)
.Emit(OpCodes.Ldarg_0)
.Emit(OpCodes.Ldfld, tFieldBuilder)
.Emit(OpCodes.Stloc_0)
.Emit(OpCodes.Ldloc_0)
.Emit(OpCodes.Ret)
End With
tPropertyBuilder.SetGetMethod(tMethodBuilder)
> Is it possible to Define a property with the TypeBuilder and having
> the IL code definition use the instance keyword... seems like code
> generated with the compiler shows this keyword and when i build my own
> types they dont have this keyword...i use Reflector to check that the
> classe generated seems ok..and reflector when in the absence of the
> instance keyword returns and indexer property... im lost here since
> calling GetProperties on my emitted type also returns a PropertyInfo
> indexer...
>
> Thanks
>