Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/String2XmlFormatter.cs @ 1530

Last change on this file since 1530 was 1476, checked in by epitzer, 16 years ago

Decomposers for all primitive types except string. (#563)

File size: 840 bytes
Line 
1using System;
2using System.Text;
3using HeuristicLab.Persistence.Core;
4using HeuristicLab.Persistence.Interfaces;
5
6namespace HeuristicLab.Persistence.Default.Xml.Primitive {
7
8  [EmptyStorableClass]
9  public class String2XmlFormatter : IFormatter {
10
11    public Type Type { get { return typeof(string); } }
12    public IFormat Format { get { return XmlFormat.Instance;  } }
13
14    public object DoFormat(object o) {     
15      return "<![CDATA[" +
16        ((string)o).Replace("]]>", "]]]]><![CDATA[>") +
17        "]]>";
18    }
19
20    public object Parse(object o) {
21      StringBuilder sb = new StringBuilder();
22      foreach (string s in ((string)o).Split(
23        new[] { "<![CDATA[", "]]>" },
24        StringSplitOptions.RemoveEmptyEntries)) {
25        sb.Append(s);
26      }
27      return sb.ToString();
28    }
29  } 
30}
Note: See TracBrowser for help on using the repository browser.