【发布时间】:2009-10-31 04:54:19
【问题描述】:
在 .net 中,我如何在声明类型中获取对象的名称。比如……
public static void Main()
{
Information dataInformation = new Information();
}
public class Inforamtion
{
//Constructor
public Inforamtion()
{
//Can I fetch name of object i.e. "dataInformation" declared in Main function
//I want to set the object's Name property = dataInformation here, because it is the name used in declaring that object.
}
public string Name = {get; set;}
}
【问题讨论】:
-
顺便说一句,我想说的是,试图在变量名和任何运行时值之间强制进行一些映射是可维护性的灾难。
-
请记住,您正在查看的是一个文本文件,并且您的变量名在编译后将简单地替换为某个标签。一旦 Jitter 获得变量名,变量名最终将成为一个指针。变量名称的文本值不会保留在源文件和调试符号之外。
-
你到底为什么要这么做?你能解释一下吗?
标签: c# .net vb.net reflection