mercredi 12 octobre 2022

Is there a way to detect the notnull constraint via reflection on a generic method?

When trying to get constraints applied to a generic method with reflection, after calling GetGenericArguments on the MethodInfo, if I use GenericParameterAttributes I get None and GetGenericParameterConstraints returns an empty Type[] when there's only a notnull constraint.

I have tried finding differences in the generated IL and (from what I understand) there's only a NullableAttribute (from System.Runtime.ComplierServices) applied to either the generic method, its declaring type or the type parameter that has the notnull constraint depending on the definition of the class nor method.

Since the attribute's location is not always the same and I'm pretty sure there are others ways it can appear I don't think looking for this attribute is a reliable solution.

Is there something more that can tell me a type parameter has the notnull constraint using reflection?





Aucun commentaire:

Enregistrer un commentaire