Given that I have a type “Wibble.Wobble” that exists in an assembly “Foo.Bar”
And that assembly is not loaded into the main applications load context
Is there an existing public mechanism for parsing the following string into its subsequent parts:
"Wibble.Wobble, Foo.Bar, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xyz"
The reason for asking is that I a need to load a variety of types at runtime, some of which may be in the current load context. Others may need to be loaded from an external assembly.
I know how to load types from the current load context Type.GetType("typename"), I know how to load an assembly and get a type from it Assembly.LoadFile("xyz").GetType("abc"). What I am having problems with is that if you try to load a type from an assembly it should not be a fully qualified name where as you can when using Type.GetType.
The solution itself should not be that complicated, it is just splitting the string before the first comma. However I wanted to know if there was a way of getting the fully qualified name as an object representation so I didn’t have to do this and it would help with locating the right assembly without having to loop through a whole directory.
After all my digging around I do not believe there is anything publicly available in the Framework that can do this. I would love for someone to show me different as I prefer to use core functionality that is (or should be) better tested and written by someone who has a better understanding of the framework than I do.
As such I have rolled my own strongly typed
TypeNameobject.The object takes in a
stringwhich should be either a type name or a fully qualified type name. If it is a fully qualified type name then the AssemblyName attribute is set using the AssemblyName class other wise it is left as null.