public CodeTypeReference (Type baseType) { #if NET_2_0 if (baseType == null) { throw new ArgumentNullException ("baseType"); } if (baseType.IsGenericParameter) { this.baseType = baseType.Name; this.referenceOptions = CodeTypeReferenceOptions.GenericTypeParameter; } else if (baseType.IsGenericTypeDefinition) this.baseType = baseType.FullName; else if (baseType.IsGenericType) { this.baseType = baseType.GetGenericTypeDefinition ().FullName; foreach (Type arg in baseType.GetGenericArguments ()) { if (arg.IsGenericParameter) TypeArguments.Add (new CodeTypeReference (new CodeTypeParameter (arg.Name))); else TypeArguments.Add (new CodeTypeReference (arg)); } } else #endif if (baseType.IsArray) { this.arrayRank = baseType.GetArrayRank (); this.arrayElementType = new CodeTypeReference (baseType.GetElementType ()); this.baseType = arrayElementType.BaseType; } else { Parse (baseType.FullName); } this.isInterface = baseType.IsInterface; }
public CodeTypeReference( Type type, CodeTypeReferenceOptions referenceOptions ) : this (type) { this.referenceOptions = referenceOptions; }
public CodeTypeReference( CodeTypeParameter typeParameter ) : this (typeParameter.Name) { this.referenceOptions = CodeTypeReferenceOptions.GenericTypeParameter; }
public CodeTypeReference( string typeName, CodeTypeReferenceOptions referenceOptions ) : this (typeName) { this.referenceOptions = referenceOptions; }
public CodeTypeReference(Type type, CodeTypeReferenceOptions codeTypeReferenceOption) { }
public CodeTypeReference(string typeName, CodeTypeReferenceOptions codeTypeReferenceOption) { }
public CodeTypeReference(Type type, CodeTypeReferenceOptions codeTypeReferenceOption) : this(type) { this.referenceOptions = codeTypeReferenceOption; }
private void Initialize(string typeName, CodeTypeReferenceOptions options) { this.Options = options; if ((typeName == null) || (typeName.Length == 0)) { typeName = typeof(void).FullName; this.baseType = typeName; this.arrayRank = 0; this.arrayElementType = null; } else { typeName = this.RipOffAssemblyInformationFromTypeName(typeName); int num = typeName.Length - 1; int num2 = num; this.needsFixup = true; Queue queue = new Queue(); while (num2 >= 0) { int num3 = 1; if (typeName[num2--] != ']') { break; } while ((num2 >= 0) && (typeName[num2] == ',')) { num3++; num2--; } if ((num2 < 0) || (typeName[num2] != '[')) { break; } queue.Enqueue(num3); num2--; num = num2; } num2 = num; ArrayList list = new ArrayList(); Stack stack = new Stack(); if ((num2 > 0) && (typeName[num2--] == ']')) { this.needsFixup = false; int num4 = 1; int num5 = num; while (num2 >= 0) { if (typeName[num2] == '[') { if (--num4 == 0) { break; } } else if (typeName[num2] == ']') { num4++; } else if ((typeName[num2] == ',') && (num4 == 1)) { if ((num2 + 1) < num5) { stack.Push(typeName.Substring(num2 + 1, (num5 - num2) - 1)); } num5 = num2; } num2--; } if ((num2 > 0) && (((num - num2) - 1) > 0)) { if ((num2 + 1) < num5) { stack.Push(typeName.Substring(num2 + 1, (num5 - num2) - 1)); } while (stack.Count > 0) { string str = this.RipOffAssemblyInformationFromTypeName((string) stack.Pop()); list.Add(new CodeTypeReference(str)); } num = num2 - 1; } } if (num < 0) { this.baseType = typeName; } else { if (queue.Count > 0) { CodeTypeReference arrayType = new CodeTypeReference(typeName.Substring(0, num + 1), this.Options); for (int i = 0; i < list.Count; i++) { arrayType.TypeArguments.Add((CodeTypeReference) list[i]); } while (queue.Count > 1) { arrayType = new CodeTypeReference(arrayType, (int) queue.Dequeue()); } this.baseType = null; this.arrayRank = (int) queue.Dequeue(); this.arrayElementType = arrayType; } else if (list.Count > 0) { for (int j = 0; j < list.Count; j++) { this.TypeArguments.Add((CodeTypeReference) list[j]); } this.baseType = typeName.Substring(0, num + 1); } else { this.baseType = typeName; } if ((this.baseType != null) && (this.baseType.IndexOf('`') != -1)) { this.needsFixup = false; } } } }
public CodeTypeReference(string typeName, CodeTypeReferenceOptions codeTypeReferenceOption) { this.Initialize(typeName, codeTypeReferenceOption); }
public CodeTypeReference(CodeTypeParameter typeParameter): this( (typeParameter == null) ? (string)null : typeParameter.Name) { referenceOptions = CodeTypeReferenceOptions.GenericTypeParameter; }
private void Initialize(string typeName, CodeTypeReferenceOptions options) { Options = options; if (typeName == null || typeName.Length == 0) { typeName = typeof(void).FullName; this.baseType = typeName; this.arrayRank = 0; this.arrayElementType = null; return; } typeName = RipOffAssemblyInformationFromTypeName(typeName); int end = typeName.Length -1; int current = end; needsFixup = true; // default to true, and if we find arity or generic type args, we'll clear the flag. // Scan the entire string for valid array tails and store ranks for array tails // we found in a queue. Queue q = new Queue(); while(current >= 0) { int rank = 1; if( typeName[current--] == ']') { while(current >=0 && typeName[current] == ',') { rank++; current--; } if( current>=0 && typeName[current] == '[') { // found a valid array tail q.Enqueue(rank); current--; end = current; continue; } } break; } // Try find generic type arguments current = end; ArrayList typeArgumentList = new ArrayList(); Stack subTypeNames = new Stack(); if( current > 0 && typeName[current--] == ']') { needsFixup = false; int unmatchedRightBrackets = 1; int subTypeNameEndIndex = end; // Try find the matching '[', if we can't find it, we will not try to parse the string while(current >= 0) { if( typeName[current] == '[' ) { // break if we found matched brackets if( --unmatchedRightBrackets == 0) break; } else if( typeName[current] == ']' ) { ++unmatchedRightBrackets; } else if( typeName[current] == ',' && unmatchedRightBrackets == 1) { // // Type name can contain nested generic types. Following is an example: // System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089], // [System.Collections.Generic.List`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], // mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] // // Spliltting by ',' won't work. We need to do first-level split by ','. // if( current + 1 < subTypeNameEndIndex) { subTypeNames.Push(typeName.Substring(current+1 , subTypeNameEndIndex - current - 1)); } subTypeNameEndIndex = current; } --current; } if( current > 0 && (end - current - 1) > 0) { // push the last generic type argument name if there is any if( current + 1 < subTypeNameEndIndex) { subTypeNames.Push(typeName.Substring(current+1 , subTypeNameEndIndex - current - 1)); } // we found matched brackets and the brackets contains some characters. while( subTypeNames.Count > 0) { String name = RipOffAssemblyInformationFromTypeName((string)subTypeNames.Pop()); typeArgumentList.Add(new CodeTypeReference(name)); } end = current - 1; } } if( end < 0) { // this can happen if we have some string like "[...]" this.baseType = typeName; return; } if (q.Count > 0 ) { CodeTypeReference type = new CodeTypeReference(typeName.Substring(0, end + 1), Options); for(int i = 0; i < typeArgumentList.Count; i++) { type.TypeArguments.Add((CodeTypeReference)typeArgumentList[i]); } while( q.Count > 1) { type = new CodeTypeReference( type, (int)q.Dequeue()); } // we don't need to create a new CodeTypeReference for the last one. Debug.Assert(q.Count == 1 , "We should have one and only one in the rank queue."); this.baseType = null; this.arrayRank = (int)q.Dequeue(); this.arrayElementType = type; } else if( typeArgumentList.Count > 0 ) { for( int i = 0; i < typeArgumentList.Count; i++) { TypeArguments.Add((CodeTypeReference)typeArgumentList[i]); } this.baseType = typeName.Substring(0, end + 1); } else{ this.baseType = typeName; } // Now see if we have some arity. baseType could be null if this is an array type. if (baseType != null && baseType.IndexOf('`') != -1) needsFixup = false; }
protected virtual CodeTypeReferenceOptions Rewrite(CodeTypeReferenceOptions source, ref bool didRewrite) { bool didChildRewrite = false; CodeTypeReferenceOptions result = new CodeTypeReferenceOptions(); if (didChildRewrite) { didRewrite = true; return result; } else { return source; } }
public CodeTypeReference (String typeName, CodeTypeReferenceOptions codeTypeReferenceOption): this(typeName) { referenceOptions = codeTypeReferenceOption; }