Merge pull request #260 from pcc/topmost
[mono.git] / mcs / class / corlib / System.Reflection / TypeInfo.cs
1 //
2 // TypeInfo.cs
3 //
4 // Authors:
5 //    Marek Safar  <marek.safar@gmail.com>
6 //    Martin Baulig <martin.baulig@xamarin.com>
7 //
8 // Copyright (c) 2011-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 #if NET_4_5
29 using System.Collections.Generic;
30
31 namespace System.Reflection
32 {
33         public abstract class TypeInfo : Type, IReflectableType
34         {
35                 internal TypeInfo ()
36                 {
37                 }
38                 
39                 TypeInfo IReflectableType.GetTypeInfo ()
40                 {
41                         return this;
42                 }
43
44                 const BindingFlags declaredFlags = BindingFlags.DeclaredOnly |
45                         BindingFlags.Public | BindingFlags.NonPublic |
46                                 BindingFlags.Static | BindingFlags.Instance;
47                 
48                 public virtual IEnumerable<ConstructorInfo> DeclaredConstructors {
49                         get { return GetConstructors (declaredFlags); }
50                 }
51                 
52                 public virtual IEnumerable<EventInfo> DeclaredEvents {
53                         get { return GetEvents (declaredFlags); }
54                 }
55                 
56                 public virtual IEnumerable<FieldInfo> DeclaredFields {
57                         get { return GetFields (declaredFlags); }
58                 }
59                 
60                 public virtual IEnumerable<MethodInfo> DeclaredMethods {
61                         get { return GetMethods (declaredFlags); }
62                 }
63                 
64                 public virtual IEnumerable<PropertyInfo> DeclaredProperties {
65                         get { return GetProperties (declaredFlags); }
66                 }
67                 
68                 public virtual IEnumerable<MemberInfo> DeclaredMembers {
69                         get {
70                                 return GetMembers (declaredFlags);
71                         }
72                 }
73                 
74                 public virtual IEnumerable<TypeInfo> DeclaredNestedTypes {
75                         get {
76                                 foreach (var nested in GetNestedTypes (declaredFlags))
77                                         yield return new TypeDelegator (nested);
78                         }
79                 }
80                 
81                 public virtual Type[] GenericTypeParameters {
82                         get {
83                                 if (!ContainsGenericParameters)
84                                         return EmptyTypes;
85
86                                 return GetGenericArguments ();
87                         }
88                 }
89
90                 public virtual IEnumerable<Type> ImplementedInterfaces {
91                         get {
92                                 return GetInterfaces ();
93                         }
94                 }
95
96                 public virtual Type AsType ()
97                 {
98                         return this;
99                 }
100
101                 public virtual EventInfo GetDeclaredEvent (string name)
102                 {
103                         return GetEvent (name, declaredFlags);
104                 }
105
106                 public virtual FieldInfo GetDeclaredField (string name)
107                 {
108                         return GetField (name, declaredFlags);
109                 }
110
111                 public virtual MethodInfo GetDeclaredMethod (string name)
112                 {
113                         return GetMethod (name, declaredFlags);
114                 }
115
116                 public virtual IEnumerable<MethodInfo> GetDeclaredMethods (string name)
117                 {
118                         foreach (var method in GetMethods (declaredFlags))
119                                 if (method.Name.Equals (name))
120                                         yield return method;
121                 }
122
123                 public virtual TypeInfo GetDeclaredNestedType (string name)
124                 {
125                         var nested = GetNestedType (name, declaredFlags);
126                         if (nested != null)
127                                 return new TypeDelegator (nested);
128                         else
129                                 return null;
130                 }
131
132                 public virtual PropertyInfo GetDeclaredProperty (string name)
133                 {
134                         return GetProperty (name, declaredFlags);
135                 }
136
137                 public virtual bool IsAssignableFrom (TypeInfo typeInfo)
138                 {
139                         return IsAssignableFrom (typeInfo.AsType ());
140                 }
141         }
142 }
143 #endif