samedi 12 décembre 2015

C# Reflection: How to determine if ParameterInfo is a generic type defined on parent class

I have a method signature like this:

public void CopyTo(TItem[] items) { }

where TItem is declared on the parent class.

I need to figure out what the generic type signature is so I can look at the XML documentation (need to build the funky generic type lookup signature). I need to map the method signature to what's in the XML documentation which looks like this:

<member name="M:ClassLibrary1.Class1`1.CopyTo(`0[])">

I'm unable to reliably detect whether TItem[] is generic and figure out how to get the generic index (generically).

When I look at the parameter signature, the ParameterType.IsGenericType is false as is .GenericParameterPosition. ParameterType.ContainsGenericParameters is true, but nowhere does it give me the generic raw type signature (ie. '0[] that the signature requires and is usually seen in the .FullName property).

This all works if the Generic definition is on actual method (ie. SomeMethod<TItem>(TItem[] blah) at which point I can parse out the parameters as I need to. But when the generic parameter is defined on the type I can't figure out the right signature to reference the parent generic type by it's generic parameter position.





Aucun commentaire:

Enregistrer un commentaire