Home All Groups Group Topic Archive Search About

DefinePropery with instance keyword...

Author
6 Jun 2006 6:35 PM
Patrick
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

Author
6 Jun 2006 10:01 PM
GhostInAK
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)

Show quote
> 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
>
Author
7 Jun 2006 1:21 PM
Patrick
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

Show quote
"GhostInAK" wrote:

> 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
> >
>
>
>
Author
7 Jun 2006 2:43 PM
Patrick
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???

Show quote
"Patrick" wrote:

> 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
>
> "GhostInAK" wrote:
>
> > 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
> > >
> >
> >
> >

AddThis Social Bookmark Button