很多时候会遇到这样一个问题,就是你想判断一个字符串是否是某个对象的属性,如果是,则返回该属性的值,否则返回空。
public string GetEntityProperty(string propertyName, object objInit)
{
PropertyInfo info = objInit.GetType().GetProperty(propertyName);
if (info != null)
{
return info.GetValue(objInit, null).ToString();
//return true;
}
else
return null;
}