using System; using System.Linq; using System.Collections.Generic; using System.Collections.Concurrent; using System.Reflection; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; var data = CustomAttributeData.GetCustomAttributes(typeof(Annotated)).Single(item => item.AttributeType == typeof(MarkerAttribute)); Console.WriteLine($"data:{data.ConstructorArguments[0].Value}"); Console.WriteLine($"constructors:{MarkerAttribute.Created}"); var instance = (MarkerAttribute)Attribute.GetCustomAttribute(typeof(Annotated), typeof(MarkerAttribute))!; Console.WriteLine($"instance:{instance.Name}"); Console.WriteLine($"constructors:{MarkerAttribute.Created}"); [Marker("demo")] sealed class Annotated { } [AttributeUsage(AttributeTargets.Class)] sealed class MarkerAttribute : Attribute { public static int Created; public string Name { get; } public MarkerAttribute(string name) { Name = name; Created++; } }