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