在 Visual Studio 中获取类的程序集限定名称

发布于 2024-08-28 11:58:02 字数 222 浏览 7 评论 0原文

我正在为一些专门的自定义域逻辑编写一个自定义的反射库,该库将使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

茶花眉 2024-09-04 11:58:03

我不确定我是否理解了这个问题。您想以编程方式获取类型的全名吗?如果是这样,您始终可以使用 typeof(YourType).FullNametypeof(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 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.

独守阴晴ぅ圆缺 2024-09-04 11:58:02

如果我处于您的情况,我只会弹出立即窗口(调试->Windows->立即)并使用typeof(TypeFullName).AssemblyQualifiedName

您需要使用完整的命名空间来限定类型才能执行此操作,这还会产生自动运行解决方案启动项目的副作用。可以通过暂时将类库设置为解决方案启动项目来减轻这种副作用。

例子:

typeof(System.Windows.Forms.Button).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:

typeof(System.Windows.Forms.Button).AssemblyQualifiedName
坠似风落 2024-09-04 11:58:02

我会将我的评论更改为正确的答案,因为在快速玩完之后,我建议的内容正是您想要的。

从此处下载 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文