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 TypeDecomposer : IDecomposer {
|
---|
10 |
|
---|
11 | public int Priority {
|
---|
12 | get { return 100; }
|
---|
13 | }
|
---|
14 |
|
---|
15 | public bool CanDecompose(Type type) {
|
---|
16 | return type == typeof(Type) ||
|
---|
17 | type.VersionInvariantName() == "System.RuntimeType, mscorlib";
|
---|
18 | }
|
---|
19 |
|
---|
20 | public IEnumerable<Tag> CreateMetaInfo(object o) {
|
---|
21 | yield return new Tag("VersionInvariantName", ((Type)o).VersionInvariantName());
|
---|
22 | }
|
---|
23 |
|
---|
24 | public IEnumerable<Tag> Decompose(object obj) {
|
---|
25 | return new Tag[] { };
|
---|
26 | }
|
---|
27 |
|
---|
28 | public object CreateInstance(Type type, IEnumerable<Tag> metaInfo) {
|
---|
29 | foreach (var typeName in metaInfo) {
|
---|
30 | return Type.GetType((string)typeName.Value);
|
---|
31 | }
|
---|
32 | return null;
|
---|
33 | }
|
---|
34 |
|
---|
35 | public void Populate(object instance, IEnumerable<Tag> objects, Type type) {
|
---|
36 | }
|
---|
37 | }
|
---|
38 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.