DefinePropery with instance keyword...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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)
 
Ok found out it was my DefineProperty that was wrong... i tought that the
ParameterTypes parameter was the "value" parameter (== to return type) ...now
i pass null and everything is back to normal.

Thanks
 
Ok what I am doing is overriding a Property... its seems to work but when i
call GetProperties on my new type that overrides the property... i get two
distinct propertyInfos... and thats not what i want since one inherits the
attributes and the other doesnt... what do i need to do to define a overriden
property???
 
Back
Top