【发布时间】:2013-10-21 06:52:45
【问题描述】:
我有两个班级:
public class LookUpData
{
[Searchable]
public string ManufactureName {get;set;)
}
public class Car
{
public int ID {get;set;}
[Searchable]
public string Model {get;set;}
public int ManufactureId {get;set;}
public LookUpData LookUpData{ get;set;}
}
使用 [Searchable] 属性,我正在尝试获取属性,之后我可以在 DB 中进行搜索。
目前我有静态方法:
public static List<PropertyInfo> GetSearchPropertiesWithOrderBy(Type type)
{
if (type == null) throw new ArgumentNullException("type");
return type.GetProperties()
.Select(x => new
{
Property = x,
Attribute =
(SearchableAttribute) Attribute.GetCustomAttribute(x, typeof (SearchableAttribute), true)
})
.OrderBy(x => x.Attribute != null ? x.Attribute.OrderBy : 200)
.Select(x => x.Property)
.ToList();
}
我可以得到一个 PropertyInfo 的列表
- Model
- LookUpData
如何获取 PropertyInfo 的列表以具有“真实姓名”属性:
- Model
- ManufacterName
提前致谢。
【问题讨论】:
-
真实姓名是什么意思?
-
子类“LookUpData”的属性名称应为“ManufacterName”
标签: c# reflection custom-attributes propertyinfo