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.
31 using System.Reflection;
32 using System.Reflection.Emit;
33 using System.Collections;
34 using System.Runtime.CompilerServices;
35 using System.Globalization;
36 using System.Runtime.InteropServices;
37 using System.Runtime.Serialization;
41 namespace System.Reflection.Emit
43 [StructLayout (LayoutKind.Sequential)]
44 abstract partial class SymbolType
46 internal Type m_baseType;
48 internal SymbolType (Type elementType)
50 this.m_baseType = elementType;
53 internal abstract String FormatName (string elementName);
55 protected override bool IsArrayImpl ()
60 protected override bool IsByRefImpl ()
65 protected override bool IsPointerImpl ()
70 public override Type MakeArrayType ()
72 return new ArrayType (this, 0);
75 public override Type MakeArrayType (int rank)
78 throw new IndexOutOfRangeException ();
79 return new ArrayType (this, rank);
82 public override Type MakeByRefType ()
84 return new ByRefType (this);
87 public override Type MakePointerType ()
89 return new PointerType (this);
92 public override string ToString ()
94 return FormatName (m_baseType.ToString ());
97 public override string AssemblyQualifiedName {
99 string fullName = FormatName (m_baseType.FullName);
100 if (fullName == null)
102 return fullName + ", " + m_baseType.Assembly.FullName;
107 public override string FullName {
109 return FormatName (m_baseType.FullName);
113 public override string Name {
115 return FormatName (m_baseType.Name);
119 public override Type UnderlyingSystemType {
125 internal override bool IsUserType {
127 return m_baseType.IsUserType;
131 // Called from the runtime to return the corresponding finished Type object
132 internal override Type RuntimeResolve () {
133 return InternalResolve ();
137 [StructLayout (LayoutKind.Sequential)]
138 internal class ArrayType : SymbolType
142 internal ArrayType (Type elementType, int rank) : base (elementType)
147 internal int GetEffectiveRank ()
152 internal override Type InternalResolve ()
154 Type et = m_baseType.InternalResolve ();
156 return et.MakeArrayType ();
157 return et.MakeArrayType (rank);
160 internal override Type RuntimeResolve ()
162 Type et = m_baseType.RuntimeResolve ();
164 return et.MakeArrayType ();
165 return et.MakeArrayType (rank);
168 protected override bool IsArrayImpl ()
173 public override int GetArrayRank ()
175 return (rank == 0) ? 1 : rank;
178 internal override String FormatName (string elementName)
180 if (elementName == null)
182 StringBuilder sb = new StringBuilder (elementName);
184 for (int i = 1; i < rank; ++i)
189 return sb.ToString ();
193 [StructLayout (LayoutKind.Sequential)]
194 internal class ByRefType : SymbolType
196 internal ByRefType (Type elementType) : base (elementType)
200 internal override Type InternalResolve ()
202 return m_baseType.InternalResolve ().MakeByRefType ();
205 protected override bool IsByRefImpl ()
210 internal override String FormatName (string elementName)
212 if (elementName == null)
214 return elementName + "&";
217 public override Type MakeArrayType ()
219 throw new ArgumentException ("Cannot create an array type of a byref type");
222 public override Type MakeArrayType (int rank)
224 throw new ArgumentException ("Cannot create an array type of a byref type");
227 public override Type MakeByRefType ()
229 throw new ArgumentException ("Cannot create a byref type of an already byref type");
232 public override Type MakePointerType ()
234 throw new ArgumentException ("Cannot create a pointer type of a byref type");
238 [StructLayout (LayoutKind.Sequential)]
239 internal class PointerType : SymbolType
241 internal PointerType (Type elementType) : base (elementType)
245 internal override Type InternalResolve ()
247 return m_baseType.InternalResolve ().MakePointerType ();
250 protected override bool IsPointerImpl ()
255 internal override String FormatName (string elementName)
257 if (elementName == null)
259 return elementName + "*";