WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
MethodInfoExtensions.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Reflection;
6 
7 
8 public static class MethodInfoExtensions
9 {
10  public static bool HasAttribute(this MethodInfo I, Type AttributeType)
11  {
12  if (!AttributeType.IsAbstract && typeof(Attribute).IsAssignableFrom(AttributeType))
13  {
14  foreach (object attribute in I.GetCustomAttributes(true))
15  {
16  if (attribute.GetType() == AttributeType)
17  {
18  return true;
19  }
20  }
21  return false;
22  }
23  else
24  {
25  throw new Exception("{0} is not a attribute");
26  }
27  }
28 
29  public static AttributeType GetAttribute<AttributeType> (this MethodInfo I) where AttributeType:Attribute
30  {
31  if (!typeof(AttributeType).IsAbstract)
32  {
33  return (AttributeType)I.GetCustomAttributes(typeof(AttributeType),true).FirstOrDefault();
34  }
35  else
36  {
37  throw new Exception("{0} is abstract");
38  }
39 
40  }
41 
42 }
43