Free cookie consent management tool by TermsFeed Policy Generator

source: branches/New Persistence Exploration/Persistence/Persistence/Default/Decomposers/KeyValuePairDecomposer.cs @ 1361

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

Split all classes into their own file (#506)

File size: 856 bytes
Line 
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using HeuristicLab.Persistence.Interfaces;
5
6namespace HeuristicLab.Persistence.Default.Decomposers {
7 
8  public class KeyValuePairDecomposer : IDecomposer {   
9
10    public bool CanDecompose(Type type) {
11      return type.IsGenericType &&
12             type.GetGenericTypeDefinition() ==
13             typeof (KeyValuePair<int, int>).GetGenericTypeDefinition();
14    }
15
16    public IEnumerable DeCompose(object o) {     
17      Type t = o.GetType();
18      yield return t.GetProperty("Key").GetValue(o, null);
19      yield return t.GetProperty("Value").GetValue(o, null);
20    }
21
22    public object Compose(IEnumerable o, Type t) {     
23      return Activator.CreateInstance(t,
24        new List<object>((IEnumerable<object>)o).ToArray());
25    }   
26  }
27
28}
Note: See TracBrowser for help on using the repository browser.