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
29 using System.Collections.Generic;
31 namespace System.Reflection
33 public static class RuntimeReflectionExtensions
35 const BindingFlags AllMembersBindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;
37 public static MethodInfo GetMethodInfo (this Delegate del)
40 throw new ArgumentNullException ("del");
45 public static MethodInfo GetRuntimeBaseDefinition (this MethodInfo method)
48 throw new ArgumentNullException ("method");
50 return method.GetBaseDefinition ();
53 public static EventInfo GetRuntimeEvent (this Type type, string name)
56 throw new ArgumentNullException ("type");
58 return type.GetEvent (name);
61 public static IEnumerable<EventInfo> GetRuntimeEvents (this Type type)
64 throw new ArgumentNullException ("type");
66 return type.GetEvents (AllMembersBindingFlags);
69 public static FieldInfo GetRuntimeField (this Type type, string name)
72 throw new ArgumentNullException ("type");
74 return type.GetField (name);
77 public static IEnumerable<FieldInfo> GetRuntimeFields (this Type type)
80 throw new ArgumentNullException ("type");
82 return type.GetFields (AllMembersBindingFlags);
85 public static InterfaceMapping GetRuntimeInterfaceMap (this TypeInfo typeInfo, Type interfaceType)
88 throw new ArgumentNullException ("typeInfo");
90 return typeInfo.GetInterfaceMap (interfaceType);
93 public static MethodInfo GetRuntimeMethod (this Type type, string name, Type[] parameters)
96 throw new ArgumentNullException ("type");
98 return type.GetMethod (name, parameters);
101 public static IEnumerable<MethodInfo> GetRuntimeMethods (this Type type)
104 throw new ArgumentNullException ("type");
106 return type.GetMethods (AllMembersBindingFlags);
109 public static IEnumerable<PropertyInfo> GetRuntimeProperties (this Type type)
112 throw new ArgumentNullException ("type");
114 return type.GetProperties (AllMembersBindingFlags);
117 public static PropertyInfo GetRuntimeProperty (this Type type, string name)
120 throw new ArgumentNullException ("type");
122 return type.GetProperty (name);