Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/11/09 16:09:29 (15 years ago)
Author:
epitzer
Message:

Store full version information with serialized data, only fall back to version invariant format if loading fails with full version. Also check, that loaded version is newer than requested version if possible. (#613)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Auxiliary/TypeStringBuilder.cs

    r1779 r1780  
    365365
    366366    public string ToString(bool full) {
     367      return ToString(full, true);
     368    }
     369
     370    public string ToString(bool full, bool includeAssembly) {
    367371      StringBuilder sb = new StringBuilder();
    368372      sb.Append(Namespace).Append('.').Append(ClassName);
     
    380384      }
    381385      sb.Append(MemoryMagic);
    382       if (AssemblyName != null)
     386      if (includeAssembly && AssemblyName != null) {
    383387        sb.Append(", ").Append(AssemblyName);
    384       if (full)
    385         foreach (var property in AssemblyAttribues)
    386           sb.Append(", ").Append(property.Key).Append('=').Append(property.Value);
     388        if (full)
     389          foreach (var property in AssemblyAttribues)
     390            sb.Append(", ").Append(property.Key).Append('=').Append(property.Value);
     391      }
    387392      return sb.ToString();
    388393    }
     
    393398
    394399    public bool IsOlderThan(TypeName t) {
    395       if (this.ClassName != t.ClassName ||
    396         this.Namespace != t.Namespace ||
    397         this.AssemblyName != t.AssemblyName)
    398         throw new Exception("Cannot compare versions of different types");
    399       if (CompareVersions(
    400         this.AssemblyAttribues["Version"],
    401         t.AssemblyAttribues["Version"]) < 0)
    402         return true;
    403       IEnumerator<TypeName> thisIt = this.GenericArgs.GetEnumerator();
    404       IEnumerator<TypeName> tIt = t.GenericArgs.GetEnumerator();
    405       while (thisIt.MoveNext()) {
    406         tIt.MoveNext();
    407         if (thisIt.Current.IsOlderThan(tIt.Current))
     400      try {
     401        if (this.ClassName != t.ClassName ||
     402          this.Namespace != t.Namespace ||
     403          this.AssemblyName != t.AssemblyName)
     404          throw new Exception("Cannot compare versions of different types");
     405        if (CompareVersions(
     406          this.AssemblyAttribues["Version"],
     407          t.AssemblyAttribues["Version"]) < 0)
    408408          return true;
    409       }
    410       return false;
     409        IEnumerator<TypeName> thisIt = this.GenericArgs.GetEnumerator();
     410        IEnumerator<TypeName> tIt = t.GenericArgs.GetEnumerator();
     411        while (thisIt.MoveNext()) {
     412          tIt.MoveNext();
     413          if (thisIt.Current.IsOlderThan(tIt.Current))
     414            return true;
     415        }
     416        return false;
     417      } catch (KeyNotFoundException) {
     418        throw new Exception("Could not extract version information from type string");
     419      }
    411420    }
    412421
Note: See TracChangeset for help on using the changeset viewer.