C# 如何获取不带';在运行时不包含属性
因此,我有一个C# 如何获取不带';在运行时不包含属性,c#,reflection,attributes,C#,Reflection,Attributes,因此,我有一个属性,我是这样创建的: public class IgnoreFilter : Attribute { } 我有一个我用过的类,也是这样: public class Customer { private string name; public string Name { get { return name; } set { name = value; Rais
属性
,我是这样创建的:
public class IgnoreFilter : Attribute
{
}
我有一个我用过的类,也是这样:
public class Customer
{
private string name;
public string Name
{
get { return name; }
set
{
name = value;
RaisePropertyChanged();
}
}
private string address;
[IgnoreFilter]
public string Address
{
get { return address; }
set
{
address = value;
RaisePropertyChanged();
}
}
我现在正试图在运行时从我的Customer
类中获取所有不包含IgnoreFilter
属性的属性。到目前为止我已经
customer.GetType().GetRuntimeProperties().Where(p => !p.CustomAttributes.Contains(typeof(IgnoreFilter)));
但是最后一行没有编译。我想我的思路是对的,但我可能遗漏了什么
有人可以帮助从不包含自定义属性的类中获取属性吗?来自我最后使用的注释:
customer.GetType().GetRuntimeProperties().Where(p => p.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(IgnoreFilter)) == null);
包含的
错误。使用of type().Any()
或只使用Any(o=>o.GetType()==typeof(IgnoreFilter))
@Sinatr谢谢,工作非常完美FirstOrDefault()==null
是!Any()
。