main
 1using System;
 2using System.Linq;
 3using System.Reflection;
 4
 5namespace jive
 6{
 7  public static class TypeExtensions
 8  {
 9    public static Type last_interface(this Type type)
10    {
11      return type.GetInterfaces()[type.GetInterfaces().Length - 1];
12    }
13
14    public static Type first_interface(this Type type)
15    {
16      return type.GetInterfaces()[0];
17    }
18
19    public static bool is_a_generic_type(this Type type)
20    {
21      //return type.IsGenericType;
22      return type.IsGenericTypeDefinition;
23    }
24
25    public static object default_value(this Type type)
26    {
27      return (type.IsValueType ? Activator.CreateInstance(type) : null);
28    }
29
30    public static Attribute get_attribute<Attribute>(this ICustomAttributeProvider provider)
31      where Attribute : System.Attribute
32      {
33        return
34          provider
35          .GetCustomAttributes(typeof (Attribute), false)
36          .Select(x => x.downcast_to<Attribute>())
37          .First();
38      }
39  }
40}