Free cookie consent management tool by TermsFeed Policy Generator

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

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

Replace final fixes for broken parent references with separation of instance creation with meta information. (#548)

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