Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/16/09 12:40:41 (16 years ago)
Author:
epitzer
Message:

Stronger typing for formatters with the help of generics. Separate format and serial data type. (#548)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/String2XmlFormatter.cs

    r1542 r1564  
    88
    99  [EmptyStorableClass]
    10   public class String2XmlFormatter : IFormatter {
    11 
    12     public Type Type { get { return typeof(string); } }
    13     public IFormat Format { get { return XmlFormat.Instance;  } }
    14 
    15     public object DoFormat(object o) {     
    16       return "<![CDATA[" +
    17         ((string)o).Replace("]]>", "]]]]><![CDATA[>") +
    18         "]]>";
     10  public class String2XmlFormatter : FormatterBase<string, XmlString> {
     11   
     12    public override XmlString Format(string s) {
     13      StringBuilder sb = new StringBuilder();
     14      sb.Append("<![CDATA[");
     15      sb.Append(s.Replace("]]>", "]]]]><![CDATA[>"));
     16      sb.Append("]]>");
     17      return new XmlString(sb.ToString()); 
    1918    }
    2019
    21     public object Parse(object o) {
     20    private static readonly string[] separators = new string[] { "<![CDATA[", "]]>" };
     21
     22    public override string Parse(XmlString x) {
    2223      StringBuilder sb = new StringBuilder();
    23       foreach (string s in ((string)o).Split(
    24         new[] { "<![CDATA[", "]]>" },
     24      foreach (string s in x.Data.Split(separators,       
    2525        StringSplitOptions.RemoveEmptyEntries)) {
    2626        sb.Append(s);
Note: See TracChangeset for help on using the changeset viewer.