[runtime] Updates comments.
[mono.git] / mcs / class / corlib / System.Reflection / RuntimeReflectionExtensions.cs
1 //
2 // RuntimeReflectionExtensions.cs
3 //
4 // Authors:
5 //       Martin Baulig <martin.baulig@xamarin.com>
6 //       Marek Safar (marek.safar@gmail.com)
7 //
8 // Copyright (c) 2013 Xamarin Inc. (http://www.xamarin.com)
9 //
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:
16 //
17 // The above copyright notice and this permission notice shall be included in
18 // all copies or substantial portions of the Software.
19 //
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
26 // THE SOFTWARE.
27
28
29 using System.Collections.Generic;
30
31 namespace System.Reflection
32 {
33         public static class RuntimeReflectionExtensions
34         {
35                 const BindingFlags AllMembersBindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;
36
37                 public static MethodInfo GetMethodInfo (this Delegate del)
38                 {
39                         if (del == null)
40                                 throw new ArgumentNullException ("del");
41
42                         return del.Method;
43                 }
44
45                 public static MethodInfo GetRuntimeBaseDefinition (this MethodInfo method)
46                 {
47                         if (method == null)
48                                 throw new ArgumentNullException ("method");
49
50                         return method.GetBaseDefinition ();
51                 }
52
53                 public static EventInfo GetRuntimeEvent (this Type type, string name)
54                 {
55                         if (type == null)
56                                 throw new ArgumentNullException ("type");
57
58                         return type.GetEvent (name);
59                 }
60
61                 public static IEnumerable<EventInfo> GetRuntimeEvents (this Type type)
62                 {
63                         if (type == null)
64                                 throw new ArgumentNullException ("type");
65
66                         return type.GetEvents (AllMembersBindingFlags);
67                 }
68
69                 public static FieldInfo GetRuntimeField (this Type type, string name)
70                 {
71                         if (type == null)
72                                 throw new ArgumentNullException ("type");
73
74                         return type.GetField (name);
75                 }
76
77                 public static IEnumerable<FieldInfo> GetRuntimeFields (this Type type)
78                 {
79                         if (type == null)
80                                 throw new ArgumentNullException ("type");
81
82                         return type.GetFields (AllMembersBindingFlags);
83                 }
84
85                 public static InterfaceMapping GetRuntimeInterfaceMap (this TypeInfo typeInfo, Type interfaceType)
86                 {
87                         if (typeInfo == null)
88                                 throw new ArgumentNullException ("typeInfo");
89
90                         return typeInfo.GetInterfaceMap (interfaceType);
91                 }
92
93                 public static MethodInfo GetRuntimeMethod (this Type type, string name, Type[] parameters)
94                 {
95                         if (type == null)
96                                 throw new ArgumentNullException ("type");
97
98                         return type.GetMethod (name, parameters);
99                 }
100
101                 public static IEnumerable<MethodInfo> GetRuntimeMethods (this Type type)
102                 {
103                         if (type == null)
104                                 throw new ArgumentNullException ("type");
105
106                         return type.GetMethods (AllMembersBindingFlags);
107                 }
108
109                 public static IEnumerable<PropertyInfo> GetRuntimeProperties (this Type type)
110                 {
111                         if (type == null)
112                                 throw new ArgumentNullException ("type");
113
114                         return type.GetProperties (AllMembersBindingFlags);
115                 }
116
117                 public static PropertyInfo GetRuntimeProperty (this Type type, string name)
118                 {
119                         if (type == null)
120                                 throw new ArgumentNullException ("type");
121
122                         return type.GetProperty (name);
123                 }
124         }
125 }
126