我想检查特定运行时类型是否包含具有特定属性的属性,如下所示:
public void Audit(MongoStorableObject oldVersion, MongoStorableObject newVersion)
{
if(oldVersion.GetType() != newVersion.GetType())
{
throw new ArgumentException("Can't Audit versions of different Types");
}
foreach(var i in oldVersion.GetType().GetProperties())
{
//The statement in here is not valid, how can I achieve look up of a particular attribute
if (i.GetCustomAttributes().Contains<Attribute>(MongoDB.Bson.Serialization.Attributes.BsonIgnoreAttribute)) continue;
//else do some actual auditing work
}
}
但是该声明无效,您能告诉我如何实现对这样的属性的特定属性的查找吗?谢谢,
更新:
我发现这不会让智能感知抱怨:
if (i.GetCustomAttributes((new MongoDB.Bson.Serialization.Attributes.BsonIgnoreAttribute()).GetType(),false).Length > 0) continue;
但我仍然不确定这也会做我想要的。