在 Visual Studio 中获取类的程序集限定名称
我正在为一些专门的自定义域逻辑编写一个自定义的反射库,该库将使用 XML 配置文件,该文件将在运行时动态解析 System.Type 对象。然而,在编写 XML 配置文件时,编写类型有点麻烦,因为它们需要是完全限定的程序集名称,以便 Type.GetType() 来解析它们。有没有办法在 Visual Studio 中找出对象的 AssemblyQualifiedName,而无需编写程序将它们打印到文件或标准输出或类似的东西?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定我是否理解了这个问题。您想以编程方式获取类型的全名吗?如果是这样,您始终可以使用
typeof(YourType).FullName
或typeof(YourType).AssemblyQualifiedName
。我能想到的是用一些自定义属性标记您需要的所有类型,以便在程序集中轻松找到它们以提取它们的名称,我认为您无法找到某种方法而不通过您需要提取其名称的每个类型姓名。
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
ortypeof(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.
如果我处于您的情况,我只会弹出立即窗口(调试->Windows->立即)并使用
typeof(TypeFullName).AssemblyQualifiedName
。您需要使用完整的命名空间来限定类型才能执行此操作,这还会产生自动运行解决方案启动项目的副作用。可以通过暂时将类库设置为解决方案启动项目来减轻这种副作用。
例子:
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:
我会将我的评论更改为正确的答案,因为在快速玩完之后,我建议的内容正是您想要的。
从此处下载 Reflector 的免费版本,解压并运行它。将程序集的编译版本拖放到其上,对话框底部信息部分中的 Name 标记旁边将是其完全限定名称,可供您复制和使用从那里粘贴。
请注意,您也可以通过右键单击已编译的文件,选择属性,然后转到详细信息选项卡来获得所需的所有信息,尽管您不能只是复制/从那里粘贴。
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.