5 // Marek Safar <marek.safar@gmail.com>
6 // Martin Baulig <martin.baulig@xamarin.com>
8 // Copyright (c) 2011-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 abstract class TypeInfo : Type, IReflectableType
39 TypeInfo IReflectableType.GetTypeInfo ()
44 static readonly BindingFlags declaredFlags = BindingFlags.DeclaredOnly |
45 BindingFlags.Public | BindingFlags.NonPublic |
46 BindingFlags.Static | BindingFlags.Instance;
48 public virtual IEnumerable<ConstructorInfo> DeclaredConstructors {
49 get { return GetConstructors (declaredFlags); }
52 public virtual IEnumerable<EventInfo> DeclaredEvents {
53 get { return GetEvents (declaredFlags); }
56 public virtual IEnumerable<FieldInfo> DeclaredFields {
57 get { return GetFields (declaredFlags); }
60 public virtual IEnumerable<MethodInfo> DeclaredMethods {
61 get { return GetMethods (declaredFlags); }
64 public virtual IEnumerable<PropertyInfo> DeclaredProperties {
65 get { return GetProperties (declaredFlags); }
68 public virtual IEnumerable<MemberInfo> DeclaredMembers {
70 var ret = new List<MemberInfo> ();
71 ret.AddRange (DeclaredConstructors);
72 ret.AddRange (DeclaredEvents);
73 ret.AddRange (DeclaredFields);
74 ret.AddRange (DeclaredMethods);
75 ret.AddRange (DeclaredProperties);
76 return ret.AsReadOnly ();
80 public virtual IEnumerable<TypeInfo> DeclaredNestedTypes {
82 foreach (var nested in GetNestedTypes (declaredFlags))
83 yield return new TypeDelegator (nested);
87 public virtual Type[] GenericTypeParameters {
89 if (!ContainsGenericParameters)
91 return GetGenericArguments ();
95 static bool list_contains (IEnumerable<Type> types, Type type)
97 foreach (var t in types) {
105 public virtual IEnumerable<Type> ImplementedInterfaces {
107 var all = GetInterfaces ();
108 var baseIfaces = BaseType != null ? BaseType.GetInterfaces () : new Type [0];
109 foreach (var iface in all)
110 if (!list_contains (baseIfaces, iface))
115 public virtual Type AsType ()
120 public virtual EventInfo GetDeclaredEvent (string name)
122 return GetEvent (name, declaredFlags);
125 public virtual FieldInfo GetDeclaredField (string name)
127 return GetField (name, declaredFlags);
130 public virtual MethodInfo GetDeclaredMethod (string name)
132 return GetMethod (name, declaredFlags);
135 public virtual IEnumerable<MethodInfo> GetDeclaredMethods (string name)
137 foreach (var method in GetMethods (declaredFlags))
138 if (method.Name.Equals (name))
142 public virtual TypeInfo GetDeclaredNestedType (string name)
144 var nested = GetNestedType (name, declaredFlags);
146 return new TypeDelegator (nested);
151 public virtual PropertyInfo GetDeclaredProperty (string name)
153 return GetProperty (name, declaredFlags);
156 public virtual bool IsAssignableFrom (TypeInfo typeInfo)
158 return IsAssignableFrom (typeInfo.AsType ());