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);
     }
 }
Beispiel #2
0
 public void TestProtobufFloat()
 {
     var v1 = new SampleFloat { F = 1e-20f, D = -3.1415E+100 };
     var ps = new ProtobufSerializer();
     var result = ps.ToBytes(v1);
     CollectionAssert.AreEqual(new byte[] {
         0x09, 0x00, 0x00, 0x00, 0x00, 0xA1, 0x9C, 0xC7, 0x3B,
         0x11, 0xCA, 0xDC, 0x09, 0x3E, 0xBE, 0xB9, 0xCC, 0xD4 }, result);
     var v2 = new SampleFloat();
     (new ProtobufDeserializer()).FromBytes(v2, result);
     Assert.AreEqual(v1.F, v2.F);
     Assert.AreEqual(v1.D, v2.D);
 }
 public bool Equals(SettingsStructProperties other) => SampleString == other.SampleString &&
 SampleInt8 == other.SampleInt8 &&
 SampleInt16 == other.SampleInt16 &&
 SampleInt32 == other.SampleInt32 &&
 SampleInt64 == other.SampleInt64 &&
 SampleUInt8 == other.SampleUInt8 &&
 SampleUInt16 == other.SampleUInt16 &&
 SampleUInt32 == other.SampleUInt32 &&
 SampleUInt64 == other.SampleUInt64 &&
 SampleFloat.Equals(other.SampleFloat) &&
 SampleDouble.Equals(other.SampleDouble) &&
 SampleDecimal == other.SampleDecimal &&
 SampleBool == other.SampleBool &&
 SampleDateTime.Equals(other.SampleDateTime) &&
 SampleTimeSpan.Equals(other.SampleTimeSpan) &&
 SampleEnum == other.SampleEnum &&
 SampleFlagEnum == other.SampleFlagEnum &&
 SampleNullableUInt32 == other.SampleNullableUInt32;
Beispiel #4
0
        public void TestProtobufFloat()
        {
            var v1 = new SampleFloat {
                F = 1e-20f, D = -3.1415E+100
            };
            var ps     = new ProtobufSerializer();
            var result = ps.ToBytes(v1);

            CollectionAssert.AreEqual(new byte[] {
                0x09, 0x00, 0x00, 0x00, 0x00, 0xA1, 0x9C, 0xC7, 0x3B,
                0x11, 0xCA, 0xDC, 0x09, 0x3E, 0xBE, 0xB9, 0xCC, 0xD4
            }, result);
            var v2 = new SampleFloat();

            (new ProtobufDeserializer()).FromBytes(v2, result);
            Assert.AreEqual(v1.F, v2.F);
            Assert.AreEqual(v1.D, v2.D);
        }
Beispiel #5
0
 public bool Equals(SettingsObjectProperties other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(SampleString == other.SampleString && SampleInt8 == other.SampleInt8 &&
            SampleInt16 == other.SampleInt16 && SampleInt32 == other.SampleInt32 &&
            SampleInt64 == other.SampleInt64 && SampleUInt8 == other.SampleUInt8 &&
            SampleUInt16 == other.SampleUInt16 && SampleUInt32 == other.SampleUInt32 &&
            SampleUInt64 == other.SampleUInt64 && SampleFloat.Equals(other.SampleFloat) &&
            SampleDouble.Equals(other.SampleDouble) && SampleDecimal == other.SampleDecimal &&
            SampleBool == other.SampleBool && SampleDateTime.Equals(other.SampleDateTime) &&
            SampleTimeSpan.Equals(other.SampleTimeSpan) && SampleEnum == other.SampleEnum &&
            SampleFlagEnum == other.SampleFlagEnum && SampleNullableUInt32 == other.SampleNullableUInt32);
 }
Beispiel #6
0
        public void TestFloat()
        {
            var js = new JsonSerializer();
            js.Options.TagMode = TagMode.Names;

            var v = new SampleFloat { F = 1e-20f, D = -3.1415e100d };
            js.JsonOptions.Indent = "";

            var result1 = js.ToString(v);
            Assert.AreEqual("{\n\"F\":1E-20,\n\"D\":-3.1415E100\n}", result1);

            var w = new SampleFloat();
            var jd = new JsonDeserializer();
            jd.Options.TagMode = TagMode.Names;
            jd.FromString(w, result1);
            Assert.AreEqual(v.F, w.F);
            Assert.AreEqual(v.D, w.D);

            Assert.AreEqual("NaN", js.ToString(Double.NaN));
            Assert.AreEqual("Infinity", js.ToString(Double.PositiveInfinity));
            Assert.AreEqual("-Infinity", js.ToString(Double.NegativeInfinity));
        }
Beispiel #7
0
        public void TestFloat()
        {
            var bs = new BinarySerializer();
            bs.Options.TagMode = TagMode.Names;

            var v = new SampleFloat { F = 1e-20f, D = -3.1415e100d };

            var result1 = bs.ToBytes(v);
            Assert.AreEqual(
                "20 01 00 " + XS(typeof(SampleFloat)) + " 02 00 " +
                XS("F", RoughType.Float, "D", RoughType.Double) +
                " 01 00 08 E5 3C 1E 02 00 CA DC 09 3E BE B9 CC D4 00 00",
                XS(result1));

            var w = new SampleFloat();
            var bd = new BinaryDeserializer();
            bd.Options.TagMode = TagMode.Names;
            bd.FromBytes(w, result1);
            Assert.AreEqual(v.F, w.F);
            Assert.AreEqual(v.D, w.D);
        }