c# - Get source property type from BindingExpression -
i trying find out source property type of binding expression. want because want use updatesourceexceptionfilter provide more useful error message generic “couldn’t convert”.
in .net 4.5 use resolvedsource , resolvedsourcepropertyname reflection source property type this:
propertyinfo sourceproperty = expr.resolvedsource.gettype().getproperty(expr.resolvedsourcepropertyname); type propertytype = sourceproperty.propertytype;
this works fine. both bindingexpression properties introduced .net 4.5, , i’m still on 4.0 (can’t update because of windows xp).
so there nice way in .net 4.0? thought getting internal sourceitem
, sourcepropertyname
properties using reflection or private worker
values rather avoid access internal/private properties or fields (and think require me trust? implications there?).
not pretty, without access private methods:
string[] splits = expr.parentbinding.path.path.split('.'); type type = expr.dataitem.gettype(); foreach (string split in splits) { type = type.getproperty(split).propertytype; }
thus, able resolve source property.
Comments
Post a Comment