如何找到分配给变量的对象的 class?

How do I find the class of the object that's assigned to a variable?

我有一些这样的代码,我不知道 class 分配给 someObject 的是什么:

public ISomeInterface someObject;

public void DoThing()
{
    someObject.DoAnotherThing();
}

如何找出分配给 someObject 的对象的 class 是什么? Visual Studio 中是否有显示此按钮的按钮?当我将鼠标悬停在 DoThing 内的 someObject 上时,Visual Studio 为我提供了 someObject 上的属性列表及其值,但它没有告诉我 [=24] 是什么=] 的 someObject 是。

我是在写题的时候想出来的。据我所知,没有办法直接在 Visual Studio 中看到这个(如果有人想出来请 post 另一个答案),但我们可以在 C# 中完成:

System.Type type = someObject.GetType();
string typeFullName = type.FullName;

您可以在调试时做同样的事情。如果您在断点处停止,您可以在下面的 Watch window 中输入该表达式。

变量的类型将显示在 Type 列中的大括号中,您必须将 Watch window 展开得非常宽才​​能看到它。类型列将如下所示:

SomeNamespace.ISomeInterface {SomeNamespace.SomeClass}