2 // System.CodeDom CodeTypeReferenceExpression Class implementation
5 // Daniel Stodden (stodden@in.tum.de)
6 // Marek Safar (marek.safar@seznam.cz)
8 // (C) 2001 Ximian, Inc.
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Runtime.InteropServices;
34 namespace System.CodeDom
37 [ClassInterface(ClassInterfaceType.AutoDispatch)]
39 public class CodeTypeReference
42 private string baseType;
43 private CodeTypeReference arrayType;
45 private bool isInterface;
48 CodeTypeReferenceCollection typeArguments;
49 CodeTypeReferenceOptions codeTypeReferenceOption;
55 public CodeTypeReference( string baseType )
57 if (baseType == null || baseType.Length == 0) {
58 this.baseType = typeof (void).FullName;
62 int array_start = baseType.LastIndexOf ('[');
63 if (array_start == -1) {
64 this.baseType = baseType;
67 string[] args = baseType.Split (',');
70 int array_end = baseType.LastIndexOf (']');
72 if ((array_end - array_start) != args.Length) {
73 arrayType = new CodeTypeReference (baseType.Substring (0, array_start));
75 TypeArguments.Add (new CodeTypeReference (baseType.Substring (array_start, array_end - array_start)));
78 arrayType = new CodeTypeReference (baseType.Substring (0, array_start), args.Length);
81 public CodeTypeReference( Type baseType )
84 if (baseType == null) {
85 throw new ArgumentNullException ("baseType");
88 if (baseType.IsArray) {
\r
89 this.rank = baseType.GetArrayRank ();
\r
90 this.arrayType = new CodeTypeReference (baseType.GetElementType ());
\r
91 this.baseType = arrayType.BaseType;
\r
93 this.baseType = baseType.FullName;
\r
95 this.isInterface = baseType.IsInterface;
98 public CodeTypeReference( CodeTypeReference arrayType, int rank )
100 this.baseType = null;
102 this.arrayType = arrayType;
105 public CodeTypeReference( string baseType, int rank )
106 : this (new CodeTypeReference (baseType), rank)
111 public CodeTypeReference( CodeTypeParameter typeParameter ) :
112 this (typeParameter.Name)
116 public CodeTypeReference( string typeName, CodeTypeReferenceOptions codeTypeReferenceOption ) :
119 this.codeTypeReferenceOption = codeTypeReferenceOption;
122 public CodeTypeReference( Type type, CodeTypeReferenceOptions codeTypeReferenceOption ) :
125 this.codeTypeReferenceOption = codeTypeReferenceOption;
128 public CodeTypeReference( string typeName, params CodeTypeReference[] typeArguments ) :
131 TypeArguments.AddRange (typeArguments);
139 public CodeTypeReference ArrayElementType
149 public int ArrayRank {
158 public string BaseType {
160 if (baseType == null)
170 internal bool IsInterface {
\r
171 get { return isInterface; }
\r
176 public CodeTypeReferenceOptions Options {
178 return codeTypeReferenceOption;
181 codeTypeReferenceOption = value;
186 public CodeTypeReferenceCollection TypeArguments {
188 if (typeArguments == null)
189 typeArguments = new CodeTypeReferenceCollection ();
190 return typeArguments;