Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/25/09 17:16:32 (15 years ago)
Author:
epitzer
Message:

Implement persistence of storables as decomposer. (#506)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/New Persistence Exploration/Persistence/Persistence/Default/Decomposers/DictionaryDecomposer.cs

    r1405 r1419  
    33using HeuristicLab.Persistence.Core;
    44using HeuristicLab.Persistence.Interfaces;
     5using System.Collections.Generic;
    56
    67namespace HeuristicLab.Persistence.Default.Decomposers {
     
    1314    }
    1415
    15     public IEnumerable DeCompose(object o) {
     16    public IEnumerable<Tag> DeCompose(object o) {
    1617      IDictionary dict = (IDictionary)o;     
    1718      foreach ( DictionaryEntry entry in dict) {
    18         yield return entry.Key;
    19         yield return entry.Value;
     19        yield return new Tag("key", entry.Key);
     20        yield return new Tag("value", entry.Value);
    2021      }
    2122    }
    2223
    23     public object Compose(IEnumerable o, Type t) {
    24       IDictionary dict = (IDictionary)Activator.CreateInstance(t, true);
    25       IEnumerator iter = o.GetEnumerator();
     24    public object CreateInstance(Type t) {
     25      return Activator.CreateInstance(t, true);
     26    }
     27
     28    public object Populate(object instance, IEnumerable<Tag> o, Type t) {
     29      IDictionary dict = (IDictionary)instance;
     30      IEnumerator<Tag> iter = o.GetEnumerator();
    2631      while (iter.MoveNext()) {
    27         object key = iter.Current;
     32        object key = iter.Current.Value;
    2833        iter.MoveNext();
    29         object value = iter.Current;
     34        object value = iter.Current.Value;
    3035        dict.Add(key, value);
    3136      }
Note: See TracChangeset for help on using the changeset viewer.