Free cookie consent management tool by TermsFeed Policy Generator

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

Replace final fixes for broken parent references with separation of instance creation with meta information. (#548)

File:
1 edited

Legend:

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

    r1542 r1553  
    55using System.Collections.Generic;
    66
    7 namespace HeuristicLab.Persistence.Default.Decomposers {
    8 
    9   class DictionaryAdder {
    10 
    11     bool keyIsSet, valueIsSet;
    12     object key;
    13     object value;
    14     readonly IDictionary dict;
    15 
    16     public DictionaryAdder(IDictionary dict) {
    17       this.dict = dict;
    18       keyIsSet = false;
    19       valueIsSet = false;
    20     }
    21 
    22     public void SetKey(object v) {
    23       key = v;
    24       keyIsSet = true;
    25       Check();
    26     }
    27 
    28     public void SetValue(object v) {
    29       value = v;
    30       valueIsSet = true;
    31       Check();
    32     }
    33 
    34     private void Check() {
    35       if ( keyIsSet && valueIsSet )
    36         dict.Add(key, value);
    37     }
    38 
    39   }
     7namespace HeuristicLab.Persistence.Default.Decomposers { 
    408 
    419  public class DictionaryDecomposer : IDecomposer {
     
    5018    }
    5119
     20    public IEnumerable<Tag> CreateMetaInfo(object o) {
     21      return new Tag[] { };
     22    }
     23
    5224    public IEnumerable<Tag> Decompose(object o) {
    5325      IDictionary dict = (IDictionary)o;     
     
    5830    }
    5931
    60     public object CreateInstance(Type t) {
     32    public object CreateInstance(Type t, IEnumerable<Tag> metaInfo) {
    6133      return Activator.CreateInstance(t, true);
    6234    }
    6335
    64     public object Populate(object instance, IEnumerable<Tag> o, Type t) {
     36    public void Populate(object instance, IEnumerable<Tag> o, Type t) {
    6537      IDictionary dict = (IDictionary)instance;
    6638      IEnumerator<Tag> iter = o.GetEnumerator();
     
    6941        iter.MoveNext();
    7042        Tag value = iter.Current;
    71         DictionaryAdder da = new DictionaryAdder(dict);
    72         key.SafeSet(da.SetKey);
    73         value.SafeSet(da.SetValue);       
    74       }
    75       return dict;
     43        dict.Add(key.Value, value.Value);
     44      }     
    7645    }
    7746  }
Note: See TracChangeset for help on using the changeset viewer.