Changeset 3004 for trunk/sources/HeuristicLab.Persistence/3.3/Auxiliary
- Timestamp:
- 03/11/10 12:54:14 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence/3.3/Auxiliary
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Auxiliary/TypeLoader.cs
r1823 r3004 10 10 namespace HeuristicLab.Persistence.Auxiliary { 11 11 12 publicclass TypeLoader {12 internal class TypeLoader { 13 13 14 14 public static Type Load(string typeNameString) { -
trunk/sources/HeuristicLab.Persistence/3.3/Auxiliary/TypeName.cs
r2859 r3004 4 4 using System.Reflection.Emit; 5 5 using System.Collections.Generic; 6 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 6 7 7 8 namespace HeuristicLab.Persistence.Auxiliary { 8 9 10 /// <summary> 11 /// Contains a more modular representation of type names that can 12 /// be used to compare versions and ignore extended assembly 13 /// attributes. 14 /// </summary> 15 [StorableClass(StorableClassType.MarkedOnly)] 9 16 public class TypeName { 17 18 [Storable] 10 19 public string Namespace { get; private set; } 20 21 [Storable] 11 22 public string ClassName { get; private set; } 23 24 [Storable] 12 25 public List<TypeName> GenericArgs { get; internal set; } 13 26 public bool IsGeneric { get { return GenericArgs.Count > 0; } } 27 28 [Storable] 14 29 public string MemoryMagic { get; internal set; } 30 31 [Storable] 15 32 public string AssemblyName { get; internal set; } 33 34 [Storable] 16 35 public Dictionary<string, string> AssemblyAttribues { get; internal set; } 36 37 [Storable] 17 38 public bool IsReference { get; internal set; } 18 39 … … 25 46 } 26 47 48 /// <param name="full">include assembly properties and generic parameters</param> 27 49 public string ToString(bool full) { 28 50 return ToString(full, true); 29 51 } 30 52 31 public string ToString(bool full, bool includeAssembly) { 53 54 /// <param name="full">include assembly properties and generic parameters</param> 55 public string ToString(bool full, bool includeAssembly) { 32 56 StringBuilder sb = new StringBuilder(); 33 57 if (!string.IsNullOrEmpty(Namespace)) … … 60 84 } 61 85 62 public bool IsNewerThan(TypeName t) { 86 87 /// <summary> 88 /// Lexicographically compare version information and make sure type and assembly 89 /// names are identical. This function recursively checks generic type arguments. 90 /// </summary> 91 public bool IsNewerThan(TypeName typeName) { 63 92 try { 64 if (this.ClassName != t .ClassName ||65 this.Namespace != t .Namespace ||66 this.AssemblyName != t .AssemblyName)93 if (this.ClassName != typeName.ClassName || 94 this.Namespace != typeName.Namespace || 95 this.AssemblyName != typeName.AssemblyName) 67 96 throw new Exception("Cannot compare versions of different types"); 68 97 if (CompareVersions( 69 98 this.AssemblyAttribues["Version"], 70 t .AssemblyAttribues["Version"]) > 0)99 typeName.AssemblyAttribues["Version"]) > 0) 71 100 return true; 72 101 IEnumerator<TypeName> thisIt = this.GenericArgs.GetEnumerator(); 73 IEnumerator<TypeName> tIt = t .GenericArgs.GetEnumerator();102 IEnumerator<TypeName> tIt = typeName.GenericArgs.GetEnumerator(); 74 103 while (thisIt.MoveNext()) { 75 104 tIt.MoveNext(); … … 83 112 } 84 113 85 public bool IsCompatible(TypeName t) { 114 115 /// <summary> 116 /// Make sure major and minor version number are identical. This function 117 /// recursively checks generic type arguments. 118 /// </summary> 119 public bool IsCompatible(TypeName typeName) { 86 120 try { 87 if (this.ClassName != t .ClassName ||88 this.Namespace != t .Namespace ||89 this.AssemblyName != t .AssemblyName)121 if (this.ClassName != typeName.ClassName || 122 this.Namespace != typeName.Namespace || 123 this.AssemblyName != typeName.AssemblyName) 90 124 throw new Exception("Cannot compare versions of different types"); 91 125 Version thisVersion = new Version(this.AssemblyAttribues["Version"]); 92 Version tVersion = new Version(t .AssemblyAttribues["Version"]);126 Version tVersion = new Version(typeName.AssemblyAttribues["Version"]); 93 127 if (thisVersion.Major != tVersion.Major || 94 128 thisVersion.Minor != tVersion.Minor) 95 129 return false; 96 130 IEnumerator<TypeName> thisIt = this.GenericArgs.GetEnumerator(); 97 IEnumerator<TypeName> tIt = t .GenericArgs.GetEnumerator();131 IEnumerator<TypeName> tIt = typeName.GenericArgs.GetEnumerator(); 98 132 while (thisIt.MoveNext()) { 99 133 tIt.MoveNext(); -
trunk/sources/HeuristicLab.Persistence/3.3/Auxiliary/TypeNameParser.cs
r2859 r3004 11 11 } 12 12 13 14 /// <summary> 15 /// Parse a .NET type name using the following grammar: 16 /// 17 /// <para><code> 18 /// TypeSpec := SimpleTypeSpec '&'? 19 /// </code></para> 20 /// 21 /// <para><code> 22 /// SimpleTypeSpec := (IDENTIFIER '.')* 23 /// (IDENTIFIER '+')* 24 /// IDENTIFIER 25 /// ( '`\d+[' Generics ']' )? 26 /// (\*|\[(\d+\.\.\d+|\d+\.\.\.|(|\*)(,(|\*))*)\])* 27 /// (',\s*' IDENTIFIER (',\s*' AssemblyProperty)* )? 28 /// </code></para> 29 /// 30 /// <para><code> 31 /// Generics := '[' SimpleTypeSpec ']' (',[' SimpleTypeSpec ']') 32 /// </code></para> 33 /// 34 /// <para><code> 35 /// AssemblyProperty := 'Version=' Version 36 /// | 'PublicKey(Token)?=[a-fA-F0-9]+' 37 /// | 'Culture=[a-zA-F0-9]+' 38 /// </code></para> 39 /// 40 /// <para><code> 41 /// Version := \d+\.\d+\.\d+\.\d+ 42 /// </code></para> 43 /// 44 /// <para><code> 45 /// IDENTIFIER = [_a-zA-Z][_a-ZA-Z0-9]* 46 /// </code></para> 47 /// </summary> 13 48 public class TypeNameParser { 14 49 … … 35 70 36 71 37 class Token {72 private class Token { 38 73 private static Dictionary<string, string> tokens = 39 74 new Dictionary<string, string> { … … 68 103 } 69 104 } 70 public static IEnumerable<Token> Tokenize(string s) { 105 public static IEnumerable<Token> Tokenize(string s) { 71 106 int pos = 0; 72 107 foreach (Match m in TokenRegex.Matches(s)) {
Note: See TracChangeset
for help on using the changeset viewer.