Line | |
---|
1 | using System;
|
---|
2 | using HeuristicLab.Persistence.Core;
|
---|
3 | using HeuristicLab.Persistence.Interfaces;
|
---|
4 | using System.Collections.Generic;
|
---|
5 |
|
---|
6 | namespace HeuristicLab.Persistence.Default.Decomposers {
|
---|
7 |
|
---|
8 | public class EnumDecomposer : IDecomposer {
|
---|
9 |
|
---|
10 | public bool CanDecompose(Type type) {
|
---|
11 | return type.IsEnum || type == typeof (Enum);
|
---|
12 | }
|
---|
13 |
|
---|
14 | public IEnumerable<Tag> DeCompose(object obj) {
|
---|
15 | yield return new Tag(Enum.GetName(obj.GetType(), obj));
|
---|
16 | }
|
---|
17 |
|
---|
18 | public object CreateInstance(Type t) {
|
---|
19 | return null;
|
---|
20 | }
|
---|
21 |
|
---|
22 | public object Populate(object instance, IEnumerable<Tag> elements, Type t) {
|
---|
23 | IEnumerator<Tag> it = elements.GetEnumerator();
|
---|
24 | it.MoveNext();
|
---|
25 | return Enum.Parse(t, (string)it.Current.Value);
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.