Last change
on this file since 1555 was
1553,
checked in by epitzer, 16 years ago
|
Replace final fixes for broken parent references with separation of instance creation with meta information. (#548)
|
File size:
954 bytes
|
Rev | Line | |
---|
[1456] | 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 |
|
---|
[1539] | 10 | public int Priority {
|
---|
| 11 | get { return 100; }
|
---|
| 12 | }
|
---|
| 13 |
|
---|
[1456] | 14 | public bool CanDecompose(Type type) {
|
---|
[1542] | 15 | return type.IsEnum || type == typeof(Enum);
|
---|
[1456] | 16 | }
|
---|
| 17 |
|
---|
[1553] | 18 | public IEnumerable<Tag> CreateMetaInfo(object obj) {
|
---|
[1456] | 19 | yield return new Tag(Enum.GetName(obj.GetType(), obj));
|
---|
| 20 | }
|
---|
| 21 |
|
---|
[1553] | 22 | public IEnumerable<Tag> Decompose(object obj) {
|
---|
| 23 | return new Tag[] { };
|
---|
[1456] | 24 | }
|
---|
[1553] | 25 |
|
---|
| 26 | public object CreateInstance(Type t, IEnumerable<Tag> metaInfo) {
|
---|
| 27 | IEnumerator<Tag> it = metaInfo.GetEnumerator();
|
---|
[1456] | 28 | it.MoveNext();
|
---|
| 29 | return Enum.Parse(t, (string)it.Current.Value);
|
---|
| 30 | }
|
---|
[1539] | 31 |
|
---|
[1553] | 32 | public void Populate(object instance, IEnumerable<Tag> elements, Type t) {
|
---|
| 33 | }
|
---|
[1456] | 34 | }
|
---|
| 35 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.