I'm trying to check if webcontrol supports a particular property (although it can be any object) - 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, but it doesn't seem to contain a value either, which is baffling me. If I remove the if(v == null) it works, but with it there is no update.
I'm testing it out on a hyperlink Text and NavigateUrl properties.
Any help appreciated.