c# - Create Expression from PropertyInfo -
i'm using api expects expression<func<t, object>>
, , uses create mappings between different objects:
map(x => x.id).to("id__c"); // expression "x => x.id"
how can create necessary expression propertyinfo
? idea being:
var properties = typeof(t).getproperties(); foreach (var propinfo in properties) { var exp = // how create expression "x => x.id" ??? map(exp).to(name); }
you need expression.property
, wrap in lambda. 1 tricky bit need convert result object
, too:
var parameter = expression.parameter(x); var property = expression.property(parameter, propinfo); var conversion = expression.convert(property, typeof(object)); var lambda = expression.lambda<func<t, object>>(conversion, parameter); map(lambda).to(name);
Comments
Post a Comment