3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 /*=============================================================================
10 ** <OWNER>Microsoft</OWNER>
13 ** Purpose: Notion of a type definition
16 =============================================================================*/
18 namespace System.Reflection
21 using System.Runtime.CompilerServices;
22 using System.Collections.Generic;
23 using System.Diagnostics.Contracts;
25 //all today's runtime Type derivations derive now from TypeInfo
26 //we make TypeInfo implement IRCT - simplifies work
27 [System.Runtime.InteropServices.ComVisible(true)]
29 public abstract class TypeInfo:Type,IReflectableType
32 internal TypeInfo() { }
34 TypeInfo IReflectableType.GetTypeInfo(){
37 public virtual Type AsType(){
41 public virtual Type[] GenericTypeParameters{
43 if(IsGenericTypeDefinition){
44 return GetGenericArguments();
47 return Type.EmptyTypes;
52 //a re-implementation of ISAF from Type, skipping the use of UnderlyingType
54 public virtual bool IsAssignableFrom(TypeInfo typeInfo)
62 // If c is a subclass of this class, then c can be cast to this type.
63 if (typeInfo.IsSubclassOf(this))
68 return typeInfo.ImplementInterface(this);
70 else if (IsGenericParameter)
72 Type[] constraints = GetGenericParameterConstraints();
73 for (int i = 0; i < constraints.Length; i++)
74 if (!constraints[i].IsAssignableFrom(typeInfo))
82 #region moved over from Type
85 public virtual EventInfo GetDeclaredEvent(String name)
87 return GetEvent(name, Type.DeclaredOnlyLookup);
89 public virtual FieldInfo GetDeclaredField(String name)
91 return GetField(name, Type.DeclaredOnlyLookup);
93 public virtual MethodInfo GetDeclaredMethod(String name)
95 return GetMethod(name, Type.DeclaredOnlyLookup);
98 public virtual IEnumerable<MethodInfo> GetDeclaredMethods(String name)
100 foreach (MethodInfo method in GetMethods(Type.DeclaredOnlyLookup))
102 if (method.Name == name)
106 public virtual System.Reflection.TypeInfo GetDeclaredNestedType(String name)
108 var nt=GetNestedType(name, Type.DeclaredOnlyLookup);
110 return null; //the extension method GetTypeInfo throws for null
112 return nt.GetTypeInfo();
115 public virtual PropertyInfo GetDeclaredProperty(String name)
117 return GetProperty(name, Type.DeclaredOnlyLookup);
126 public virtual IEnumerable<ConstructorInfo> DeclaredConstructors
130 return GetConstructors(Type.DeclaredOnlyLookup);
134 public virtual IEnumerable<EventInfo> DeclaredEvents
138 return GetEvents(Type.DeclaredOnlyLookup);
142 public virtual IEnumerable<FieldInfo> DeclaredFields
146 return GetFields(Type.DeclaredOnlyLookup);
150 public virtual IEnumerable<MemberInfo> DeclaredMembers
154 return GetMembers(Type.DeclaredOnlyLookup);
158 public virtual IEnumerable<MethodInfo> DeclaredMethods
162 return GetMethods(Type.DeclaredOnlyLookup);
165 public virtual IEnumerable<System.Reflection.TypeInfo> DeclaredNestedTypes
169 foreach (var t in GetNestedTypes(Type.DeclaredOnlyLookup)){
170 yield return t.GetTypeInfo();
175 public virtual IEnumerable<PropertyInfo> DeclaredProperties
179 return GetProperties(Type.DeclaredOnlyLookup);
184 public virtual IEnumerable<Type> ImplementedInterfaces
188 return GetInterfaces();