Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Persistence/Default/Decomposers/EnumDecomposer.cs @ 1476

Last change on this file since 1476 was 1456, checked in by epitzer, 16 years ago

Added EnumDecomposer. (#549)

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