Example

For brevity, the program only checks for the existence of one custom attribute, but for completeness attributes are applied to most targets in the source code.

 using System; using System.Reflection; [assembly: Samples.MyCustom] [module: Samples.MyCustom] namespace Samples { [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)] public class MyCustomAttribute: Attribute {} public class Foo {} public interface IFoo { [MyCustom] int age { get;} } [MyCustom] public struct Bar {} [MyCustom] public class AttributeUsageSample { [MyCustom] enum Color {black, white} [MyCustom] public delegate int D(); [MyCustom] public event D MyD; [MyCustom] private int i; [MyCustom] public static void Main() { Assembly e = Assembly.GetExecutingAssembly(); ...

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.