Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/16/09 12:40:41 (15 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/ViewOnly/ViewOnlyFormat.cs

    r1556 r1564  
    99namespace HeuristicLab.Persistence.Default.ViewOnly {
    1010
    11   public class ViewOnlyFormat : FormatBase {
    12     public override string Name { get { return "ViewOnly"; } }
    13     public static ViewOnlyFormat Instance = new ViewOnlyFormat();
     11  public class String : ISerialData {
     12    public string Data { get; set; }
     13    public String(string s) {
     14      Data = s;
     15    }
    1416  }
    1517
    16   public abstract class ValueType2ViewFormatter : IFormatter {
    17     public abstract Type Type { get; }
    18     public IFormat Format { get { return ViewOnlyFormat.Instance; } }
    19     public object DoFormat(object o) { return o; }
    20     public object Parse(object o) {
     18  public class ViewOnlyFormat : FormatBase<String> {
     19    public override string Name { get { return "ViewOnly"; } }   
     20  }
     21
     22  public abstract class ValueType2ViewFormatterBase<T> : FormatterBase<T, String> {
     23    public override String Format(T o) { return new String(o.ToString()); }
     24    public override T Parse(String s) {
    2125      throw new NotImplementedException();
    2226    }
    2327  }
    2428
    25   public class String2ViewFormatter : ValueType2ViewFormatter {
    26     public override Type Type { get { return typeof(string); } }
    27   }
     29  [EmptyStorableClass]
     30  public class String2ViewFormatter : ValueType2ViewFormatterBase<string> { }
    2831
    29   public class Bool2ViewFormatter : ValueType2ViewFormatter {
    30     public override Type Type { get { return typeof(bool); } }
    31   }
     32  [EmptyStorableClass]
     33  public class Bool2ViewFormatter : ValueType2ViewFormatterBase<bool> { }
    3234
    33   public class Int2ViewFormatter : ValueType2ViewFormatter {
    34     public override Type Type { get { return typeof(int); } }
    35   }
     35  [EmptyStorableClass]
     36  public class Int2ViewFormatter : ValueType2ViewFormatterBase<int> { }
    3637
    37   public class Double2ViewFormatter : ValueType2ViewFormatter {
    38     public override Type Type { get { return typeof(double); } }
    39   }
     38  [EmptyStorableClass]
     39  public class Double2ViewFormatter : ValueType2ViewFormatterBase<double> { }
    4040
    41   public class DateTime2ViewFormatter : ValueType2ViewFormatter {
    42     public override Type Type { get { return typeof(DateTime); } }
    43   }
     41  [EmptyStorableClass]
     42  public class DateTime2ViewFormatter : ValueType2ViewFormatterBase<DateTime> { }
    4443
    45   public class Type2ViewFormatter : ValueType2ViewFormatter {
    46     public override Type Type { get { return typeof(Type); } }
    47   }
     44  [EmptyStorableClass]
     45  public class Type2ViewFormatter : ValueType2ViewFormatterBase<Type> { }
    4846
    49   public class Float2ViewFormatter : ValueType2ViewFormatter {
    50     public override Type Type { get { return typeof(float); } }
    51   }
    52 
    53   public class ViewOnlyGenerator : Generator<string> {
     47  [EmptyStorableClass]
     48  public class Float2ViewFormatter : ValueType2ViewFormatterBase<float> { }
     49   
     50  public class ViewOnlyGenerator : GeneratorBase<string> {
    5451
    5552    private bool isSepReq;
     
    9895        sb.Append('=');
    9996      }
    100       sb.Append(primitiveToken.SerialData);
     97      sb.Append(((String)primitiveToken.SerialData).Data);
    10198      isSepReq = true;     
    10299      return sb.ToString(); 
     
    140137
    141138    public static string Serialize(object o) {
    142       return Serialize(o, ConfigurationService.Instance.GetDefaultConfig(ViewOnlyFormat.Instance));
     139      return Serialize(o, ConfigurationService.Instance.GetDefaultConfig(new ViewOnlyFormat()));
    143140    }
    144141
Note: See TracChangeset for help on using the changeset viewer.