已知
mD tmp = Item as mD;
string a=tmp.DeptCode.ToLower().IndexOf(search.ToLower());
现在如果mD可能是一个未知类似我用反射的方法去实现上面的功能string dp="DeptCode";
PropertyInfo[] properties = Item.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
foreach (PropertyInfo a in properties)
{
if (dp== a.Name) //存在DeptCode属性
{
string a= //这里用反射怎么写?
}
}
mD tmp = Item as mD;
string a=tmp.DeptCode.ToLower().IndexOf(search.ToLower());
现在如果mD可能是一个未知类似我用反射的方法去实现上面的功能string dp="DeptCode";
PropertyInfo[] properties = Item.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
foreach (PropertyInfo a in properties)
{
if (dp== a.Name) //存在DeptCode属性
{
string a= //这里用反射怎么写?
}
}
string dp="DeptCode";
PropertyInfo[] properties = Item.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
foreach (PropertyInfo a in properties)
{
if (dp== a.Name) //存在DeptCode属性
{
int index=(a.GetValue(Item,null) as string).ToLower().IndexOf(search.ToLower());
//这里用反射怎么写?
}
}
{
MessageBox.Show(string.Format("{0}={1}",info.Name,info.GetValue(b.Property2,null)));
}