特定のランタイム型に、次のような特定の属性を持つプロパティが含まれているかどうかを確認したい:
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;
しかし、これが私が望むことをするかどうかはまだわかりません。