What is the equivalent of Type.GetGenericArguments() in .NETStandard 1.0 / .NET Core?

前端 未结 2 1920
春和景丽
春和景丽 2021-02-13 10:37

The method System.Type.GetGenericArguments() is \'missing\' from .NETStandard 1.0, and I thought that the TypeInfo.GenericTypeArguments was the replace

2条回答
  •  离开以前
    2021-02-13 11:17

    This may turn out to be a comment (not an answer) after all.

    On .NET 4.6.1, there are two members on System.Type, namely:

    /* 1 */ type.GetGenericArguments()               // returns { TCommand, }
    
    /* 2 */ type.GenericTypeArguments                // returns empty array
    

    plus one member on System.Reflection.TypeInfo, namely:

    /* 3 */ type.GetTypeInfo().GenericTypeParameters // returns { TCommand, }
    

    for a total of three members.

    However, the two first-mentioned members are also inherited by System.Reflection.TypeInfo, a subclass of System.Type.

    On .NET 4.6.1, when you do type.GetTypeInfo().GenericTypeArguments (as in your question), you really call the property on Type, i.e. my member marked /* 2 */.

提交回复
热议问题