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 | [EmptyStorableClass]
|
---|
9 | public class EnumDecomposer : IDecomposer {
|
---|
10 |
|
---|
11 | public int Priority {
|
---|
12 | get { return 100; }
|
---|
13 | }
|
---|
14 |
|
---|
15 | public bool CanDecompose(Type type) {
|
---|
16 | return type.IsEnum || type == typeof(Enum);
|
---|
17 | }
|
---|
18 |
|
---|
19 | public IEnumerable<Tag> CreateMetaInfo(object obj) {
|
---|
20 | yield return new Tag(Enum.GetName(obj.GetType(), obj));
|
---|
21 | }
|
---|
22 |
|
---|
23 | public IEnumerable<Tag> Decompose(object obj) {
|
---|
24 | return new Tag[] { };
|
---|
25 | }
|
---|
26 |
|
---|
27 | public object CreateInstance(Type t, IEnumerable<Tag> metaInfo) {
|
---|
28 | IEnumerator<Tag> it = metaInfo.GetEnumerator();
|
---|
29 | it.MoveNext();
|
---|
30 | return Enum.Parse(t, (string)it.Current.Value);
|
---|
31 | }
|
---|
32 |
|
---|
33 | public void Populate(object instance, IEnumerable<Tag> elements, Type t) {
|
---|
34 | }
|
---|
35 | }
|
---|
36 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.