简体   繁体   English

如何确定属性是否为DNX Core 5.0中的通用类型?

[英]How can I determine whether a property is a Generic Type in DNX Core 5.0?

Previously I could use this to get the generic types on a class; 以前我可以使用它来获取类的泛型类型;

typeof(MyClass).GetTypeInfo().DeclaredProperties.Any(p => p.PropertyType.IsGenericType)

However, in DNX Core 5.0, IsGenericType is not supported. 但是,在DNX Core 5.0中,不支持IsGenericType What can I use now? 我现在可以用什么?

Just looked through some source here that confirms there is still a IsGenericType property in the framework. 刚刚查看了一些源代码,确认框架中仍然存在IsGenericType属性。

https://github.com/aspnet/Common/blob/dev/src/Microsoft.Framework.ClosedGenericMatcher.Sources/ClosedGenericMatcher.cs#L44 https://github.com/aspnet/Common/blob/dev/src/Microsoft.Framework.ClosedGenericMatcher.Sources/ClosedGenericMatcher.cs#L44

Does the following work? 以下工作如何?

typeof(MyClass).GetTypeInfo().DeclaredProperties.Any(p => p.PropertyType.GetTypeInfo().IsGenericType)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM