source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Persistence/GeometrySerializer.cs @ 13069

Last change on this file since 13069 was 13069, checked in by gkronber, 7 years ago

#2499: imported source code for HeuristicLab.BioBoost from private repository with some changes

File size: 1.3 KB
Line 
1using GeoAPI.Geometries;
2using HeuristicLab.Persistence.Core;
3using HeuristicLab.Persistence.Interfaces;
4using NetTopologySuite.IO;
5using System;
6using System.Collections.Generic;
7using System.Linq;
8
9namespace 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.