如何在解决方案中获取具有给定类的完整名称空间的程序集名称和类名称? [英] How to get the assembly name and class name with full namespace of a given class in the solution?

查看:69
本文介绍了如何在解决方案中获取具有给定类的完整名称空间的程序集名称和类名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WPF,经常需要获取给定类的名称空间和程序集名称.但是我不知道该怎么做.

那么,在解决方案资源管理器中浏览类或/和编辑类的代码时,如何获得名称?请帮忙!

解决方案

您可以使用Visual Studio 立即窗口作为获取解决方案项目之一的程序集合格名称的快速方法./p>

IIRC,这些步骤应该有效:

  1. 打开要获取程序集名称的项目中包含的类的文件;
  2. 将该项目设置为该解决方案的启动项目;
  3. 打开立即窗口,默认的C#环境快捷方式为 CTRL + D + I
  4. 在立即窗口"中,键入 typeof(ClassNameOfStep1).AssemblyQualifiedName ,然后按 Enter .

立即窗口取决于设计时表达式评估依次取决于Visual Studio托管过程,因此您需要启用它,默认情况下已启用它.

此外,我做了一些快速测试,并且在所有情况下该类的名称都足够了,除非我在VS 2008上尝试过,这要求我提供该类型的 FullName .因此,如果 Name 错误,请使用名称空间限定的 Name .

I'm working with WPF and often have the need to get the namespace and assembly name of a given class. But I don't know how to do this.

So, how can we get the names when browsing the classes in the Solution Explorer or/and when editing the class's codes? Please help!

解决方案

You could use the Visual Studio Immediate Window as a quick way to obtain the assembly qualified name for one of the solution projects.

IIRC, these steps should work:

  1. Open the file of a class contained in the project for which you want to obtain assembly name;
  2. Set that project as the startup project for the solution;
  3. Open the Immediate Window, default C# environment shortcut is CTRL+D+I;
  4. In the Immediate Window type typeof(ClassNameOfStep1).AssemblyQualifiedName and press Enter.

The Immediate Window depends on Design-Time Expression Evaluation which in turns depends of Visual Studio Hosting Process so you need to have it enabled, which by default already is.

Also, I did some quick tests and the Name of the class was sufficient in all cases except when I tried it on VS 2008, which required me to provide the FullName of the type. So if Name results in error use the Name qualified with the namespace.

这篇关于如何在解决方案中获取具有给定类的完整名称空间的程序集名称和类名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆