获取程序集名称 [英] Getting assembly name
本文介绍了获取程序集名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
C#的异常类的source属性默认情况下设置为程序集的名称。
是否有另一种方法来获取此确切的字符串(不解析其他字符串)?
C#'s exception class has a source property which is set to the name of the assembly by default.
Is there another way to get this exact string (without parsing a different string)?
我尝试了以下操作:
catch(Exception e)
{
string str = e.Source;
//"EPA" - what I want
str = System.Reflection.Assembly.GetExecutingAssembly().FullName;
//"EPA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
str = typeof(Program).FullName;
//"EPA.Program"
str = typeof(Program).Assembly.FullName;
//"EPA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
str = typeof(Program).Assembly.ToString();
//"EPA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
str = typeof(Program).AssemblyQualifiedName;
//"EPA.Program, EPA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
}
推荐答案
System.Reflection.Assembly.GetExecutingAssembly().GetName().Name
或
typeof(Program).Assembly.GetName().Name;
这篇关于获取程序集名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文