public override int GetHashCode() { unchecked { var hashCode = (SampleString != null ? SampleString.GetHashCode() : 0); hashCode = (hashCode * 397) ^ SampleInt8.GetHashCode(); hashCode = (hashCode * 397) ^ SampleInt16.GetHashCode(); hashCode = (hashCode * 397) ^ SampleInt32; hashCode = (hashCode * 397) ^ SampleInt64.GetHashCode(); hashCode = (hashCode * 397) ^ SampleUInt8.GetHashCode(); hashCode = (hashCode * 397) ^ SampleUInt16.GetHashCode(); hashCode = (hashCode * 397) ^ (int)SampleUInt32; hashCode = (hashCode * 397) ^ SampleUInt64.GetHashCode(); hashCode = (hashCode * 397) ^ SampleFloat.GetHashCode(); hashCode = (hashCode * 397) ^ SampleDouble.GetHashCode(); hashCode = (hashCode * 397) ^ SampleDecimal.GetHashCode(); hashCode = (hashCode * 397) ^ SampleBool.GetHashCode(); hashCode = (hashCode * 397) ^ SampleDateTime.GetHashCode(); hashCode = (hashCode * 397) ^ SampleTimeSpan.GetHashCode(); hashCode = (hashCode * 397) ^ (int)SampleEnum; hashCode = (hashCode * 397) ^ (int)SampleFlagEnum; hashCode = (hashCode * 397) ^ SampleNullableUInt32.GetHashCode(); return(hashCode); } }
public void TestDecimal() { var js = new JsonSerializer(); js.JsonOptions.Indent = ""; var v = new SampleDecimal { N = -12.34m }; var jd = new JsonDeserializer(); var result1 = js.ToString(v); Assert.AreEqual("{\n\"N\":-12.34\n}", result1); var w1 = new SampleDecimal(); jd.FromString(w1, result1); Assert.AreEqual(v.N, w1.N); jd.JsonOptions.DecimalAsString = js.JsonOptions.DecimalAsString = true; var result2 = js.ToString(v); Assert.AreEqual("{\n\"N\":\"-12.34\"\n}", result2); var w2 = new SampleDecimal(); jd.FromString(w2, result2); Assert.AreEqual(v.N, w2.N); var w3 = (SampleDecimal)SampleDecimal_JsonDeserializer.Instance.FromString(result1); Assert.AreEqual(v.N, w3.N); }
public void TestDecimal() { var bs = new BinarySerializer(); var v = new SampleDecimal { N = -12.34m }; var result1 = bs.ToBytes(v); Assert.AreEqual( "20 01 00 " + XS(typeof(SampleDecimal)) + " 01 00 " + XS("N", RoughType.Decimal) + " 01 00" + " D2 04 00 00 00 00 00 00 00 00 00 00" + " 00 00 02 80" + " 00 00", XS(result1)); CheckDeserializers(bd => { var w = bd.FromBytes<SampleDecimal>(result1); Assert.AreEqual(v.N, w.N); }); }