Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/23/09 14:22:29 (15 years ago)
Author:
epitzer
Message:

Added PersistenceException used consistently for all error conditions in the persistence framework (#548)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/ArrayDecomposer.cs

    r1623 r1625  
    5454    }
    5555
    56     public object CreateInstance(Type t, IEnumerable<Tag> metaInfo) {
    57       IEnumerator<Tag> e = metaInfo.GetEnumerator();
    58       e.MoveNext();
    59       int rank = (int)e.Current.Value;
    60       int[] lengths = new int[rank];
    61       for (int i = 0; i < rank; i++) {
     56    public object CreateInstance(Type t, IEnumerable<Tag> metaInfo) {     
     57      try {
     58        IEnumerator<Tag> e = metaInfo.GetEnumerator();
    6259        e.MoveNext();
    63         lengths[i] = (int)e.Current.Value;
    64       }
    65       int[] lowerBounds = new int[rank];
    66       for (int i = 0; i < rank; i++) {
    67         e.MoveNext();
    68         lowerBounds[i] = (int)e.Current.Value;
    69       }
    70       return Array.CreateInstance(t.GetElementType(), lengths, lowerBounds);
     60        int rank = (int)e.Current.Value;
     61        int[] lengths = new int[rank];
     62        for (int i = 0; i < rank; i++) {
     63          e.MoveNext();
     64          lengths[i] = (int)e.Current.Value;
     65        }
     66        int[] lowerBounds = new int[rank];
     67        for (int i = 0; i < rank; i++) {
     68          e.MoveNext();
     69          lowerBounds[i] = (int)e.Current.Value;
     70        }
     71        return Array.CreateInstance(t.GetElementType(), lengths, lowerBounds);
     72      } catch (InvalidOperationException x) {
     73        throw new PersistenceException("Insufficient meta information to construct array instance.", x);
     74      } catch (InvalidCastException x) {
     75        throw new PersistenceException("Invalid format of array metainfo.", x);
     76      }     
    7177    }
    7278
     
    8389      int[] positions = (int[])lowerBounds.Clone();
    8490      IEnumerator<Tag> e = elements.GetEnumerator();
    85       while (e.MoveNext()) {
    86         int[] currentPositions = positions;
    87         a.SetValue(e.Current.Value, currentPositions);
    88         positions[0] += 1;
    89         for (int i = 0; i < a.Rank - 1; i++) {
    90           if (positions[i] >= lengths[i] + lowerBounds[i]) {
    91             positions[i] = lowerBounds[i];
    92             positions[i + 1] += 1;
    93           } else {
    94             break;
     91      try {
     92        while (e.MoveNext()) {
     93          int[] currentPositions = positions;
     94          a.SetValue(e.Current.Value, currentPositions);
     95          positions[0] += 1;
     96          for (int i = 0; i < a.Rank - 1; i++) {
     97            if (positions[i] >= lengths[i] + lowerBounds[i]) {
     98              positions[i] = lowerBounds[i];
     99              positions[i + 1] += 1;
     100            } else {
     101              break;
     102            }
    95103          }
    96104        }
     105      } catch (InvalidOperationException x) {
     106        throw new PersistenceException("Insufficient data to fill array instance", x);
     107      } catch (InvalidCastException x) {
     108        throw new PersistenceException("Invalid element data. Cannot fill array", x);
     109      } catch (IndexOutOfRangeException x) {
     110        throw new PersistenceException("Too many elements during array deserialization", x);
    97111      }
    98112    }
Note: See TracChangeset for help on using the changeset viewer.