コード例 #1
0
ファイル: StringTest.cs プロジェクト: samibrahmi/BinaryPack
        // Test method for a generic string
        private static void Test(string?text)
        {
            // Serialization
            BinaryWriter writer = new BinaryWriter(BinaryWriter.DefaultSize);

            StringProcessor.Instance.Serializer(text, ref writer);
            Span <byte>  span   = MemoryMarshal.CreateSpan(ref Unsafe.AsRef(writer.Span.GetPinnableReference()), writer.Span.Length);
            BinaryReader reader = new BinaryReader(span);
            string?      result = StringProcessor.Instance.Deserializer(ref reader);

            // Equality check
            Assert.IsTrue(StructuralComparer.IsMatch(text, result));
        }
コード例 #2
0
        // Test method for nullable struct types
        private static void Test <T>(T?value) where T : struct, IEquatable <T>
        {
            // Serialization
            BinaryWriter writer = new BinaryWriter(BinaryWriter.DefaultSize);

            NullableProcessor <T> .Instance.Serializer(value, ref writer);

            Span <byte>  span   = MemoryMarshal.CreateSpan(ref Unsafe.AsRef(writer.Span.GetPinnableReference()), writer.Span.Length);
            BinaryReader reader = new BinaryReader(span);
            T?           result = NullableProcessor <T> .Instance.Deserializer(ref reader);

            // Equality check
            Assert.IsTrue(StructuralComparer.IsMatch(value, result));
        }
コード例 #3
0
        // Test method for collections of an unmanaged type
        public static void Test(ICollection <DateTime>?sequence)
        {
            // Serialization
            BinaryWriter writer = new BinaryWriter(BinaryWriter.DefaultSize);

            ICollectionProcessor <DateTime> .Instance.Serializer(sequence, ref writer);

            Span <byte>            span   = MemoryMarshal.CreateSpan(ref Unsafe.AsRef(writer.Span.GetPinnableReference()), writer.Span.Length);
            BinaryReader           reader = new BinaryReader(span);
            ICollection <DateTime>?result = ICollectionProcessor <DateTime> .Instance.Deserializer(ref reader);

            // Equality check
            Assert.IsTrue(StructuralComparer.IsMatch(sequence, result));
        }
コード例 #4
0
        // Test method for a generic list of reference types
        public static void Test <T>(List <T>?list) where T : class, IEquatable <T>
        {
            // Serialization
            BinaryWriter writer = new BinaryWriter(BinaryWriter.DefaultSize);

            ListProcessor <T> .Instance.Serializer(list, ref writer);

            Span <byte>  span   = MemoryMarshal.CreateSpan(ref Unsafe.AsRef(writer.Span.GetPinnableReference()), writer.Span.Length);
            BinaryReader reader = new BinaryReader(span);
            List <T>?    result = ListProcessor <T> .Instance.Deserializer(ref reader);

            // Equality check
            Assert.IsTrue(StructuralComparer.IsMatch(list, result));
        }
コード例 #5
0
ファイル: ArrayTest.cs プロジェクト: samibrahmi/BinaryPack
        // Test method for arrays of an unmanaged type
        public static void Test(DateTime[, ]?array)
        {
            // Serialization
            BinaryWriter writer = new BinaryWriter(BinaryWriter.DefaultSize);

            ArrayProcessor <DateTime[, ]> .Instance.Serializer(array, ref writer);

            Span <byte>  span   = MemoryMarshal.CreateSpan(ref Unsafe.AsRef(writer.Span.GetPinnableReference()), writer.Span.Length);
            BinaryReader reader = new BinaryReader(span);

            DateTime[, ]? result = ArrayProcessor <DateTime[, ]> .Instance.Deserializer(ref reader);

            // Equality check
            Assert.IsTrue(StructuralComparer.IsMatch(array?.Cast <DateTime>(), result?.Cast <DateTime>()));
        }
コード例 #6
0
        // Test method for a generic dictionary
        public static void Test <K, V>(IDictionary <K, V?>?dictionary)
            where K : IEquatable <K>
            where V : class, IEquatable <V>
        {
            // Serialization
            BinaryWriter writer = new BinaryWriter(BinaryWriter.DefaultSize);

            IDictionaryProcessor <K, V?> .Instance.Serializer(dictionary, ref writer);

            Span <byte>         span   = MemoryMarshal.CreateSpan(ref Unsafe.AsRef(writer.Span.GetPinnableReference()), writer.Span.Length);
            BinaryReader        reader = new BinaryReader(span);
            IDictionary <K, V?>?result = IDictionaryProcessor <K, V?> .Instance.Deserializer(ref reader);

            // Equality check
            Assert.IsTrue(StructuralComparer.IsMatch(dictionary, result));
        }
コード例 #7
0
ファイル: ObjectTest.cs プロジェクト: samibrahmi/BinaryPack
        // Test method for reference types
        private static void Test <T>() where T : class, IInitializable, IEquatable <T>, new()
        {
            // Initialization
            T obj = new T();

            obj.Initialize();

            // Serialization
            BinaryWriter writer = new BinaryWriter(BinaryWriter.DefaultSize);

            ObjectProcessor <T> .Instance.Serializer(obj, ref writer);

            Span <byte>  span   = MemoryMarshal.CreateSpan(ref Unsafe.AsRef(writer.Span.GetPinnableReference()), writer.Span.Length);
            BinaryReader reader = new BinaryReader(span);
            T            result = ObjectProcessor <T> .Instance.Deserializer(ref reader);

            // Equality check
            Assert.IsTrue(StructuralComparer.IsMatch(obj, result));
        }
コード例 #8
0
ファイル: BitArrayTest.cs プロジェクト: samibrahmi/BinaryPack
        // Test method for a generic BitArray instance
        public static void Test(BitArray?array)
        {
            // Serialization
            BinaryWriter writer = new BinaryWriter(BinaryWriter.DefaultSize);

            BitArrayProcessor.Instance.Serializer(array, ref writer);
            Span <byte>  span   = MemoryMarshal.CreateSpan(ref Unsafe.AsRef(writer.Span.GetPinnableReference()), writer.Span.Length);
            BinaryReader reader = new BinaryReader(span);
            BitArray?    result = BitArrayProcessor.Instance.Deserializer(ref reader);

            // Equality check
            if (array == null)
            {
                Assert.IsNull(result);
            }
            else
            {
                Assert.IsNotNull(result);
                Assert.IsTrue(array.Length == result !.Length);
                Assert.IsTrue(StructuralComparer.IsMatch(array.Cast <bool>(), result.Cast <bool>()));
            }
        }
コード例 #9
0
 public bool Equals(ValidationReferenceTypeModel?other)
 {
     if (other is null)
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return
         (P1 == other.P1 &&
          P2 == other.P2 &&
          P3 == other.P3 &&
          MathF.Abs(P4 - other.P4) < 0.001f &&
          Math.Abs(P5 - other.P5) < 0.001 &&
          P6.Equals(other.P6) &&
          P7.Equals(other.P7) &&
          PN1_0 == other.PN1_0 &&
          PN1_1 == other.PN1_1 &&
          PN2 == other.PN2 &&
          PN3_0 == other.PN3_0 &&
          PN3_1 == other.PN3_1 &&
          (PN4.HasValue && other.PN4.HasValue && MathF.Abs(PN4.Value - other.PN4.Value) < 0.001f ||
           PN4 == null && other.PN4 == null) &&
          (PN5.HasValue && other.PN5.HasValue && Math.Abs(PN5.Value - other.PN5.Value) < 0.001 ||
           PN5 == null && other.PN5 == null) &&
          (PN6.HasValue && other.PN6.HasValue && PN6.Value.Equals(other.PN6.Value) ||
           PN6 == null && other.PN6 == null) &&
          (PN7_0.HasValue && other.PN7_0.HasValue && PN7_0.Value.Equals(other.PN7_0.Value) ||
           PN7_0 == null && other.PN7_0 == null) &&
          (PN7_1.HasValue && other.PN7_1.HasValue && PN7_1.Value.Equals(other.PN7_1.Value) ||
           PN7_1 == null && other.PN7_1 == null) &&
          (P8_0 != null && other.P8_0 != null && P8_0.Equals(other.P8_0) ||
           P8_0 == null && other.P8_0 == null) &&
          (P8_1 != null && other.P8_1 != null && P8_1.Equals(other.P8_1) ||
           P8_1 == null && other.P8_1 == null) &&
          (P8_2 != null && other.P8_2 != null && P8_2.Equals(other.P8_2) ||
           P8_2 == null && other.P8_2 == null) &&
          (P9_0 != null && other.P9_0 != null && P9_0.Length == other.P9_0.Length && P9_0.Zip(other.P9_0).All(t => t.First == t.Second) ||
           P9_0 == null && other.P9_0 == null) &&
          (P9_1 != null && other.P9_1 != null && P9_1.Length == other.P9_1.Length && P9_1.Zip(other.P9_1).All(t => t.First == t.Second) ||
           P9_1 == null && other.P9_1 == null) &&
          (P10 != null && other.P10 != null && P10.Length == other.P10.Length && P10.Zip(other.P10).All(t => t.First == t.Second) ||
           P10 == null && other.P10 == null) &&
          (P11_0 != null && other.P11_0 != null && P11_0.Length == other.P11_0.Length && P11_0.Zip(other.P11_0).All(t => t.First == t.Second) ||
           P11_0 == null && other.P11_0 == null) &&
          (P11_1 != null && other.P11_1 != null && P11_1.Length == other.P11_1.Length && P11_1.Zip(other.P11_1).All(t => t.First == t.Second) ||
           P11_1 == null && other.P11_1 == null) &&
          (P12_0 != null && other.P12_0 != null && P12_0.Count == other.P12_0.Count && P12_0.Zip(other.P12_0).All(t => t.First == t.Second) ||
           P12_0 == null && other.P12_0 == null) &&
          (P12_1 != null && other.P12_1 != null && P12_1.Count == other.P12_1.Count && P12_1.Zip(other.P12_1).All(t => t.First == t.Second) ||
           P12_1 == null && other.P12_1 == null) &&
          (PN12 != null && other.PN12 != null && PN12.Count == other.PN12.Count && PN12.Zip(other.PN12).All(t => t.First == t.Second) ||
           PN12 == null && other.PN12 == null) &&
          (P13 != null && other.P13 != null && P13.Count == other.P13.Count && P13.Zip(other.P13).All(t => t.First == t.Second) ||
           P13 == null && other.P13 == null) &&
          StructuralComparer.IsMatch(P14, other.P14) &&
          StructuralComparer.IsMatch(P15, other.P15) &&
          StructuralComparer.IsMatch(P16, other.P16) &&
          StructuralComparer.IsMatch(P17, other.P17) &&
          StructuralComparer.IsMatch(P18, other.P18) &&
          StructuralComparer.IsMatch(P19, other.P19) &&
          StructuralComparer.IsMatch(P20, other.P20) &&
          StructuralComparer.IsMatch(P21 as Dictionary <string, int?>, other.P21 as Dictionary <string, int?>) &&
          StructuralComparer.IsMatch(P22 as Dictionary <string, JsonResponseModel?>, other.P22 as Dictionary <string, JsonResponseModel?>));
 }