How to determine if ParameterInfo is of generic type?

后端 未结 4 956
自闭症患者
自闭症患者 2020-12-19 07:42

I have a MethodInfo of a GenericMethodDefinition. Such as: CallMethod(T arg, string arg2). The GetParameters() method will give me two P

4条回答
  •  借酒劲吻你
    2020-12-19 07:59

    Check ParameterType.IsGenericParameter.
    You may also want to check ContainsGenericParameters, which will be true for something like MyMethod(List param). (Even though List<> isn't a generic parameter)

    If IsGenericParameter is true, you can also call GetGenericParameterConstraints() to get interface or base type constraints, and you can check GenericParameterAttributes (a [Flags] enum) for new(), struct, or class constraints.

提交回复
热议问题