Free cookie consent management tool by TermsFeed Policy Generator

source: branches/New Persistence Exploration/Persistence/Persistence/Default/Decomposers/DictionaryDecomposer.cs @ 1421

Last change on this file since 1421 was 1421, checked in by epitzer, 15 years ago

Remove unnecessary class attributes. (#506)

File size: 1.2 KB
Line 
1using System;
2using System.Collections;
3using HeuristicLab.Persistence.Core;
4using HeuristicLab.Persistence.Interfaces;
5using System.Collections.Generic;
6
7namespace HeuristicLab.Persistence.Default.Decomposers {
8 
9  public class DictionaryDecomposer : IDecomposer {
10
11    public bool CanDecompose(Type type) {
12      return type.GetInterface(typeof(IDictionary).FullName) != null;       
13    }
14
15    public IEnumerable<Tag> DeCompose(object o) {
16      IDictionary dict = (IDictionary)o;     
17      foreach ( DictionaryEntry entry in dict) {
18        yield return new Tag("key", entry.Key);
19        yield return new Tag("value", entry.Value);
20      }
21    }
22
23    public object CreateInstance(Type t) {
24      return Activator.CreateInstance(t, true);
25    }
26
27    public object Populate(object instance, IEnumerable<Tag> o, Type t) {
28      IDictionary dict = (IDictionary)instance;
29      IEnumerator<Tag> iter = o.GetEnumerator();
30      while (iter.MoveNext()) {
31        object key = iter.Current.Value;
32        iter.MoveNext();
33        object value = iter.Current.Value;
34        dict.Add(key, value);
35      }
36      return dict;
37    }
38  }
39
40}
Note: See TracBrowser for help on using the repository browser.