- Timestamp:
- 04/16/13 13:13:41 (11 years ago)
- Location:
- branches/OaaS
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS
- Property svn:ignore
-
old new 21 21 protoc.exe 22 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll 23 24 packages
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/OaaS/HeuristicLab.Persistence
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Persistence (added) merged: 8246,8588,8600,8641,8647,8698-8699,8924,9005,9014-9015,9018
- Property svn:mergeinfo changed
-
branches/OaaS/HeuristicLab.Persistence/3.3/Auxiliary/TypeName.cs
r7259 r9363 51 51 52 52 /// <summary> 53 /// Gets or sets the number of generic args for 54 /// each class in a series of nested classes. 55 /// </summary> 56 [Storable] 57 public List<int> GenericArgCounts { get; private set; } 58 59 /// <summary> 53 60 /// Gets or sets the generic args. 54 61 /// </summary> … … 103 110 /// <param name="nameSpace">The namespace.</param> 104 111 /// <param name="className">Name of the class.</param> 105 internal TypeName(string nameSpace, string className ) {112 internal TypeName(string nameSpace, string className, List<int> genericArgCounts=null) { 106 113 Namespace = nameSpace; 107 114 ClassName = className; … … 109 116 MemoryMagic = ""; 110 117 AssemblyAttribues = new Dictionary<string, string>(); 111 } 112 118 if (genericArgCounts != null) 119 GenericArgCounts = genericArgCounts.ToList(); 120 } 121 122 internal TypeName(TypeName typeName, string className = null, string nameSpace = null) { 123 Namespace = nameSpace ?? typeName.Namespace; 124 ClassName = className ?? typeName.ClassName; 125 GenericArgs = new List<TypeName>(typeName.GenericArgs); 126 AssemblyAttribues = new Dictionary<string, string>(typeName.AssemblyAttribues); 127 MemoryMagic = typeName.MemoryMagic; 128 AssemblyName = typeName.AssemblyName; 129 IsReference = typeName.IsReference; 130 if (typeName.GenericArgCounts != null) 131 GenericArgCounts = typeName.GenericArgCounts.ToList(); 132 } 113 133 114 134 /// <summary> … … 135 155 /// </returns> 136 156 public string ToString(bool full, bool includeAssembly) { 137 StringBuilder sb = new StringBuilder();157 var sb = new StringBuilder(); 138 158 if (!string.IsNullOrEmpty(Namespace)) 139 159 sb.Append(Namespace).Append('.'); 140 sb.Append(ClassName); 160 if (GenericArgCounts != null) { 161 sb.Append(string.Join("+", 162 ClassName 163 .Split('+') 164 .Zip(GenericArgCounts, (n, c) => 165 c > 0 ? String.Format("{0}`{1}", n, c) : n))); 166 } else { 167 sb.Append(ClassName); 168 if (IsGeneric) 169 sb.Append('`').Append(GenericArgs.Count); 170 } 141 171 if (IsGeneric) { 142 sb.Append('`').Append(GenericArgs.Count).Append('['); 143 bool first = true; 144 foreach (TypeName t in GenericArgs) { 145 if (first) 146 first = false; 147 else 148 sb.Append(','); 149 sb.Append('[').Append(t.ToString(full)).Append(']'); 150 } 172 sb.Append('['); 173 sb.Append(String.Join(",", GenericArgs.Select(a => 174 string.Format("[{0}]", a.ToString(full))))); 151 175 sb.Append(']'); 152 176 } … … 161 185 } 162 186 163 public string GetTypeNameInCode(HashSet<string> omitNamespaces) { 164 StringBuilder sb = new StringBuilder(); 165 if (!string.IsNullOrEmpty(Namespace) && omitNamespaces == null || !omitNamespaces.Contains(Namespace)) 166 sb.Append(Namespace).Append('.'); 167 sb.Append(ClassName); 168 if (IsGeneric) { 169 sb.Append("<"); 170 sb.Append( 171 string.Join(", ", 172 GenericArgs 173 .Select(a => a.GetTypeNameInCode(omitNamespaces)) 174 .ToArray())); 175 sb.Append(">"); 187 private IEnumerable<string> GetNestedClassesInCode(HashSet<string> omitNamespaces, bool includeAllNamespaces) { 188 var i = 0; 189 foreach (var pair in ClassName.Split('+').Zip(GenericArgCounts, (n, c) => new {n, c})) { 190 if (pair.c == 0) { 191 yield return pair.n; 192 } 193 else { 194 yield return string.Format("{0}<{1}>", 195 pair.n, 196 string.Join(",", 197 GenericArgs 198 .GetRange(i, pair.c) 199 .Select(a => a.GetTypeNameInCode(omitNamespaces, includeAllNamespaces)))); 200 i += pair.c; 201 } 202 } 203 } 204 205 private string GetTypeNameInCode(HashSet<string> omitNamespaces, bool includeNamespaces) { 206 var sb = new StringBuilder(); 207 if (!string.IsNullOrEmpty(Namespace) && 208 (omitNamespaces == null && includeNamespaces) || 209 omitNamespaces != null && !omitNamespaces.Contains(Namespace)) 210 sb.Append(Namespace).Append('.'); 211 if (GenericArgCounts != null) { 212 sb.Append(string.Join(".", GetNestedClassesInCode(omitNamespaces, includeNamespaces))); 213 } else { 214 sb.Append(ClassName); 215 if (IsGeneric) { 216 sb.Append("<"); 217 sb.Append( 218 string.Join(", ", 219 GenericArgs 220 .Select(a => a.GetTypeNameInCode(omitNamespaces, includeNamespaces)) 221 .ToArray())); 222 sb.Append(">"); 223 } 176 224 } 177 225 sb.Append(MemoryMagic); … … 179 227 } 180 228 181 public string GetTypeNameInCode(bool includeAllNamespaces) { 182 StringBuilder sb = new StringBuilder(); 183 if (includeAllNamespaces) 184 sb.Append(Namespace).Append('.'); 185 sb.Append(ClassName); 186 if (IsGeneric) { 187 sb.Append("<"); 188 sb.Append( 189 string.Join(", ", 190 GenericArgs 191 .Select(a => a.GetTypeNameInCode(includeAllNamespaces)) 192 .ToArray())); 193 sb.Append(">"); 194 } 195 sb.Append(MemoryMagic); 196 return sb.ToString(); 229 public string GetTypeNameInCode(HashSet<string> omitNamespaces) { 230 return GetTypeNameInCode(omitNamespaces, false); 231 } 232 233 public string GetTypeNameInCode(bool includeNamespaces) { 234 return GetTypeNameInCode(null, includeNamespaces); 197 235 } 198 236 … … 235 273 } 236 274 return false; 237 } catch (KeyNotFoundException) { 275 } 276 catch (KeyNotFoundException) { 238 277 throw new Exception("Could not extract version information from type string"); 239 278 } … … 272 311 } 273 312 return true; 274 } catch (KeyNotFoundException) { 313 } 314 catch (KeyNotFoundException) { 275 315 throw new Exception("Could not extract version infomration from type string"); 276 316 }
Note: See TracChangeset
for help on using the changeset viewer.