Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/14/09 13:23:08 (16 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/KeyValuePairDecomposer.cs

    r1542 r1553  
    2121    }
    2222
    23     public IEnumerable<Tag> Decompose(object o) {     
     23    public IEnumerable<Tag> CreateMetaInfo(object o) {
     24      return new Tag[] { };
     25    }
     26
     27    public IEnumerable<Tag> Decompose(object o) {
    2428      Type t = o.GetType();
    2529      yield return new Tag("key", t.GetProperty("Key").GetValue(o, null));
     
    2731    }
    2832
    29     public object CreateInstance(Type type) {
     33    public object CreateInstance(Type type, IEnumerable<Tag> metaInfo) {
    3034      return Activator.CreateInstance(type, true);
    3135    }
    3236
    33     public object Populate(object instance, IEnumerable<Tag> o, Type t) {
     37    public void Populate(object instance, IEnumerable<Tag> o, Type t) {
    3438      IEnumerator<Tag> iter = o.GetEnumerator();
     39      iter.MoveNext();     
     40      t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
     41        .Single(fi => fi.Name == "key").SetValue(instance, iter.Current.Value);
    3542      iter.MoveNext();
    36       FieldInfo keyFieldInfo =
    37         t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
    38         .Single(fi => fi.Name == "key");
    39       FieldInfo valueFieldInfo =
    40         t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
    41         .Single(fi => fi.Name == "value");
    42       iter.Current.SafeSet(value => keyFieldInfo.SetValue(instance, value));     
    43       iter.MoveNext();
    44       iter.Current.SafeSet(value => valueFieldInfo.SetValue(instance, value));
    45       return instance;
    46     }   
     43      t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
     44        .Single(fi => fi.Name == "value").SetValue(instance, iter.Current.Value);     
     45    }
    4746  }
    48 
    4947}
Note: See TracChangeset for help on using the changeset viewer.