获取作为lambda表达式传递的参数的PropertyInfo | Compact Framework,C#
假设我拥有以下资产类别:获取作为lambda表达式传递的参数的PropertyInfo | Compact Framework,C#,c#,reflection,lambda,compact-framework,C#,Reflection,Lambda,Compact Framework,假设我拥有以下资产类别: class Asset { public int Id { get; set; } public string Name { get; set; } } 现在我想写一个方法GetPropertyInfo(a=>a.Name)这个方法给了我Asset.Name的PropertyInfo。我应该能够像这样调用此方法: 编辑示例方法调用 PropertyInfo propInfo = GetPropertyInfo(a=>a.Name); 我有一个列
class Asset
{
public int Id { get; set; }
public string Name { get; set; }
}
现在我想写一个方法GetPropertyInfo(a=>a.Name)
这个方法给了我Asset.Name的PropertyInfo。我应该能够像这样调用此方法:
编辑示例方法调用
PropertyInfo propInfo = GetPropertyInfo(a=>a.Name);
我有一个列表
,所以我想将给定的lambda表达式与列表中的表达式进行匹配
if(Possible on Compact Framework 3.5 && using C#)
How?
else
Please Notify
谢谢。这可以在.NETCF 3.5下完成
private List<Asset> m_list;
private Asset[] GetPropertyInfo(string name) {
var items = m_list.Where(a => a.Name == name);
if (items != null) {
return items.ToArray();
} else {
return null;
}
}
不过,我不确定您是如何获得列表的。我能够使用下面的代码提取单个属性info
对象:
private PropertyInfo GetPropertyInfo() {
var t = Type.GetType("System.Reflection.MemberInfo");
return t.GetProperty("Name");
}
此项中没有任何有用的内容。这可以在.NETCF 3.5下完成
private List<Asset> m_list;
private Asset[] GetPropertyInfo(string name) {
var items = m_list.Where(a => a.Name == name);
if (items != null) {
return items.ToArray();
} else {
return null;
}
}
不过,我不确定您是如何获得列表的。我能够使用下面的代码提取单个属性info
对象:
private PropertyInfo GetPropertyInfo() {
var t = Type.GetType("System.Reflection.MemberInfo");
return t.GetProperty("Name");
}
这个项目没有什么用处。你搞错了。我想要PropertyInfo对象属于asset.Name属性。编辑您的原始帖子,以准确显示您正在拉什么以及如何使用常规代码。也许到时候我会理解得足以帮助你。正在执行的程序集有很多属性和方法。我添加了如何调用我的方法。希望现在更清楚。我仍然不确定你需要做什么。我更新了我的代码,但我不认为你会利用移动设备的反射来获取太多信息。你搞错了。我想要PropertyInfo对象属于asset.Name属性。编辑您的原始帖子,以准确显示您正在拉什么以及如何使用常规代码。也许到时候我会理解得足以帮助你。正在执行的程序集有很多属性和方法。我添加了如何调用我的方法。希望现在更清楚。我仍然不确定你需要做什么。我更新了我的代码,但我不认为你会通过移动设备的反射获取太多信息。