- Timestamp:
- 04/16/09 12:40:41 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/DateTime2XmlFormatter.cs
r1454 r1564 6 6 7 7 [EmptyStorableClass] 8 public class DateTime2XmlFormatter : IFormatter { 9 10 public Type Type { get { return typeof(DateTime); } } 11 public IFormat Format { get { return XmlFormat.Instance; } } 12 13 public object DoFormat(object o) { 14 return ((DateTime)o).Ticks.ToString(); 8 public class DateTime2XmlFormatter : FormatterBase<DateTime, XmlString> { 9 10 public override XmlString Format(DateTime dt) { 11 return new XmlString(dt.Ticks.ToString()); 15 12 } 16 13 17 public o bject Parse(object o) {18 return new DateTime(long.Parse( (string)o));14 public override DateTime Parse(XmlString x) { 15 return new DateTime(long.Parse(x.Data)); 19 16 } 20 17 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/DecimalNumber2XmlFormatterBase.cs
r1554 r1564 7 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 8 9 public abstract class DecimalNumber2XmlFormatterBase<T> : IFormatter { 10 11 public Type Type { get { return typeof(T); } } 12 13 public IFormat Format { get { return XmlFormat.Instance; } } 14 9 public abstract class DecimalNumber2XmlFormatterBase<T> : FormatterBase<T, XmlString> { 10 15 11 private static MethodInfo ToStringMethod = typeof(T) 16 12 .GetMethod( … … 31 27 null); 32 28 33 public o bject DoFormat(object o) {34 return ToStringMethod.Invoke(o, new object[] { "r", CultureInfo.InvariantCulture });29 public override XmlString Format(T t) { 30 return new XmlString((string)ToStringMethod.Invoke(t, new object[] { "r", CultureInfo.InvariantCulture })); 35 31 } 36 public o bject Parse(object o) {37 return ParseMethod.Invoke(null, new[] { o, CultureInfo.InvariantCulture });32 public override T Parse(XmlString x) { 33 return (T)ParseMethod.Invoke(null, new object[] { x.Data, CultureInfo.InvariantCulture }); 38 34 } 39 35 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/SimpleNumber2XmlFormatterBase.cs
r1554 r1564 7 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 8 9 public abstract class SimpleNumber2XmlFormatterBase<T> : IFormatter { 10 11 public Type Type { get { return typeof(T); } } 12 13 public IFormat Format { get { return XmlFormat.Instance; } } 9 public abstract class SimpleNumber2XmlFormatterBase<T> : FormatterBase<T, XmlString> { 14 10 15 11 private static MethodInfo ParseMethod = typeof(T) … … 22 18 null); 23 19 24 public o bject DoFormat(object o) {25 return ((T)o).ToString();20 public override XmlString Format(T t) { 21 return new XmlString(t.ToString()); 26 22 } 27 public o bject Parse(object o) {28 return ParseMethod.Invoke(null, new[] { o});23 public override T Parse(XmlString x) { 24 return (T)ParseMethod.Invoke(null, new[] { x.Data }); 29 25 } 30 26 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/String2XmlFormatter.cs
r1542 r1564 8 8 9 9 [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()); 19 18 } 20 19 21 public object Parse(object o) { 20 private static readonly string[] separators = new string[] { "<![CDATA[", "]]>" }; 21 22 public override string Parse(XmlString x) { 22 23 StringBuilder sb = new StringBuilder(); 23 foreach (string s in ((string)o).Split( 24 new[] { "<![CDATA[", "]]>" }, 24 foreach (string s in x.Data.Split(separators, 25 25 StringSplitOptions.RemoveEmptyEntries)) { 26 26 sb.Append(s);
Note: See TracChangeset
for help on using the changeset viewer.