c# - Should properties be emitted as methods using Reflection.Emit? -
i'm using types reflection.emit
namespace generating dynamic assembly on fly (with dynamic types in it).
both reflection , reflection.emit
namespace provide apis dealing methods , properties of clr types.
to knowledge, properties implemented methods c# compiler, , i'm wondering how should these treated when emitting them dynamically?
should properties emitted using methodbuilder
or using propertybuilder
? (i.e: calling definemethod
or defineproperty
?)
is there recommendation 1 approach on other?
should properties emitted using
methodbuilder
or usingpropertybuilder
?
both. if have read-write property x
, in cil it's represented a method (usually called get_x
), set method (usually called set_x
) , called x
points 2 methods.
so, create property using reflection.emit, should:
- use
methodbuilder
create method (probably reading field). - use
methodbuilder
create set method (probably writing same field). - use
propertybuilder
create property, settingname
, callingsetgetmethod()
,setsetmethod()
.
if want create read-only property, skip step 2 , don't call getsetmethod()
.
Comments
Post a Comment