2 // RuntimeReflectionExtensions.cs
5 // Martin Baulig <martin.baulig@xamarin.com>
6 // Marek Safar (marek.safar@gmail.com)
8 // Copyright (c) 2013 Xamarin Inc. (http://www.xamarin.com)
10 // Permission is hereby granted, free of charge, to any person obtaining a copy
11 // of this software and associated documentation files (the "Software"), to deal
12 // in the Software without restriction, including without limitation the rights
13 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 // copies of the Software, and to permit persons to whom the Software is
15 // furnished to do so, subject to the following conditions:
17 // The above copyright notice and this permission notice shall be included in
18 // all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30 using System.Collections.Generic;
32 namespace System.Reflection
34 public static class RuntimeReflectionExtensions
36 const BindingFlags AllMembersBindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;
38 public static MethodInfo GetMethodInfo (this Delegate del)
41 throw new ArgumentNullException ("del");
46 public static MethodInfo GetRuntimeBaseDefinition (this MethodInfo method)
49 throw new ArgumentNullException ("method");
51 return method.GetBaseDefinition ();
54 public static EventInfo GetRuntimeEvent (this Type type, string name)
57 throw new ArgumentNullException ("type");
59 return type.GetEvent (name);
62 public static IEnumerable<EventInfo> GetRuntimeEvents (this Type type)
65 throw new ArgumentNullException ("type");
67 return type.GetEvents (AllMembersBindingFlags);
70 public static FieldInfo GetRuntimeField (this Type type, string name)
73 throw new ArgumentNullException ("type");
75 return type.GetField (name);
78 public static IEnumerable<FieldInfo> GetRuntimeFields (this Type type)
81 throw new ArgumentNullException ("type");
83 return type.GetFields (AllMembersBindingFlags);
86 public static InterfaceMapping GetRuntimeInterfaceMap (this TypeInfo typeInfo, Type interfaceType)
89 throw new ArgumentNullException ("typeInfo");
91 return typeInfo.GetInterfaceMap (interfaceType);
94 public static MethodInfo GetRuntimeMethod (this Type type, string name, Type[] parameters)
97 throw new ArgumentNullException ("type");
99 return type.GetMethod (name, parameters);
102 public static IEnumerable<MethodInfo> GetRuntimeMethods (this Type type)
105 throw new ArgumentNullException ("type");
107 return type.GetMethods (AllMembersBindingFlags);
110 public static IEnumerable<PropertyInfo> GetRuntimeProperties (this Type type)
113 throw new ArgumentNullException ("type");
115 return type.GetProperties (AllMembersBindingFlags);
118 public static PropertyInfo GetRuntimeProperty (this Type type, string name)
121 throw new ArgumentNullException ("type");
123 return type.GetProperty (name);