【问题标题】:How can I determine whether a property is a Generic Type in DNX Core 5.0?如何确定属性是否为 DNX Core 5.0 中的通用类型?
【发布时间】:2015-09-17 05:14:51
【问题描述】:

以前我可以使用它来获取类的泛型类型;

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

但是,在 DNX Core 5.0 中,不支持 IsGenericType。我现在可以使用什么?

【问题讨论】:

    标签: c# .net asp.net-core dnx


    【解决方案1】:

    刚刚查看了这里的一些来源,确认框架中仍然存在 IsGenericType 属性。

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

    以下是否有效?

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多