开发者

Get Class Name with extension in C#?

开发者 https://www.devze.com 2023-03-20 18:59 出处:网络
I am trying to get class name with the exten开发者_开发问答sion (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 h

I am trying to get class name with the exten开发者_开发问答sion (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;


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消