using System; using System.Collections.Generic; using DPumpHydr.WinFrmUI.WenSkin.Json.Utilities; namespace DPumpHydr.WinFrmUI.WenSkin.Json.Serialization { /// /// Contract details for a used by the . /// public class JsonPrimitiveContract : JsonContract { private static readonly Dictionary ReadTypeMap = new Dictionary { [typeof(byte[])] = ReadType.ReadAsBytes, [typeof(byte)] = ReadType.ReadAsInt32, [typeof(short)] = ReadType.ReadAsInt32, [typeof(int)] = ReadType.ReadAsInt32, [typeof(decimal)] = ReadType.ReadAsDecimal, [typeof(bool)] = ReadType.ReadAsBoolean, [typeof(string)] = ReadType.ReadAsString, [typeof(DateTime)] = ReadType.ReadAsDateTime, [typeof(DateTimeOffset)] = ReadType.ReadAsDateTimeOffset, [typeof(float)] = ReadType.ReadAsDouble, [typeof(double)] = ReadType.ReadAsDouble }; internal PrimitiveTypeCode TypeCode { get; set; } /// /// Initializes a new instance of the class. /// /// The underlying type for the contract. public JsonPrimitiveContract(Type underlyingType) : base(underlyingType) { ContractType = JsonContractType.Primitive; TypeCode = ConvertUtils.GetTypeCode(underlyingType); IsReadOnlyOrFixedSize = true; if (ReadTypeMap.TryGetValue(NonNullableUnderlyingType, out var value)) { InternalReadType = value; } } } }