removed unused variables
[mono.git] / mcs / class / System / System.CodeDom / CodeTypeReference.cs
1 //
2 // System.CodeDom CodeTypeReferenceExpression Class implementation
3 //
4 // Author:
5 //   Daniel Stodden (stodden@in.tum.de)
6 //   Marek Safar (marek.safar@seznam.cz)
7 //
8 // (C) 2001 Ximian, Inc.
9 //
10
11 //
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:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
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.
30 //
31
32 using System.Runtime.InteropServices;
33
34 namespace System.CodeDom
35 {
36         [Serializable]
37         [ClassInterface(ClassInterfaceType.AutoDispatch)]
38         [ComVisible(true)]
39         public class CodeTypeReference
40                 : CodeObject
41         {
42                 private string baseType;
43                 private CodeTypeReference arrayType;
44                 private int rank;
45
46 #if NET_2_0
47                 CodeTypeReferenceCollection typeArguments;
48                 CodeTypeReferenceOptions codeTypeReferenceOption;
49 #endif
50
51                 //
52                 // Constructors
53                 //
54                 public CodeTypeReference( string baseType )
55                 {
56                         if (baseType.Length == 0) {
57                                 this.baseType = typeof (void).FullName;
58                                 return;
59                         }
60
61                         int array_start = baseType.LastIndexOf ('[');
62                         if (array_start == -1) {
63                                 this.baseType = baseType;
64                                 return;
65                         }
66                         string[] args = baseType.Split (',');
67
68 #if NET_2_0\r
69                         int array_end = baseType.LastIndexOf (']');
70
71                         if ((array_end - array_start) != args.Length) {
72                                 arrayType = new CodeTypeReference (baseType.Substring (0, array_start));
73                                 array_start++;
74                                 TypeArguments.Add (new CodeTypeReference (baseType.Substring (array_start, array_end - array_start)));
75                         } else
76 #endif
77                                 arrayType = new CodeTypeReference (baseType.Substring (0, array_start), args.Length);
78                 }
79                 
80                 public CodeTypeReference( Type baseType )
81                 {
82                         if (baseType.IsArray) {
83                                 this.rank = baseType.GetArrayRank ();
84                                 this.arrayType = new CodeTypeReference (baseType.GetElementType ());
85                                 this.baseType = arrayType.BaseType;
86                                 return;
87                         }
88                         this.baseType = baseType.FullName;
89                 }
90
91                 public CodeTypeReference( CodeTypeReference arrayType, int rank )
92                 {
93                         this.baseType = null;
94                         this.rank = rank;
95                         this.arrayType = arrayType;
96                 }
97
98                 public CodeTypeReference( string baseType, int rank )
99                         : this (new CodeTypeReference (baseType), rank)
100                 {
101                 }
102                         
103 #if NET_2_0
104                 public CodeTypeReference( CodeTypeParameter typeParameter ) :
105                         this (typeParameter.Name)
106                 {
107                 }
108
109                 public CodeTypeReference( string typeName, CodeTypeReferenceOptions codeTypeReferenceOption ) :
110                         this (typeName)
111                 {
112                         this.codeTypeReferenceOption = codeTypeReferenceOption;
113                 }
114
115                 public CodeTypeReference( Type type, CodeTypeReferenceOptions codeTypeReferenceOption ) :
116                         this (type)
117                 {
118                         this.codeTypeReferenceOption = codeTypeReferenceOption;
119                 }
120
121                 public CodeTypeReference( string typeName, params CodeTypeReference[] typeArguments ) :
122                         this (typeName)
123                 {
124                         TypeArguments.AddRange (typeArguments);
125                 }
126 #endif
127
128                 //
129                 // Properties
130                 //
131
132                 public CodeTypeReference ArrayElementType
133                 {
134                         get {
135                                 return arrayType;
136                         }
137                         set {
138                                 arrayType = value;
139                         }
140                 }
141                 
142                 public int ArrayRank {
143                         get {
144                                 return rank;
145                         }
146                         set {
147                                 rank = value;
148                         }
149                 }
150
151                 public string BaseType {
152                         get {
153                                 if (baseType == null)
154                                         return String.Empty;
155
156                                 return baseType;
157                         }
158                         set {
159                                 baseType = value;
160                         }
161                 }
162
163 #if NET_2_0
164                 [ComVisible (false)]
165                 public CodeTypeReferenceOptions Options {
166                         get {
167                                 return codeTypeReferenceOption;
168                         }
169                         set {
170                                 codeTypeReferenceOption = value;
171                         }
172                 }
173
174                 [ComVisible (false)]
175                 public CodeTypeReferenceCollection TypeArguments {
176                         get {
177                                 if (typeArguments == null)
178                                         typeArguments = new CodeTypeReferenceCollection ();
179                                 return typeArguments;
180                         }
181                 }
182 #endif
183         }
184 }