You can use an abstract class to check attributes when initializing a class.
abstract class MustImpliment { protected MustImpliment() { object[] attributes = this.GetType().GetCustomAttributes(typeof(DescriptionAttribute), true); if (attributes == null || attributes.Length == 0) throw new NotImplementedException("Pick a better exception"); }
Update: this will not cause a compiler error, but you can use it as part of the Unit Test, as suggested by Jerod Hewtelling.
chilltemp
source share