samedi 22 juillet 2017

Using reflection, is there a way to load a .NET type with generic parameters without having to append the number of them to the name?

I am working on my own language and for the sake of .NET interop I've been using the Reflection methods to query the .NET types and method signatures.

open System
let asm = Reflection.Assembly.Load("mscorlib")
let dic = asm.GetType("System.Collections.Generic.Dictionary`2")

The above is how I would load the type of Dictionary directly from mscorlib. Note that unlike in standard code, the 2 at the end separated by the grave character is necessary.

Since C# and F# do not require specifying the number of generic parameters as a part of the name, I've been wondering whether there is a better way of doing this?

This is awkward because right now, I have to write out the full name in my language's code as well.





Aucun commentaire:

Enregistrer un commentaire