I'm writing a customized reflective library for some specialized custom domain logic, and that library is going to use XML configuration files that will dynamically resolve System.Type objects at runtime. However, when writing the XML configuration files, it's a bit of a pain to write the types because they need to be fully qualified assembly names for Type.GetType() to resolve them. Is there a way to find out the AssemblyQualifiedName of an object in Visual Studio without resorting to writing a program to print them out to a file or standard out or anything like that ?
问题:
回答1:
I'm gonna change my comment to a proper answer, because after having a quick play what i suggested does exactly what you want.
Download the free version of Reflector from here, unpack it and run it. Drag and drop a compiled version of your assembly on to it, and next to the Name tag in the info section at the bottom of the dialog will be its fully qualified name, ready for you to just copy and paste from there.
Note that all the info you need is also availableby right-clicking on the compiled file, select Properties, then go to the Details tab, although you can't just copy/paste from there.
回答2:
If I were in your situation I would just popup the Immediate Window (Debug->Windows->Immediate) and use typeof(TypeFullName).AssemblyQualifiedName
.
You need to qualify the type with the full namespace in order to do this and this also has the side effect of automatically running the solution startup project. This side effect can be mitigated by temporarily setting a class library as the solution startup project.
Example:
typeof(System.Windows.Forms.Button).AssemblyQualifiedName
回答3:
I'm not sure if I understood the problem. You want to get full names of your types programmatically? If so, you can always use typeof(YourType).FullName
or typeof(YourType).AssemblyQualifiedName
.
What I can think of is marking all of types you need with some custom atribute to easyly find them in the assemblies to extract their names, I don't think you can find some way without going through each of the type you need to extract its name.