views:

38

answers:

1

I use following code:

protected object GetProperty(object target, string fieldName)
{
    Type type = target.GetType();
    PropertyInfo mi = type.GetProperty(
        fieldName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty);
    object obj = mi.GetValue(target, null);
    return obj;
}

It works in .NET 3.5. But if I change to .NET 4, then mi becomes null. Why?

+5  A: 

Does the target still have the desired property in .net 4? There were quite a few API Changes.

Michael Stum
You are right. The Property has been removed in .net 4. Not good
magol
@Magol: That is the risk of relying on private and/or undocumented things -- they can, and do, change.
Richard