在 C# 中获取带有扩展名的类名?
我试图在我的代码中获取带有扩展名的类名(例如 Employee.cs 或 Employee.aspx.cs)。我能够获得类的名称没有扩展名,但是有人知道我怎样才能获得类的扩展名吗?
这就是我为获取类名所做的事情:
var frame = new StackFrame(1);
string className = frame.GetMethod().ReflectedType.Name;
I am trying to get class name with the extension (e.g. Employee.cs or Employee.aspx.cs) in my code. I was able to get the name of the class without the extension but does anybody know how can i also get extension of the class??
This is what i did to get class name:
var frame = new StackFrame(1);
string className = frame.GetMethod().ReflectedType.Name;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

这是反射不可能实现的。源编译文件的名称不是类型元数据的一部分。
That is not possible with reflection. The name of the source compilation file is not part of the metadata of the type.