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
;
47 CodeTypeReferenceCollection typeArguments
;
48 CodeTypeReferenceOptions codeTypeReferenceOption
;
54 public CodeTypeReference( string baseType
)
56 if (baseType
.Length
== 0) {
57 this.baseType
= typeof (void).FullName
;
61 int array_start
= baseType
.LastIndexOf ('[');
62 if (array_start
== -1) {
63 this.baseType
= baseType
;
66 string[] args
= baseType
.Split (',');
68 int array_end
= baseType
.LastIndexOf (']');
71 if ((array_end
- array_start
) != args
.Length
) {
72 arrayType
= new CodeTypeReference (baseType
.Substring (0, array_start
));
74 TypeArguments
.Add (new CodeTypeReference (baseType
.Substring (array_start
, array_end
- array_start
)));
77 arrayType
= new CodeTypeReference (baseType
.Substring (0, array_start
), args
.Length
);
80 public CodeTypeReference( Type baseType
)
82 if (baseType
.IsArray
) {
83 this.rank
= baseType
.GetArrayRank ();
84 this.arrayType
= new CodeTypeReference (baseType
.GetElementType ());
85 this.baseType
= arrayType
.BaseType
;
88 this.baseType
= baseType
.FullName
;
91 public CodeTypeReference( CodeTypeReference arrayType
, int rank
)
95 this.arrayType
= arrayType
;
98 public CodeTypeReference( string baseType
, int rank
)
99 : this (new CodeTypeReference (baseType
), rank
)
104 public CodeTypeReference( CodeTypeParameter typeParameter
) :
105 this (typeParameter
.Name
)
109 public CodeTypeReference( string typeName
, CodeTypeReferenceOptions codeTypeReferenceOption
) :
112 this.codeTypeReferenceOption
= codeTypeReferenceOption
;
115 public CodeTypeReference( Type type
, CodeTypeReferenceOptions codeTypeReferenceOption
) :
118 this.codeTypeReferenceOption
= codeTypeReferenceOption
;
121 public CodeTypeReference( string typeName
, params CodeTypeReference
[] typeArguments
) :
124 TypeArguments
.AddRange (typeArguments
);
132 public CodeTypeReference ArrayElementType
142 public int ArrayRank
{
151 public string BaseType
{
153 if (baseType
== null)
165 public CodeTypeReferenceOptions Options
{
167 return codeTypeReferenceOption
;
170 codeTypeReferenceOption
= value;
175 public CodeTypeReferenceCollection TypeArguments
{
177 if (typeArguments
== null)
178 typeArguments
= new CodeTypeReferenceCollection ();
179 return typeArguments
;