2 // System.Reflection.Emit.DerivedTypes.cs
5 // Rodrigo Kumpera <rkumpera@novell.com>
8 // Copyright (C) 2009 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Reflection;
31 using System.Reflection.Emit;
32 using System.Collections;
33 using System.Runtime.CompilerServices;
34 using System.Globalization;
35 using System.Runtime.InteropServices;
36 using System.Runtime.Serialization;
40 namespace System.Reflection.Emit
42 internal enum TypeKind : int {
47 internal abstract class DerivedType : Type
49 internal Type elementType;
51 [MethodImplAttribute(MethodImplOptions.InternalCall)]
52 internal static extern void create_unmanaged_type (Type type);
54 internal DerivedType (Type elementType)
56 this.elementType = elementType;
59 internal abstract String FormatName (string elementName);
61 public override Type GetInterface (string name, bool ignoreCase)
63 throw new NotSupportedException ();
66 public override Type[] GetInterfaces ()
68 throw new NotSupportedException ();
71 public override Type GetElementType ()
76 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
78 throw new NotSupportedException ();
81 public override EventInfo[] GetEvents (BindingFlags bindingAttr)
83 throw new NotSupportedException ();
86 public override FieldInfo GetField( string name, BindingFlags bindingAttr)
88 throw new NotSupportedException ();
91 public override FieldInfo[] GetFields (BindingFlags bindingAttr)
93 throw new NotSupportedException ();
96 public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
98 throw new NotSupportedException ();
101 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
102 CallingConventions callConvention, Type[] types,
103 ParameterModifier[] modifiers)
105 throw new NotSupportedException ();
108 public override MethodInfo[] GetMethods (BindingFlags bindingAttr)
110 throw new NotSupportedException ();
113 public override Type GetNestedType (string name, BindingFlags bindingAttr)
115 throw new NotSupportedException ();
118 public override Type[] GetNestedTypes (BindingFlags bindingAttr)
120 throw new NotSupportedException ();
123 public override PropertyInfo[] GetProperties (BindingFlags bindingAttr)
125 throw new NotSupportedException ();
128 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
129 Type returnType, Type[] types, ParameterModifier[] modifiers)
131 throw new NotSupportedException ();
134 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
136 CallingConventions callConvention,
138 ParameterModifier[] modifiers)
140 throw new NotSupportedException ();
144 protected override TypeAttributes GetAttributeFlagsImpl ()
146 /*LAMEIMPL MS just return the elementType.Attributes*/
147 return elementType.Attributes;
150 protected override bool HasElementTypeImpl ()
155 protected override bool IsArrayImpl ()
160 protected override bool IsByRefImpl ()
165 protected override bool IsCOMObjectImpl ()
170 protected override bool IsPointerImpl ()
175 protected override bool IsPrimitiveImpl ()
181 public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
183 throw new NotSupportedException ();
186 public override object InvokeMember (string name, BindingFlags invokeAttr,
187 Binder binder, object target, object[] args,
188 ParameterModifier[] modifiers,
189 CultureInfo culture, string[] namedParameters)
191 throw new NotSupportedException ();
194 public override InterfaceMapping GetInterfaceMap (Type interfaceType)
196 throw new NotSupportedException ();
199 public override bool IsInstanceOfType (object o)
205 //FIXME this should be handled by System.Type
206 public override Type MakeGenericType (params Type[] typeArguments)
208 throw new NotSupportedException ();
211 public override Type MakeArrayType ()
213 return MakeArrayType (1);
216 public override Type MakeArrayType (int rank)
219 throw new IndexOutOfRangeException ();
220 return new ArrayType (this, rank);
223 public override Type MakeByRefType ()
225 return new ByRefType (this);
228 public override Type MakePointerType ()
230 return new PointerType (this);
233 public override GenericParameterAttributes GenericParameterAttributes {
234 get { throw new NotSupportedException (); }
237 public override StructLayoutAttribute StructLayoutAttribute {
238 get { throw new NotSupportedException (); }
242 public override Assembly Assembly {
243 get { return elementType.Assembly; }
246 public override string AssemblyQualifiedName {
247 get { return FullName + ", " + elementType.Assembly.FullName; }
251 public override string FullName {
253 return FormatName (elementType.FullName);
257 public override string Name {
259 return FormatName (elementType.Name);
263 public override Guid GUID {
264 get { throw new NotSupportedException (); }
267 public override Module Module {
268 get { return elementType.Module; }
271 public override string Namespace {
272 get { return elementType.Namespace; }
275 public override RuntimeTypeHandle TypeHandle {
276 get { throw new NotSupportedException (); }
279 public override Type UnderlyingSystemType {
284 public override bool IsDefined (Type attributeType, bool inherit)
286 throw new NotSupportedException ();
289 public override object [] GetCustomAttributes (bool inherit)
291 throw new NotSupportedException ();
294 public override object [] GetCustomAttributes (Type attributeType, bool inherit)
296 throw new NotSupportedException ();
300 internal class ArrayType : DerivedType
304 internal ArrayType (Type elementType, int rank) : base (elementType)
309 protected override bool IsArrayImpl ()
314 public override int GetArrayRank ()
319 public override Type BaseType {
320 get { return typeof (System.Array); }
323 internal override String FormatName (string elementName)
325 StringBuilder sb = new StringBuilder (elementName);
327 for (int i = 1; i < rank; ++i)
330 return sb.ToString ();
335 internal class ByRefType : DerivedType
337 internal ByRefType (Type elementType) : base (elementType)
341 protected override bool IsByRefImpl ()
346 public override Type BaseType {
350 internal override String FormatName (string elementName)
352 return elementName + "&";
356 public override Type MakeArrayType ()
358 throw new ArgumentException ("Cannot create an array type of a byref type");
361 public override Type MakeArrayType (int rank)
363 throw new ArgumentException ("Cannot create an array type of a byref type");
366 public override Type MakeByRefType ()
368 throw new ArgumentException ("Cannot create a byref type of an already byref type");
371 public override Type MakePointerType ()
373 throw new ArgumentException ("Cannot create a pointer type of a byref type");
379 internal class PointerType : DerivedType
381 internal PointerType (Type elementType) : base (elementType)
385 protected override bool IsPointerImpl ()
390 public override Type BaseType {
394 internal override String FormatName (string elementName)
396 return elementName + "*";