Line | |
---|
1 | using GeoAPI.Geometries;
|
---|
2 | using HeuristicLab.Persistence.Core;
|
---|
3 | using HeuristicLab.Persistence.Interfaces;
|
---|
4 | using NetTopologySuite.IO;
|
---|
5 | using System;
|
---|
6 | using System.Collections.Generic;
|
---|
7 | using System.Linq;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.BioBoost.Persistence {
|
---|
10 |
|
---|
11 | public class GeometrySerializer : ICompositeSerializer {
|
---|
12 |
|
---|
13 | #region ICompositeSerializer Members
|
---|
14 |
|
---|
15 | public int Priority {
|
---|
16 | get { return 300; }
|
---|
17 | }
|
---|
18 |
|
---|
19 | public bool CanSerialize(Type type) {
|
---|
20 | return type.GetInterfaces().Contains(typeof (IGeometry));
|
---|
21 | }
|
---|
22 |
|
---|
23 | public string JustifyRejection(Type type) {
|
---|
24 | return "type does not implement interface IGeometry";
|
---|
25 | }
|
---|
26 |
|
---|
27 | public object CreateInstance(Type type, IEnumerable<Tag> metaInfo) {
|
---|
28 | return new WKBReader().Read((byte[]) metaInfo.First().Value);
|
---|
29 | }
|
---|
30 |
|
---|
31 | public IEnumerable<Tag> CreateMetaInfo(object obj) {
|
---|
32 | var g = obj as IGeometry;
|
---|
33 | return new[] {new Tag("WKB", new WKBWriter().Write(g))};
|
---|
34 | }
|
---|
35 |
|
---|
36 | public IEnumerable<Tag> Decompose(object obj) {
|
---|
37 | // object was fully decomposed in CreateMetaInfo
|
---|
38 | return new Tag[0];
|
---|
39 | }
|
---|
40 |
|
---|
41 |
|
---|
42 | public void Populate(object instance, IEnumerable<Tag> tags, Type type) {
|
---|
43 | // object was fully populated in CreateInstance
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | #endregion
|
---|
48 | }
|
---|
49 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.