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:
- am correct, compiled expressions (using system.linq.expressions) , generated code (using codedom / microsoft.csharp.csharpcodeprovider) cannot used set private properties?
- would possible using reflection.emit?
- would of mapping libraries (automapper, valueinjecter) (i don't know technology use internally)?
- 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
Post a Comment