I am trying to find out the source property type of a binding expression. I want to do this because I want to use the UpdateSourceExceptionFilter to provide a more useful error message than just the generic “couldn’t convert”.
In .NET 4.5 I use ResolvedSource and ResolvedSourcePropertyName with reflection to get the source property type like this:
PropertyInfo sourceProperty = expr.ResolvedSource.GetType().GetProperty(expr.ResolvedSourcePropertyName);
Type propertyType = sourceProperty.PropertyType;
This works just fine. However both those BindingExpression properties were just introduced with .NET 4.5, and I’m still on 4.0 (can’t really update because of Windows XP).
So is there a nice way to do this in .NET 4.0? I thought about getting the internal SourceItem
and SourcePropertyName
properties using reflection or just the private Worker
to get those values but I would rather avoid to access internal/private properties or fields (and I think this would also require me to do something about trust? What implications are there?).