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;
57 public CodeTypeReference ()
62 public CodeTypeReference (string baseType)
64 if (baseType == null || baseType.Length == 0) {
65 this.baseType = typeof (void).FullName;
69 int array_start = baseType.LastIndexOf ('[');
70 if (array_start == -1) {
71 this.baseType = baseType;
75 int array_end = baseType.LastIndexOf (']');
76 if (array_end < array_start) {
77 this.baseType = baseType;
81 string[] args = baseType.Substring (array_start + 1, array_end - array_start - 1).Split (',');
84 if ((array_end - array_start) != args.Length) {
85 this.baseType = baseType.Substring(0, array_start);
86 foreach (string arg in args) {
87 if (arg.Length != 0) {
88 TypeArguments.Add (new CodeTypeReference (arg));
92 arrayType = new CodeTypeReference (baseType.Substring (0, array_start));
97 foreach (string arg in args) {
98 if (arg.Length != 0) {
104 arrayType = new CodeTypeReference (baseType.Substring (0, array_start));
107 this.baseType = baseType;
112 public CodeTypeReference( Type baseType )
115 if (baseType == null) {
116 throw new ArgumentNullException ("baseType");
119 if (baseType.IsArray) {
120 this.rank = baseType.GetArrayRank ();
121 this.arrayType = new CodeTypeReference (baseType.GetElementType ());
122 this.baseType = arrayType.BaseType;
124 this.baseType = baseType.FullName;
126 this.isInterface = baseType.IsInterface;
129 public CodeTypeReference( CodeTypeReference arrayType, int rank )
131 this.baseType = null;
133 this.arrayType = arrayType;
136 public CodeTypeReference( string baseType, int rank )
137 : this (new CodeTypeReference (baseType), rank)
142 public CodeTypeReference( CodeTypeParameter typeParameter ) :
143 this (typeParameter.Name)
145 this.codeTypeReferenceOption = CodeTypeReferenceOptions.GenericTypeParameter;
148 public CodeTypeReference( string typeName, CodeTypeReferenceOptions codeTypeReferenceOption ) :
151 this.codeTypeReferenceOption = codeTypeReferenceOption;
154 public CodeTypeReference( Type type, CodeTypeReferenceOptions codeTypeReferenceOption ) :
157 this.codeTypeReferenceOption = codeTypeReferenceOption;
160 public CodeTypeReference( string typeName, params CodeTypeReference[] typeArguments ) :
163 TypeArguments.AddRange (typeArguments);
171 public CodeTypeReference ArrayElementType
181 public int ArrayRank {
190 public string BaseType {
192 if (arrayType != null) {
193 return arrayType.BaseType;
196 if (baseType == null)
206 internal bool IsInterface {
207 get { return isInterface; }
212 public CodeTypeReferenceOptions Options {
214 return codeTypeReferenceOption;
217 codeTypeReferenceOption = value;
222 public CodeTypeReferenceCollection TypeArguments {
224 if (typeArguments == null)
225 typeArguments = new CodeTypeReferenceCollection ();
226 return typeArguments;