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 using propertybuilder?

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:

  1. use methodbuilder create method (probably reading field).
  2. use methodbuilder create set method (probably writing same field).
  3. use propertybuilder create property, setting name , calling setgetmethod() , setsetmethod().

if want create read-only property, skip step 2 , don't call getsetmethod().


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -