[1454] | 1 | using System;
|
---|
| 2 | using HeuristicLab.Persistence.Core;
|
---|
| 3 | using HeuristicLab.Persistence.Interfaces;
|
---|
| 4 | using System.Collections.Generic;
|
---|
[1623] | 5 | using HeuristicLab.Persistence.Default.Decomposers.Storable;
|
---|
[1454] | 6 |
|
---|
| 7 | namespace HeuristicLab.Persistence.Default.Decomposers {
|
---|
[1566] | 8 |
|
---|
[1563] | 9 | [EmptyStorableClass]
|
---|
[1539] | 10 | public class TypeDecomposer : IDecomposer {
|
---|
| 11 |
|
---|
| 12 | public int Priority {
|
---|
| 13 | get { return 100; }
|
---|
| 14 | }
|
---|
| 15 |
|
---|
[1454] | 16 | public bool CanDecompose(Type type) {
|
---|
[1566] | 17 | return type == typeof(Type) ||
|
---|
[1454] | 18 | type.VersionInvariantName() == "System.RuntimeType, mscorlib";
|
---|
| 19 | }
|
---|
| 20 |
|
---|
[1553] | 21 | public IEnumerable<Tag> CreateMetaInfo(object o) {
|
---|
| 22 | yield return new Tag("VersionInvariantName", ((Type)o).VersionInvariantName());
|
---|
[1454] | 23 | }
|
---|
| 24 |
|
---|
[1553] | 25 | public IEnumerable<Tag> Decompose(object obj) {
|
---|
| 26 | return new Tag[] { };
|
---|
[1454] | 27 | }
|
---|
| 28 |
|
---|
[1553] | 29 | public object CreateInstance(Type type, IEnumerable<Tag> metaInfo) {
|
---|
[1625] | 30 | IEnumerator<Tag> it = metaInfo.GetEnumerator();
|
---|
| 31 | try {
|
---|
| 32 | it.MoveNext();
|
---|
| 33 | } catch (InvalidOperationException e) {
|
---|
| 34 | throw new PersistenceException("Insufficient meta information to instantiate Type object", e);
|
---|
[1454] | 35 | }
|
---|
[1625] | 36 | try {
|
---|
| 37 | return Type.GetType((string)it.Current.Value, true);
|
---|
| 38 | } catch (InvalidCastException e) {
|
---|
| 39 | throw new PersistenceException("Invalid meta information during reconstruction of Type object", e);
|
---|
| 40 | } catch (TypeLoadException e) {
|
---|
| 41 | throw new PersistenceException(String.Format(
|
---|
| 42 | "Cannot load Type {0}, make sure all required assemblies are available.",
|
---|
| 43 | (string)it.Current.Value), e);
|
---|
| 44 | }
|
---|
[1454] | 45 | }
|
---|
[1553] | 46 |
|
---|
[1566] | 47 | public void Populate(object instance, IEnumerable<Tag> objects, Type type) {
|
---|
[1625] | 48 | // Type ojects are populated during instance creation.
|
---|
[1553] | 49 | }
|
---|
[1454] | 50 | }
|
---|
| 51 | }
|
---|