2010-04-06 Jb Evain <jbevain@novell.com>
[mcs.git] / class / corlib / System.Reflection.Emit / DerivedTypes.cs
blob43ff5e6a7aabbbe418f2f42e7bd89c45c9e81755
1 //
2 // System.Reflection.Emit.DerivedTypes.cs
3 //
4 // Authors:
5 // Rodrigo Kumpera <rkumpera@novell.com>
6 //
7 //
8 // Copyright (C) 2009 Novell, Inc (http://www.novell.com)
9 //
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:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
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;
37 using System.Text;
40 namespace System.Reflection.Emit
42 internal enum TypeKind : int {
43 SZARRAY = 0x1d,
44 ARRAY = 0x14
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 internal override bool IsCompilerContext {
62 get {
63 return elementType.IsCompilerContext;
67 public override Type GetInterface (string name, bool ignoreCase)
69 throw new NotSupportedException ();
72 public override Type[] GetInterfaces ()
74 throw new NotSupportedException ();
77 public override Type GetElementType ()
79 return elementType;
82 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
84 throw new NotSupportedException ();
87 public override EventInfo[] GetEvents (BindingFlags bindingAttr)
89 throw new NotSupportedException ();
92 public override FieldInfo GetField( string name, BindingFlags bindingAttr)
94 throw new NotSupportedException ();
97 public override FieldInfo[] GetFields (BindingFlags bindingAttr)
99 throw new NotSupportedException ();
102 public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
104 throw new NotSupportedException ();
107 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
108 CallingConventions callConvention, Type[] types,
109 ParameterModifier[] modifiers)
111 throw new NotSupportedException ();
114 public override MethodInfo[] GetMethods (BindingFlags bindingAttr)
116 throw new NotSupportedException ();
119 public override Type GetNestedType (string name, BindingFlags bindingAttr)
121 throw new NotSupportedException ();
124 public override Type[] GetNestedTypes (BindingFlags bindingAttr)
126 throw new NotSupportedException ();
129 public override PropertyInfo[] GetProperties (BindingFlags bindingAttr)
131 throw new NotSupportedException ();
134 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
135 Type returnType, Type[] types, ParameterModifier[] modifiers)
137 throw new NotSupportedException ();
140 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
141 Binder binder,
142 CallingConventions callConvention,
143 Type[] types,
144 ParameterModifier[] modifiers)
146 throw new NotSupportedException ();
150 protected override TypeAttributes GetAttributeFlagsImpl ()
152 /*LAMEIMPL MS just return the elementType.Attributes*/
153 return elementType.Attributes;
156 protected override bool HasElementTypeImpl ()
158 return true;
161 protected override bool IsArrayImpl ()
163 return false;
166 protected override bool IsByRefImpl ()
168 return false;
171 protected override bool IsCOMObjectImpl ()
173 return false;
176 protected override bool IsPointerImpl ()
178 return false;
181 protected override bool IsPrimitiveImpl ()
183 return false;
187 public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
189 throw new NotSupportedException ();
192 public override object InvokeMember (string name, BindingFlags invokeAttr,
193 Binder binder, object target, object[] args,
194 ParameterModifier[] modifiers,
195 CultureInfo culture, string[] namedParameters)
197 throw new NotSupportedException ();
200 public override InterfaceMapping GetInterfaceMap (Type interfaceType)
202 throw new NotSupportedException ();
205 public override bool IsInstanceOfType (object o)
207 return false;
210 public override bool IsAssignableFrom (Type c)
212 return false;
215 public override bool ContainsGenericParameters {
216 get { return elementType.ContainsGenericParameters; }
219 //FIXME this should be handled by System.Type
220 public override Type MakeGenericType (params Type[] typeArguments)
222 throw new NotSupportedException ();
225 public override Type MakeArrayType ()
227 return new ArrayType (this, 0);
230 public override Type MakeArrayType (int rank)
232 if (rank < 1)
233 throw new IndexOutOfRangeException ();
234 return new ArrayType (this, rank);
237 public override Type MakeByRefType ()
239 return new ByRefType (this);
242 public override Type MakePointerType ()
244 return new PointerType (this);
247 public override string ToString ()
249 return FormatName (elementType.ToString ());
252 public override GenericParameterAttributes GenericParameterAttributes {
253 get { throw new NotSupportedException (); }
256 public override StructLayoutAttribute StructLayoutAttribute {
257 get { throw new NotSupportedException (); }
260 public override Assembly Assembly {
261 get { return elementType.Assembly; }
264 public override string AssemblyQualifiedName {
265 get {
266 string fullName = FormatName (elementType.FullName);
267 if (fullName == null)
268 return null;
269 return fullName + ", " + elementType.Assembly.FullName;
274 public override string FullName {
275 get {
276 return FormatName (elementType.FullName);
280 public override string Name {
281 get {
282 return FormatName (elementType.Name);
286 public override Guid GUID {
287 get { throw new NotSupportedException (); }
290 public override Module Module {
291 get { return elementType.Module; }
294 public override string Namespace {
295 get { return elementType.Namespace; }
298 public override RuntimeTypeHandle TypeHandle {
299 get { throw new NotSupportedException (); }
302 public override Type UnderlyingSystemType {
303 get {
304 create_unmanaged_type (this);
305 return this;
309 //MemberInfo
310 public override bool IsDefined (Type attributeType, bool inherit)
312 throw new NotSupportedException ();
315 public override object [] GetCustomAttributes (bool inherit)
317 throw new NotSupportedException ();
320 public override object [] GetCustomAttributes (Type attributeType, bool inherit)
322 throw new NotSupportedException ();
326 internal class ArrayType : DerivedType
328 int rank;
330 internal ArrayType (Type elementType, int rank) : base (elementType)
332 this.rank = rank;
335 internal int GetEffectiveRank ()
337 return rank;
340 protected override bool IsArrayImpl ()
342 return true;
345 public override int GetArrayRank ()
347 return (rank == 0) ? 1 : rank;
350 public override Type BaseType {
351 get { return typeof (System.Array); }
354 protected override TypeAttributes GetAttributeFlagsImpl ()
356 if (IsCompilerContext)
357 return (elementType.Attributes & TypeAttributes.VisibilityMask) | TypeAttributes.Sealed | TypeAttributes.Serializable;
358 return elementType.Attributes;
361 internal override String FormatName (string elementName)
363 if (elementName == null)
364 return null;
365 StringBuilder sb = new StringBuilder (elementName);
366 sb.Append ("[");
367 for (int i = 1; i < rank; ++i)
368 sb.Append (",");
369 if (rank == 1)
370 sb.Append ("*");
371 sb.Append ("]");
372 return sb.ToString ();
377 internal class ByRefType : DerivedType
379 internal ByRefType (Type elementType) : base (elementType)
383 protected override bool IsByRefImpl ()
385 return true;
388 public override Type BaseType {
389 get { return typeof (Array); }
392 internal override String FormatName (string elementName)
394 if (elementName == null)
395 return null;
396 return elementName + "&";
399 public override Type MakeArrayType ()
401 throw new ArgumentException ("Cannot create an array type of a byref type");
404 public override Type MakeArrayType (int rank)
406 throw new ArgumentException ("Cannot create an array type of a byref type");
409 public override Type MakeByRefType ()
411 throw new ArgumentException ("Cannot create a byref type of an already byref type");
414 public override Type MakePointerType ()
416 throw new ArgumentException ("Cannot create a pointer type of a byref type");
421 internal class PointerType : DerivedType
423 internal PointerType (Type elementType) : base (elementType)
427 protected override bool IsPointerImpl ()
429 return true;
432 public override Type BaseType {
433 get { return typeof(Array); }
436 internal override String FormatName (string elementName)
438 if (elementName == null)
439 return null;
440 return elementName + "*";