Changeset 1553 for trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/DictionaryDecomposer.cs
- Timestamp:
- 04/14/09 13:23:08 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/DictionaryDecomposer.cs
r1542 r1553 5 5 using System.Collections.Generic; 6 6 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 } 7 namespace HeuristicLab.Persistence.Default.Decomposers { 40 8 41 9 public class DictionaryDecomposer : IDecomposer { … … 50 18 } 51 19 20 public IEnumerable<Tag> CreateMetaInfo(object o) { 21 return new Tag[] { }; 22 } 23 52 24 public IEnumerable<Tag> Decompose(object o) { 53 25 IDictionary dict = (IDictionary)o; … … 58 30 } 59 31 60 public object CreateInstance(Type t ) {32 public object CreateInstance(Type t, IEnumerable<Tag> metaInfo) { 61 33 return Activator.CreateInstance(t, true); 62 34 } 63 35 64 public objectPopulate(object instance, IEnumerable<Tag> o, Type t) {36 public void Populate(object instance, IEnumerable<Tag> o, Type t) { 65 37 IDictionary dict = (IDictionary)instance; 66 38 IEnumerator<Tag> iter = o.GetEnumerator(); … … 69 41 iter.MoveNext(); 70 42 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 } 76 45 } 77 46 }
Note: See TracChangeset
for help on using the changeset viewer.