Explorar o código

Serialisation now works with decimals.

Kenric Nugteren hai 1 mes
pai
achega
40a0c19f1a
Modificáronse 3 ficheiros con 37 adicións e 3 borrados
  1. 6 0
      InABox.Core/CoreUtils.cs
  2. 13 0
      InABox.Core/Query/Filter.cs
  3. 18 3
      InABox.Core/Serialization.cs

+ 6 - 0
InABox.Core/CoreUtils.cs

@@ -1266,6 +1266,12 @@ namespace InABox.Core
                 {
                     return Guid.Empty;
                 }
+                if (type == typeof(decimal))
+                {
+                    return value;
+                    //    if (Equals(FilterConstant.Zero, value))
+                    //        return (double)0;
+                }
                 if (type == typeof(double))
                 {
                     return value;

+ 13 - 0
InABox.Core/Query/Filter.cs

@@ -1101,6 +1101,7 @@ namespace InABox.Core
             Long,
             Float,
             Double,
+            Decimal,
             String,
             Boolean,
             DateTime,
@@ -1216,6 +1217,10 @@ namespace InABox.Core
             {
                 valueType = ValueType.Double;
             }
+            else if (type == typeof(decimal))
+            {
+                valueType = ValueType.Decimal;
+            }
             else
             {
                 throw new Exception("Invalid Filter Value Type");
@@ -1327,6 +1332,10 @@ namespace InABox.Core
             {
                 writer.Write(f64);
             }
+            else if (value is decimal d)
+            {
+                writer.Write(d);
+            }
         }
 
         private ValueTypeClass ReadValueType(CoreBinaryReader reader)
@@ -1360,6 +1369,8 @@ namespace InABox.Core
                     return typeof(float);
                 case ValueType.Double:
                     return typeof(double);
+                case ValueType.Decimal:
+                    return typeof(decimal);
                 case ValueType.String:
                     return typeof(string);
                 case ValueType.Boolean:
@@ -1403,6 +1414,8 @@ namespace InABox.Core
                     return reader.ReadSingle();
                 case ValueType.Double:
                     return reader.ReadDouble();
+                case ValueType.Decimal:
+                    return reader.ReadDecimal();
                 case ValueType.String:
                     return reader.ReadString();
                 case ValueType.Boolean:

+ 18 - 3
InABox.Core/Serialization.cs

@@ -446,8 +446,8 @@ namespace InABox.Core
         /// <remarks>
         /// Handles <see cref="byte"/>[], <see cref="Array"/>s of serialisable values, <see cref="Enum"/>, <see cref="bool"/>, <see cref="string"/>,
         /// <see cref="Guid"/>, <see cref="byte"/>, <see cref="Int16"/>, <see cref="Int32"/>, <see cref="Int64"/>, <see cref="float"/>, <see cref="double"/>,
-        /// <see cref="DateTime"/>, <see cref="TimeSpan"/>, <see cref="LoggablePropertyAttribute"/>, <see cref="IPackable"/>, <see cref="Nullable{T}"/>
-        /// and <see cref="ISerializeBinary"/>.
+        /// <see cref="decimal"/>, <see cref="DateTime"/>, <see cref="TimeSpan"/>, <see cref="LoggablePropertyAttribute"/>, <see cref="IPackable"/>,
+        /// <see cref="Nullable{T}"/> and <see cref="ISerializeBinary"/>.
         /// </remarks>
         /// <param name="writer"></param>
         /// <param name="type"></param>
@@ -524,6 +524,9 @@ namespace InABox.Core
             else if (MatchType<double, object>(type) && value is double f64)
                 writer.Write(f64);
 
+            else if (MatchType<decimal, object>(type) && value is decimal d)
+                writer.Write(d);
+
             else if (MatchType<DateTime, object>(type) && value is DateTime date)
                 writer.Write(date.Ticks);
 
@@ -571,7 +574,7 @@ namespace InABox.Core
         /// </summary>
         /// <remarks>
         /// Handles <see cref="byte"/>[], <see cref="Array"/>s of serialisable values, <see cref="Enum"/>, <see cref="bool"/>, <see cref="string"/>,
-        /// <see cref="Guid"/>, <see cref="byte"/>, <see cref="Int16"/>, <see cref="Int32"/>, <see cref="Int64"/>, <see cref="float"/>, <see cref="double"/>,
+        /// <see cref="Guid"/>, <see cref="byte"/>, <see cref="Int16"/>, <see cref="Int32"/>, <see cref="Int64"/>, <see cref="float"/>, <see cref="double"/>, <see cref="decimal"/>,
         /// <see cref="DateTime"/>, <see cref="TimeSpan"/>, <see cref="LoggablePropertyAttribute"/>, <see cref="IPackable"/>, <see cref="Nullable{T}"/>
         /// and <see cref="ISerializeBinary"/>.
         /// </remarks>
@@ -638,6 +641,10 @@ namespace InABox.Core
             {
                 return reader.ReadDouble();
             }
+            else if (type == typeof(decimal))
+            {
+                return reader.ReadDecimal();
+            }
             else if (type == typeof(DateTime))
             {
                 return new DateTime(reader.ReadInt64());
@@ -967,6 +974,8 @@ namespace InABox.Core
                 case JsonTokenType.Number:
                     if (reader.TryGetInt32(out int intValue))
                         return intValue;
+                    if (reader.TryGetDecimal(out var decimalValue))
+                        return decimalValue;
                     if (reader.TryGetDouble(out double doubleValue))
                         return doubleValue;
                     return null;
@@ -1067,6 +1076,8 @@ namespace InABox.Core
                 writer.WriteNumberValue(f);
             else if (value is double dVal)
                 writer.WriteNumberValue(dVal);
+            else if (value is decimal decVal)
+                writer.WriteNumberValue(decVal);
             else if (value is DateTime dtVal)
                 writer.WriteStringValue(dtVal.ToString());
             else if (value is TimeSpan tsVal)
@@ -1138,6 +1149,10 @@ namespace InABox.Core
                     {
                         return lValue;
                     }
+                    else if(reader.TryGetDecimal(out var decValue))
+                    {
+                        return decValue;
+                    }
                     else if(reader.TryGetDouble(out var dValue))
                     {
                         return dValue;