UWP 应用程序中是否有 Attribute.IsDefined 的替代品?
Is there a replacement for Attribute.IsDefined in UWP apps?
UWP 应用程序似乎缺少静态方法 Attribute.IsDefined,我可以导航到属性 class 的元数据,好的,方法在那里,但项目无法编译声明 'Attribute' 不包含 'IsDefined' 的定义 - 很奇怪(事实上,根据 IntelliSense,该类型根本没有静态方法)。
我打算查询具有特定属性的类型,例如
var types = this.GetType().GetTypeInfo().Assembly.GetTypes()
.Where(t => Attribute.IsDefined(t, typeof (MyAttribute)));
我想知道是否有解决方法。
这应该有效:
var types = this.GetType().GetTypeInfo().Assembly.GetTypes()
.Where(t => t.GetTypeInfo().GetCustomAttribute<MyAttribute>() != null);
UWP 应用程序似乎缺少静态方法 Attribute.IsDefined,我可以导航到属性 class 的元数据,好的,方法在那里,但项目无法编译声明 'Attribute' 不包含 'IsDefined' 的定义 - 很奇怪(事实上,根据 IntelliSense,该类型根本没有静态方法)。
我打算查询具有特定属性的类型,例如
var types = this.GetType().GetTypeInfo().Assembly.GetTypes()
.Where(t => Attribute.IsDefined(t, typeof (MyAttribute)));
我想知道是否有解决方法。
这应该有效:
var types = this.GetType().GetTypeInfo().Assembly.GetTypes()
.Where(t => t.GetTypeInfo().GetCustomAttribute<MyAttribute>() != null);