lundi 21 septembre 2015

propertinfo.getvalue() not giving expected result

I'm trying to check if webcontrol supports a particulat property - if it does I want to check if a value exists - if a value exists, I want to do nothing, otherwise I'll update it with a given value.

Here's my code:

    public static void SetProperty(this object @this, string name, object value)
    {
        var p = @this.GetType().GetProperty(name);
        if (p != null)
        {
            var v = p.GetValue(@this, null);
            if(v == null) p.SetValue(@this, value, null);
        }
    }

The problem is that v is never NULL, which is baffling me. Any help appreciated.





Aucun commentaire:

Enregistrer un commentaire