Line | |
---|
1 | using System;
|
---|
2 | using System.Collections;
|
---|
3 | using System.Collections.Generic;
|
---|
4 | using HeuristicLab.Persistence.Interfaces;
|
---|
5 |
|
---|
6 | namespace 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.