Com*_*ser 27 .net c# .net-assembly
我Assembly.GetEntryAssembly().GetName()
用来获取应用程序/程序集名称及其版本,但我没有看到公司名称和版权的任何变量.我怎么做到的?
Ale*_*ria 47
您可以像这样使用FileVersionInfo:
var versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location);
var companyName = versionInfo.CompanyName;
Run Code Online (Sandbox Code Playgroud)
Geo*_*ett 10
Assembly currentAssem = typeof(CurrentClass).Assembly;
object[] attribs = currentAssem.GetCustomAttributes(typeof(AssemblyCompanyAttribute), true);
if(attribs.Length > 0)
{
string company = ((AssemblyCompanyAttribute)attribs[0]).Company
}
Run Code Online (Sandbox Code Playgroud)
类似的版权.(使用AssemblyCopyrightAttribute
).
这些是您必须使用反射在 Assembly 对象上枚举的属性。
var attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
var attribute = null;
if (attributes.Length > 0)
{
attribute = attributes[0] as AssemblyCompanyAttribute;
}
Run Code Online (Sandbox Code Playgroud)