main
 1using System;
 2using System.Reflection;
 3
 4namespace momoney.utility
 5{
 6    static public class AttributeExtensions
 7    {
 8        static public bool is_decorated_with<T>(this object item) where T : Attribute
 9        {
10            return item.GetType().is_decorated_with<T>();
11        }
12
13        static public bool is_decorated_with<T>(this ICustomAttributeProvider item) where T : Attribute
14        {
15            return item.IsDefined(typeof (T), true);
16        }
17
18        static public T attribute<T>(this object item) where T : Attribute
19        {
20            return item.GetType().attribute<T>();
21        }
22
23        static public T attribute<T>(this ICustomAttributeProvider item) where T : Attribute
24        {
25            return (T) item.GetCustomAttributes(typeof (T), true)[0];
26        }
27    }
28}