阅读大会作者

问题描述 投票:1回答:1

读取程序集的某些元数据,只需加载Assembly,然后获取自定义属性,就很容易,例如:

Assembly assembly = Assembly.GetExecutingAssembly();
AssemblyTitleAttribute? attribute = assembly.GetCustomAttribute<AssemblyTitleAttribute>();
string? title = attribute?.Title;

您可以将AssemblyTitleAttribute替换为CopyrightTrademarkDescriptionVersion等一些其他名称,但我找不到Authors的某些内容(可以在在项目解决方案的程序包选项卡上,位置与其他位置相同)。

enter image description here

任何想法,为什么缺少此属性以及如何读取它的值? (我使用的是dotnet标准2.1)

c# .net-core attributes metadata .net-assembly
1个回答
0
投票

默认情况下,AttributeNo个程序集Authors

这里是IEnumerable<Attribute>个项目的列表,Authors不是其中之一

System.Runtime.CompilerServices.CompilationRelaxationsAttribute
System.Runtime.CompilerServices.RuntimeCompatibilityAttribute
System.Diagnostics.DebuggableAttribute
System.Reflection.AssemblyTitleAttribute
System.Reflection.AssemblyDescriptionAttribute
System.Reflection.AssemblyConfigurationAttribute
System.Reflection.AssemblyCompanyAttribute
System.Reflection.AssemblyProductAttribute
System.Reflection.AssemblyCopyrightAttribute
System.Reflection.AssemblyTrademarkAttribute
System.Runtime.InteropServices.ComVisibleAttribute
System.Runtime.InteropServices.GuidAttribute
System.Reflection.AssemblyFileVersionAttribute
System.Runtime.Versioning.TargetFrameworkAttribute

但是,我相信您指的是ExtendedFileAttributes here

例如,您可以更改MS-Word文档的作者属性,但默认情况下不更改exe的作者属性,因为每种文件类型都具有特定的扩展文件属性,并且并非所有属性都是可写的。

参考:

Setting Extended Properties

Custom Assembly Attributes

© www.soinside.com 2019 - 2024. All rights reserved.