Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/19/19 16:33:01 (4 years ago)
Author:
dpiringe
Message:

#3026:

  • relocated GetMaxValue and GetMinValue from ValueTypeValueConverter into BaseConverter
  • fixed a bug in ConstrainedValueParameterConverter (from GetType().Name to ToString())
  • printing now PrettyNames for types
  • added comments
  • added StorableConverter.cs (not finished, maybe not a good converter)
  • added ValueRangeConverter.cs for DoubleRange and IntRange
  • added ParameterConverter.cs for default parameter conversion
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeValueConverter.cs

    r17342 r17353  
    1818      new JsonItem() {
    1919        Value = value.Cast<ValueType>().Value,
    20         Range = new object[] { GetMinValue(), GetMaxValue() }
     20        Range = new object[] { GetMinValue(typeof(T)), GetMaxValue(typeof(T)) }
    2121      };
    22 
    23     #region Helper
    24     private object GetMaxValue() {
    25       TypeCode typeCode = Type.GetTypeCode(typeof(T));
    26 
    27       if (typeof(ValueType).IsEqualTo(typeof(PercentValue)))
    28         return 1.0d;
    29 
    30       switch (typeCode) {
    31         case TypeCode.Int16: return Int16.MaxValue;
    32         case TypeCode.Int32: return Int32.MaxValue;
    33         case TypeCode.Int64: return Int64.MaxValue;
    34         case TypeCode.UInt16: return UInt16.MaxValue;
    35         case TypeCode.UInt32: return UInt32.MaxValue;
    36         case TypeCode.UInt64: return UInt64.MaxValue;
    37         case TypeCode.Single: return Single.MaxValue;
    38         case TypeCode.Double: return Double.MaxValue;
    39         case TypeCode.Decimal: return Decimal.MaxValue;
    40         case TypeCode.Byte: return Byte.MaxValue;
    41         case TypeCode.Boolean: return true;
    42         default: return default(T);
    43       }
    44     }
    45 
    46     private object GetMinValue() {
    47       TypeCode typeCode = Type.GetTypeCode(typeof(T));
    48 
    49       if (typeof(ValueType).IsEqualTo(typeof(PercentValue)))
    50         return 0.0d;
    51 
    52       switch (typeCode) {
    53         case TypeCode.Int16: return Int16.MinValue;
    54         case TypeCode.Int32: return Int32.MinValue;
    55         case TypeCode.Int64: return Int64.MinValue;
    56         case TypeCode.UInt16: return UInt16.MinValue;
    57         case TypeCode.UInt32: return UInt32.MinValue;
    58         case TypeCode.UInt64: return UInt64.MinValue;
    59         case TypeCode.Single: return Single.MinValue;
    60         case TypeCode.Double: return Double.MinValue;
    61         case TypeCode.Decimal: return Decimal.MinValue;
    62         case TypeCode.Byte: return Byte.MinValue;
    63         case TypeCode.Boolean: return false;
    64         default: return default(T);
    65       }
    66     }
    67     #endregion
    6822  }
    6923}
Note: See TracChangeset for help on using the changeset viewer.