在 C# 中获取带有扩展名的类名?

发布于 11-24 02:38 字数 252 浏览 7 评论 0原文

我试图在我的代码中获取带有扩展名的类名(例如 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

卷耳2024-12-01 02:38:24

这是反射不可能实现的。源编译文件的名称不是类型元数据的一部分。

That is not possible with reflection. The name of the source compilation file is not part of the metadata of the type.

忱杏2024-12-01 02:38:24

调用 frame.GetFileName()
仅当您有 PDB 文件时这才有效。

Call frame.GetFileName().
This will only work if you have the PDB file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文