Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB.NET:获取实例的类名_.net_Vb.net_Oop_Class_Instance - Fatal编程技术网

VB.NET:获取实例的类名

VB.NET:获取实例的类名,.net,vb.net,oop,class,instance,.net,Vb.net,Oop,Class,Instance,有没有办法用VB.NET获取实例的类名?试试下面的方法 Dim name = Me.GetType().Name 或者无论如何 Dim name = theObject.GetType().Name “全名”将获得类型的完全限定名,包括类型的命名空间 有关类型可用功能的详细信息,请参阅。如果使用asp.net网站类而不是对象,则此功能可能会更好 Dim ClassName as string = Me.GetType().BaseType.FullName 或 当您使用桌面应用程序时 Di

有没有办法用VB.NET获取实例的类名?

试试下面的方法

Dim name = Me.GetType().Name
或者无论如何

Dim name = theObject.GetType().Name
“全名”将获得类型的完全限定名,包括类型的命名空间


有关
类型

可用功能的详细信息,请参阅。如果使用asp.net网站类而不是对象,则此功能可能会更好

Dim ClassName as string = Me.GetType().BaseType.FullName

当您使用桌面应用程序时

Dim ClassName as string = Me.GetType().Name

使用反射,您可以执行以下操作

System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString()
我在记录跟踪信息时使用以下命令。这将为您提供类名、所有名称空间和当前方法名

$"{System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString()}.{MethodBase.GetCurrentMethod().Name}"

您将如何在共享级别执行此操作?也支持子类?如何在子类的共享级别上做到这一点?Me.GetType().BaseType.FullName不会为我获取类名(对于我编码的类)。它只返回“System.Object”。但是me.GetType().Name会返回我的类的名称。
$"{System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString()}.{MethodBase.GetCurrentMethod().Name}"