public static bool PropertyCheck(this object o, string propertyName)
{
if (string.IsNullOrEmpty(propertyName))
return false;
Type type = (o is Type) ? o as Type : o.GetType();
PropertyInfo pi = type.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty);
if (pi != null && pi.PropertyType == typeof(string))
return true;
return false;
}
and then Invoke it like this:
object someobj = new Object();
if (someobj.PropertyCheck("someproperty"))
// do stuff
or you could do it like this:
Type type = typeof(someobject);
if (type.PropertyCheck("someproperty"))
this has some limitations as you then cannot check the Type
type itself for properties, but you can always make another version of that if it is needed.
I think this is what you wanted, hope it helps