Fix null sessions in HttpContextWrapper.Session
[mono.git] / mcs / class / IKVM.Reflection / TypeInfo.cs
1 /*
2   Copyright (C) 2012 Jeroen Frijters
3
4   This software is provided 'as-is', without any express or implied
5   warranty.  In no event will the authors be held liable for any damages
6   arising from the use of this software.
7
8   Permission is granted to anyone to use this software for any purpose,
9   including commercial applications, and to alter it and redistribute it
10   freely, subject to the following restrictions:
11
12   1. The origin of this software must not be misrepresented; you must not
13      claim that you wrote the original software. If you use this software
14      in a product, an acknowledgment in the product documentation would be
15      appreciated but is not required.
16   2. Altered source versions must be plainly marked as such, and must not be
17      misrepresented as being the original software.
18   3. This notice may not be removed or altered from any source distribution.
19
20   Jeroen Frijters
21   jeroen@frijters.net
22   
23 */
24 using System;
25 using System.Collections.Generic;
26
27 namespace IKVM.Reflection
28 {
29         public interface IReflectableType
30         {
31                 TypeInfo GetTypeInfo();
32         }
33
34         public static class IntrospectionExtensions
35         {
36                 // we target .NET 2.0 so we can't define an extension method
37                 public static TypeInfo GetTypeInfo(/*this*/ Type type)
38                 {
39                         return type.GetTypeInfo();
40                 }
41         }
42
43         public abstract class TypeInfo : Type, IReflectableType
44         {
45                 private const BindingFlags Flags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;
46
47                 internal TypeInfo()
48                 {
49                 }
50
51                 internal TypeInfo(Type underlyingType)
52                         : base(underlyingType)
53                 {
54                 }
55
56                 public IEnumerable<ConstructorInfo> DeclaredConstructors
57                 {
58                         get { return GetConstructors(Flags); }
59                 }
60
61                 public IEnumerable<EventInfo> DeclaredEvents
62                 {
63                         get { return GetEvents(Flags); }
64                 }
65
66                 public IEnumerable<FieldInfo> DeclaredFields
67                 {
68                         get { return GetFields(Flags); }
69                 }
70
71                 public IEnumerable<MemberInfo> DeclaredMembers
72                 {
73                         get { return GetMembers(Flags); }
74                 }
75
76                 public IEnumerable<MethodInfo> DeclaredMethods
77                 {
78                         get { return GetMethods(Flags); }
79                 }
80
81                 public IEnumerable<TypeInfo> DeclaredNestedTypes
82                 {
83                         get
84                         {
85                                 Type[] types = GetNestedTypes(Flags);
86                                 TypeInfo[] typeInfos = new TypeInfo[types.Length];
87                                 for (int i = 0; i < types.Length; i++)
88                                 {
89                                         typeInfos[i] = types[i].GetTypeInfo();
90                                 }
91                                 return typeInfos;
92                         }
93                 }
94
95                 public IEnumerable<PropertyInfo> DeclaredProperties
96                 {
97                         get { return GetProperties(Flags); }
98                 }
99
100                 public Type[] GenericTypeParameters
101                 {
102                         get { return IsGenericTypeDefinition ? GetGenericArguments() : Type.EmptyTypes; }
103                 }
104
105                 public IEnumerable<Type> ImplementedInterfaces
106                 {
107                         get { return __GetDeclaredInterfaces(); }
108                 }
109
110                 public Type AsType()
111                 {
112                         return this;
113                 }
114
115                 public EventInfo GetDeclaredEvent(string name)
116                 {
117                         return GetEvent(name, Flags);
118                 }
119
120                 public FieldInfo GetDeclaredField(string name)
121                 {
122                         return GetField(name, Flags);
123                 }
124
125                 public MethodInfo GetDeclaredMethod(string name)
126                 {
127                         return GetMethod(name, Flags);
128                 }
129
130                 public IEnumerable<MethodInfo> GetDeclaredMethods(string name)
131                 {
132                         List<MethodInfo> methods = new List<MethodInfo>();
133                         foreach (MethodInfo method in GetMethods(Flags))
134                         {
135                                 if (method.Name == name)
136                                 {
137                                         methods.Add(method);
138                                 }
139                         }
140                         return methods;
141                 }
142
143                 public TypeInfo GetDeclaredNestedType(string name)
144                 {
145                         return GetNestedType(name, Flags).GetTypeInfo();
146                 }
147
148                 public PropertyInfo GetDeclaredProperty(string name)
149                 {
150                         return GetProperty(name, Flags);
151                 }
152
153                 public bool IsAssignableFrom(TypeInfo typeInfo)
154                 {
155                         return base.IsAssignableFrom(typeInfo);
156                 }
157         }
158 }