performance - setting private properties of classes -


i have old code uses reflection set properties of objects, e.g this:

var properties = obj.gettype().getproperties(   bindingflags.public | bindingflags.nonpublic | bindingflags.instance); foreach (var property in properties) {   property.setvalue(obj, lookup[property.name]); } 

i thinking replacing code make faster. because above code allows setting private properties of object, i'm not sure other options there exist.

questions:

  1. am correct, compiled expressions (using system.linq.expressions) , generated code (using codedom / microsoft.csharp.csharpcodeprovider) cannot used set private properties?
  2. would possible using reflection.emit?
  3. would of mapping libraries (automapper, valueinjecter) (i don't know technology use internally)?
  4. are there other options?

the open source framework impromptu-interface has static method invokeset uses dlr rather reflection, , call private methods. runs little on 2 times faster reflection in unit speed test case, looks similar yours.

using impromptuinterface; 

...

foreach(var property in properties){     impromptuinterface.invokeset(obj, property.name, lookup[property.name]); } 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -