March 2004
Intermediate to advanced
560 pages
26h 47m
English
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(); ...Read now
Unlock full access