Windows Universal Apps中的反思
我需要使用GetProperties方法,以便我可以测试特定类中的任何属性是否具有指定的自定义属性。 但是,似乎Windows Universal Apps不支持此function:
obj.GetType().GetProperties()
引发错误:
'System.Type' does not contain a definition for 'GetProperties' and no extension method 'GetProperties' accepting a first argument of type 'System.Type' could be found (are you missing a using directive or an assembly reference?)
为了使用完整的reflection库,我需要参考什么?
提前致谢。
将此添加到您的using语句:
using System.Reflection;
然后你可以使用obj.GetType().GetRuntimeProperties()
方法。 此方法返回在指定类型上定义的所有属性,包括inheritance,非公共,实例和静态属性。 请记住,此行为与GetProperties()
的行为略有不同,后者仅返回公共属性。