Line | |
---|
1 | using System;
|
---|
2 | using HeuristicLab.Persistence.Core;
|
---|
3 | using HeuristicLab.Persistence.Interfaces;
|
---|
4 | using System.Collections.Generic;
|
---|
5 | using HeuristicLab.Persistence.Default.Decomposers.Storable;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.Persistence.Default.Decomposers {
|
---|
8 |
|
---|
9 | [EmptyStorableClass]
|
---|
10 | public class TypeDecomposer : IDecomposer {
|
---|
11 |
|
---|
12 | public int Priority {
|
---|
13 | get { return 100; }
|
---|
14 | }
|
---|
15 |
|
---|
16 | public bool CanDecompose(Type type) {
|
---|
17 | return type == typeof(Type) ||
|
---|
18 | type.VersionInvariantName() == "System.RuntimeType, mscorlib";
|
---|
19 | }
|
---|
20 |
|
---|
21 | public IEnumerable<Tag> CreateMetaInfo(object o) {
|
---|
22 | yield return new Tag("VersionInvariantName", ((Type)o).VersionInvariantName());
|
---|
23 | }
|
---|
24 |
|
---|
25 | public IEnumerable<Tag> Decompose(object obj) {
|
---|
26 | return new Tag[] { };
|
---|
27 | }
|
---|
28 |
|
---|
29 | public object CreateInstance(Type type, IEnumerable<Tag> metaInfo) {
|
---|
30 | foreach (var typeName in metaInfo) {
|
---|
31 | return Type.GetType((string)typeName.Value);
|
---|
32 | }
|
---|
33 | return null;
|
---|
34 | }
|
---|
35 |
|
---|
36 | public void Populate(object instance, IEnumerable<Tag> objects, Type type) {
|
---|
37 | }
|
---|
38 | }
|
---|
39 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.