Как читать атрибуты сборки

Я создал этот метод расширения, который reflect использует Linq:

public static T GetAssemblyAttribute(this System.Reflection.Assembly ass) where T :  Attribute
{
    object[] attributes = ass.GetCustomAttributes(typeof(T), false);
    if (attributes == null || attributes.Length == 0)
        return null;
    return attributes.OfType().SingleOrDefault();
}

и тогда вы dotnet можете удобно использовать reflect это так:

var attr = targetAssembly.GetAssemblyAttribute();
if(attr != null)
     Console.WriteLine("{0} Assembly Description:{1}", Environment.NewLine, attr.Description);

.net

reflection

assemblies

attributes

2022-11-09T00:10:47+00:00