Note that there are some explanatory texts on larger screens.

plurals
  1. POGet source property type from BindingExpression
    primarykey
    data
    text
    <p>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 <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.updatesourceexceptionfilter.aspx" rel="nofollow">UpdateSourceExceptionFilter</a> to provide a more useful error message than just the generic “couldn’t convert”.</p> <p>In .NET 4.5 I use <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.bindingexpression.resolvedsource.aspx" rel="nofollow">ResolvedSource</a> and <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.bindingexpression.resolvedsourcepropertyname.aspx" rel="nofollow">ResolvedSourcePropertyName</a> with reflection to get the source property type like this:</p> <pre><code>PropertyInfo sourceProperty = expr.ResolvedSource.GetType().GetProperty(expr.ResolvedSourcePropertyName); Type propertyType = sourceProperty.PropertyType; </code></pre> <p>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).</p> <p>So is there a nice way to do this in .NET 4.0? I thought about getting the internal <code>SourceItem</code> and <code>SourcePropertyName</code> properties using reflection or just the private <code>Worker</code> 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?).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload