使用GetCustomAttributes获取除DataMemberAttributes之外的所有属性

时间:2017-02-28 16:45:10

标签: c# reflection attributes

我正在尝试从PropertyInfo对象获取自定义属性,但我试图避免获取DataMemberAttributes。我遇到编译错误'无法转换为' object'到' System.Reflection.MemberInfo'"使用以下代码:

PropertyInfo myProperty = GetMyProperty(myObject);

object[] myAttributes= fromProperty.GetCustomAttributes(false).Where(a => !Attribute.IsDefined(a, typeof(DataMemberAttribute)));

正确的lambda语法是什么?

0 个答案:

没有答案
相关问题