public void Empty()
        {
            {
                IDictionary <long, bool> dict = new Dictionary <long, bool>();
                var bytes = ZeroFormatterSerializer.Serialize(dict);

                var d = ZeroFormatterSerializer.Deserialize <IDictionary <long, bool> >(bytes);

                d.IsEmpty();
            }
            {
                var lookup = Enumerable.Empty <int>().ToLookup(x => x % 2 == 0);
                var c      = ZeroFormatterSerializer.Convert(lookup);
                c.IsEmpty();
            }
            {
                IList <int> fixedList = Enumerable.Empty <int>().ToArray();
                var         c         = ZeroFormatterSerializer.Convert(fixedList);
                c.IsEmpty();
            }
            {
                IList <string> variableList = Enumerable.Empty <string>().ToArray();
                var            c            = ZeroFormatterSerializer.Convert(variableList);
                c.IsEmpty();
            }
        }
        public void VariableReadOnlyList()
        {
            var bytes = new byte[1000];
            IReadOnlyList <string> variableList = new[] { "abcde", "fghijk" };
            var record = KeyTuple.Create("aiueo", variableList, "kakikukeko");

            var size = ZeroFormatterSerializer.Serialize(ref bytes, 33, record);

            var newBytes = new byte[2000];

            Buffer.BlockCopy(bytes, 33, newBytes, 99, size);

            var result = ZeroFormatterSerializer.Deserialize <KeyTuple <string, IList <string>, string> >(newBytes, 99);

            {
                result.Item1.Is("aiueo");
                var l = result.Item2;
                l.Count.Is(2);
                l[0].Is("abcde");
                l[1].Is("fghijk");
                result.Item3.Is("kakikukeko");
            }

            result.Item2[0] = "zzzzz"; // mutate

            var reconvert = ZeroFormatterSerializer.Convert(result);
            {
                reconvert.Item1.Is("aiueo");
                var l = reconvert.Item2;
                l.Count.Is(2);
                l[0].Is("zzzzz");
                l[1].Is("fghijk");
                reconvert.Item3.Is("kakikukeko");
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            ZeroFormatter.Formatters.Formatter <Guid> .Register(new GuidFormatter());

            ZeroFormatter.Formatters.Formatter <Uri> .Register(new UriFormatter());


            ZeroFormatter.Formatters.Formatter.AppendFormatterResolver(t =>
            {
                if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(KeyValuePair <,>))
                {
                    var formatterType = typeof(KeyValuePairFormatter <,>).MakeGenericType(t.GetGenericArguments());
                    return(Activator.CreateInstance(formatterType));
                }

                return(null);
            });


            var my = new MyGuid()
            {
                MyProperty  = Guid.NewGuid(),
                MyProperty2 = new Uri("http://hogehoge.com/hugahuga/takotako"),
                MyProperty3 = new KeyValuePair <string, int>("hugahugahugahuga", 10000)
            };
            var huga = ZeroFormatterSerializer.Convert(my);

            Console.WriteLine(my.MyProperty);
            Console.WriteLine(huga.MyProperty);
            Console.WriteLine(huga.MyProperty3);
            Console.WriteLine(my.MyProperty2);
            Console.WriteLine(huga.MyProperty2);
            Console.WriteLine(huga.MyProperty3);
        }
Exemple #4
0
        public void ArrayFormatter()
        {
            {
                var conv = ZeroFormatterSerializer.Convert(new[]
                {
                    new MyVector(1.32342f, 32423.342f),
                    new MyVector(-1.0f, 42.452f),
                    new MyVector(0f, -32662.25252f),
                });

                conv[0].X.Is(1.32342f); conv[0].Y.Is(32423.342f);
                conv[1].X.Is(-1.0f); conv[1].Y.Is(42.452f);
                conv[2].X.Is(0f); conv[2].Y.Is(-32662.25252f);
            }
            {
                var conv = ZeroFormatterSerializer.Convert(new[]
                {
                    new MyVectorClass(1.32342f, 32423.342f),
                    new MyVectorClass(-1.0f, 42.452f),
                    new MyVectorClass(0f, -32662.25252f),
                });

                conv[0].X.Is(1.32342f); conv[0].Y.Is(32423.342f);
                conv[1].X.Is(-1.0f); conv[1].Y.Is(42.452f);
                conv[2].X.Is(0f); conv[2].Y.Is(-32662.25252f);
            }
        }
        public void KeyTupleFormatter()
        {
            var kc = new KeyTupleCheck();

            kc.KeyTupleDictionary = new Dictionary <KeyTuple <int, string>, MyClass>
            {
                { KeyTuple.Create(1, "aaa"), new MyClass {
                      Age = 10, FirstName = "hoge", LastName = "huga", MyList = new [] { 1, 10, 100 }
                  } },
                { KeyTuple.Create(9, "zzz"), new MyClass {
                      Age = 20, FirstName = "hage", LastName = "hnga", MyList = new [] { 3, 44, 200 }
                  } },
                { KeyTuple.Create(4, "vda"), new MyClass {
                      Age = 30, FirstName = "hbge", LastName = "hzga", MyList = new [] { 4, 33, 300 }
                  } }
            };

            var converted = ZeroFormatterSerializer.Convert(kc);

            converted.KeyTupleDictionary.Count.Is(3);

            var a = converted.KeyTupleDictionary[KeyTuple.Create(1, "aaa")];
            var b = converted.KeyTupleDictionary[KeyTuple.Create(9, "zzz")];
            var c = converted.KeyTupleDictionary[KeyTuple.Create(4, "vda")];

            a.Age.Is(10); a.FirstName.Is("hoge"); a.LastName.Is("huga"); a.MyList.IsCollection(1, 10, 100);
            b.Age.Is(20); b.FirstName.Is("hage"); b.LastName.Is("hnga"); b.MyList.IsCollection(3, 44, 200);
            c.Age.Is(30); c.FirstName.Is("hbge"); c.LastName.Is("hzga"); c.MyList.IsCollection(4, 33, 300);
        }
Exemple #6
0
        public void PrimitiveArrayFormatter()
        {
            /*
             * Tuple.Create(typeof(Int16), 2),
             * Tuple.Create(typeof(Int32), 4),
             * Tuple.Create(typeof(Int64), 8),
             * Tuple.Create(typeof(UInt16), 2),
             * Tuple.Create(typeof(UInt32), 4),
             * Tuple.Create(typeof(UInt64), 8),
             * Tuple.Create(typeof(Single), 4),
             * Tuple.Create(typeof(Double), 8),
             * Tuple.Create(typeof(bool), 1),
             * Tuple.Create(typeof(byte), 1),
             * Tuple.Create(typeof(sbyte), 1),
             * Tuple.Create(typeof(char), 2),
             */

            ZeroFormatterSerializer.Convert(new Int16[] { 1, 2, 3, short.MinValue, short.MaxValue }).Is((short)1, (short)2, (short)3, short.MinValue, short.MaxValue);
            ZeroFormatterSerializer.Convert(new Int32[] { 1, 2, 3, int.MinValue, int.MaxValue }).Is((Int32)1, (Int32)2, (Int32)3, int.MinValue, int.MaxValue);
            ZeroFormatterSerializer.Convert(new Int64[] { 1, 2, 3, long.MinValue, long.MaxValue }).Is((Int64)1, (Int64)2, (Int64)3, long.MinValue, long.MaxValue);
            ZeroFormatterSerializer.Convert(new UInt16[] { 1, 2, 3, UInt16.MinValue, UInt16.MaxValue }).Is((UInt16)1, (UInt16)2, (UInt16)3, UInt16.MinValue, UInt16.MaxValue);
            ZeroFormatterSerializer.Convert(new UInt32[] { 1, 2, 3, UInt32.MinValue, UInt32.MaxValue }).Is((UInt32)1, (UInt32)2, (UInt32)3, UInt32.MinValue, UInt32.MaxValue);
            ZeroFormatterSerializer.Convert(new UInt64[] { 1, 2, 3, UInt64.MinValue, UInt64.MaxValue }).Is((UInt64)1, (UInt64)2, (UInt64)3, UInt64.MinValue, UInt64.MaxValue);
            ZeroFormatterSerializer.Convert(new Single[] { float.MinValue, 2.2f, float.MaxValue }).Is(float.MinValue, 2.2f, float.MaxValue);
            ZeroFormatterSerializer.Convert(new Double[] { double.MinValue, 2.2, double.MaxValue }).Is(double.MinValue, 2.2, double.MaxValue);
            ZeroFormatterSerializer.Convert(new Boolean[] { true, false, true }).Is(true, false, true);
            ZeroFormatterSerializer.Convert(new byte[] { 0, 1, 2, byte.MinValue, byte.MaxValue }).Is((byte)0, (byte)1, (byte)2, byte.MinValue, byte.MaxValue);
            ZeroFormatterSerializer.Convert(new sbyte[] { 0, 1, 2, sbyte.MinValue, sbyte.MaxValue }).Is((sbyte)0, (sbyte)1, (sbyte)2, sbyte.MinValue, sbyte.MaxValue);
            ZeroFormatterSerializer.Convert(new char[] { char.MinValue, char.MaxValue, 'a', 'あ' }).Is(char.MinValue, char.MaxValue, 'a', 'あ');
        }
        public void Class()
        {
            var mc = new MyClass
            {
                MyReadOnlyListOne = new List <int> {
                    1, 10, 100, 1000
                },
                MyReadOnlyListTwo = new string[] { "a", "bcde", "fghijklmnop" },
                MyReadOnlyDictOne = new Dictionary <int, string> {
                    { 0, "a" }, { 100, "bcd" }
                },
                MyReadOnlyDictTwo = new Dictionary <KeyTuple <int, string>, string> {
                    { KeyTuple.Create(10, "aiueo"), "AAA" }, { KeyTuple.Create(999, "nano"), "sa" }
                }
            };

            var converted = ZeroFormatterSerializer.Convert(mc);

            converted.MyReadOnlyListOne.Is(1, 10, 100, 1000);
            converted.MyReadOnlyListTwo.Is("a", "bcde", "fghijklmnop");
            var r1 = converted.MyReadOnlyDictOne.OrderBy(x => x.Key).ToArray();

            r1[0].Key.Is(0); r1[0].Value.Is("a");
            r1[1].Key.Is(100); r1[1].Value.Is("bcd");

            var r2 = converted.MyReadOnlyDictTwo.OrderBy(x => x.Key.Item1).ToArray();

            r2[0].Key.Is(KeyTuple.Create(10, "aiueo")); r2[0].Value.Is("AAA");
            r2[1].Key.Is(KeyTuple.Create(999, "nano")); r2[1].Value.Is("sa");
        }
        public void Serialize2()
        {
            var d = new InDictionary
            {
                D1 = new Dictionary <string, int> {
                    { "a", 1 }, { "b", 2 }
                },
                D2 = new Dictionary <string, int> {
                    { "a", 1 }, { "b", 2 }
                }.AsLazyDictionary(),
                D3 = new Dictionary <string, int> {
                    { "a", 1 }, { "b", 2 }
                },
                D4 = new Dictionary <string, int> {
                    { "a", 1 }, { "b", 2 }
                }.AsLazyReadOnlyDictionary(),
            };

            var c = ZeroFormatterSerializer.Convert(d);

            var props = c.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            c.D1["a"].Is(1); c.D1["b"].Is(2);
            c.D2["a"].Is(1); c.D2["b"].Is(2);
            c.D2["a"].Is(1); c.D2["b"].Is(2);
            c.D2["a"].Is(1); c.D2["b"].Is(2);
        }
        public void LookupSegment()
        {
            ILazyLookup <bool, int> lookup = Enumerable.Range(1, 10).ToLookup(x => x % 2 == 0).AsLazyLookup();
            var segment = ZeroFormatterSerializer.Convert(lookup);

            segment[true].IsCollection(2, 4, 6, 8, 10);
            segment[false].IsCollection(1, 3, 5, 7, 9);

            bool isFirst = true;

            foreach (var g in segment.OrderByDescending(x => x.Key))
            {
                if (isFirst)
                {
                    isFirst = false;
                    g.Key.IsTrue();
                    g.AsEnumerable().IsCollection(2, 4, 6, 8, 10);
                }
                else
                {
                    g.Key.IsFalse();
                    g.AsEnumerable().IsCollection(1, 3, 5, 7, 9);
                }
            }
        }
Exemple #10
0
        public void ModeLazyAll()
        {
            ILazyDictionary <int, string> dict = new Dictionary <int, string>
            {
                { 1, "a" },
                { 2, "b" },
                { 3, "c" }
            }.AsLazyDictionary();

            var immediateLazySegment = ZeroFormatterSerializer.Convert(dict);
            var segment = immediateLazySegment as IZeroFormatterSegment;

            immediateLazySegment[1].Is("a");
            immediateLazySegment[2].Is("b");
            immediateLazySegment[3].Is("c");

            segment.CanDirectCopy().IsTrue();
            var moreSerialize = ZeroFormatterSerializer.Convert(immediateLazySegment, true);

            (moreSerialize as IZeroFormatterSegment).CanDirectCopy().IsTrue();

            moreSerialize.Add(10, "hugahuga");
            (moreSerialize as IZeroFormatterSegment).CanDirectCopy().IsFalse();
            moreSerialize[10].Is("hugahuga");

            var lastSerialize = ZeroFormatterSerializer.Convert(moreSerialize, true);

            lastSerialize[1].Is("a");
            lastSerialize[2].Is("b");
            lastSerialize[3].Is("c");
            moreSerialize[10].Is("hugahuga");
        }
Exemple #11
0
        public void Struct()
        {
            ZeroFormatterSerializer.Convert(new ZeroStruct()).IsInstanceOf <ZeroStruct>();
            var len = ZeroFormatter.Formatters.Formatter <DefaultResolver, ZeroStruct> .Default.GetLength();

            len.IsNotNull();
            len.Is(0);
        }
Exemple #12
0
        public void Vector2()
        {
            var v  = new UnityEngine.Vector2(15.5f, 20.49f);
            var v2 = ZeroFormatterSerializer.Convert(v);

            v2.x.Is(v.x);
            v2.y.Is(v.y);
        }
        public void MyTestMethod()
        {
            var mc1 = ZeroFormatterSerializer.Convert(new MyClass5()
            {
                Dame = "hoge"
            });

            mc1.Dame = "hoge";
        }
Exemple #14
0
        public void FieldStruct()
        {
            var xs = new FloatVector2(100.4f, 200.5f);

            var huga = ZeroFormatterSerializer.Convert(xs);

            huga.x.Is(100.4f);
            huga.y.Is(200.5f);
        }
Exemple #15
0
        public void SkipIndexTest()
        {
            var c = new SkipIndex
            {
                MyProperty1 = 1111,
                MyProperty2 = 9999,
                MyProperty3 = 500,
                MyProperty5 = "ほぐあhzgっhれあgはえ"
            };


            var bytes = ZeroFormatterSerializer.Serialize(c);
            var r     = ZeroFormatterSerializer.Deserialize <SkipIndex>(bytes);

            r.MyProperty1.Is(1111);
            r.MyProperty2.Is(9999);
            r.MyProperty3.Is(500);
            r.MyProperty5.Is("ほぐあhzgっhれあgはえ");

            var r_b = ZeroFormatterSerializer.Convert <SkipIndex>(r);

            r_b.MyProperty1.Is(1111);
            r_b.MyProperty2.Is(9999);
            r_b.MyProperty3.Is(500);
            r_b.MyProperty5.Is("ほぐあhzgっhれあgはえ");



            var r2 = ZeroFormatterSerializer.Deserialize <OtherSchema1>(bytes);

            r2.MyProperty1.Is(1111);

            var r3 = ZeroFormatterSerializer.Deserialize <OtherSchema2>(bytes);

            r3.MyProperty3.Is(500);

            var r4 = ZeroFormatterSerializer.Deserialize <OtherSchema3>(bytes);

            r4.MyProperty7.Is(0);
            r4.MyProperty8.IsNull();
            r4.MyProperty10 = 0;

            r4.MyProperty3 = 3;
            r4.MyProperty8 = 99999999;
            r4.MyProperty7 = 12345.12345;

            r4.MyProperty10 = 54321;

            var moreBytes = ZeroFormatterSerializer.Serialize <OtherSchema3>(r4);
            var r5        = ZeroFormatterSerializer.Deserialize <OtherSchema3>(moreBytes);

            r5.MyProperty3.Is(3);
            r5.MyProperty7.Is(12345.12345);
            r5.MyProperty8.Value.Is(99999999);
            r5.MyProperty10.Is(54321);
        }
        public void KVPTest()
        {
            {
                var t1 = new KeyValuePair <int, int>(100, 300);
                var t2 = ZeroFormatterSerializer.Convert(t1);

                t2.Key.Is(t1.Key);
                t2.Value.Is(t1.Value);
            }
        }
        public void Seq()
        {
            var t = new AllNewFormat()
            {
                A1  = new Int16[] { 1, 2, 3, short.MinValue, short.MaxValue },
                A2  = new Int32[] { 1, 2, 3, int.MinValue, int.MaxValue },
                A3  = new Int64[] { 1, 2, 3, long.MinValue, long.MaxValue },
                A4  = new UInt16[] { 1, 2, 3, UInt16.MinValue, UInt16.MaxValue },
                A5  = new UInt32[] { 1, 2, 3, UInt32.MinValue, UInt32.MaxValue },
                A6  = new UInt64[] { 1, 2, 3, UInt64.MinValue, UInt64.MaxValue },
                A7  = new Single[] { float.MinValue, 2.2f, float.MaxValue },
                A8  = new Double[] { double.MinValue, 2.2, double.MaxValue },
                A9  = new Boolean[] { true, false, true },
                A10 = new byte[] { 0, 1, 2, byte.MinValue, byte.MaxValue },
                A11 = new sbyte[] { 0, 1, 2, sbyte.MinValue, sbyte.MaxValue },
                A12 = new char[] { char.MinValue, char.MaxValue, 'a', 'あ' },
                V1  = new[] { new MyVector(1.3f, 10.4f) },
                V2  = new[] { new MyVectorClass {
                                  X = 3242.3141f, Y = 34224.423f
                              } },
                V3 = new Dictionary <int, string> {
                    { 1231, "hogehoge" }
                },
                V4 = new List <int> {
                    1, 10, 100
                },
                V5 = new HashSet <string> {
                    "a", "b", "cde"
                },
                V6 = new KeyValuePair <int, string>(1000, "aiueo")
            };

            var newT = ZeroFormatterSerializer.Convert(t);

            newT.A1.IsCollection(t.A1);
            newT.A2.IsCollection(t.A2);
            newT.A3.IsCollection(t.A3);
            newT.A4.IsCollection(t.A4);
            newT.A5.IsCollection(t.A5);
            newT.A6.IsCollection(t.A6);
            newT.A7.IsCollection(t.A7);
            newT.A8.IsCollection(t.A8);
            newT.A9.IsCollection(t.A9);
            newT.A10.IsCollection(t.A10);
            newT.A11.IsCollection(t.A11);
            newT.A12.IsCollection(t.A12);

            newT.V1[0].X.Is(1.3f); newT.V1[0].Y.Is(10.4f);
            newT.V2[0].X.Is(3242.3141f); newT.V2[0].Y.Is(34224.423f);
            newT.V3[1231].Is("hogehoge");
            newT.V4.IsCollection(1, 10, 100);
            newT.V5.OrderBy(x => x).IsCollection("a", "b", "cde");
            newT.V6.Key.Is(1000);
            newT.V6.Value.Is("aiueo");
        }
Exemple #18
0
 public void SequenceDictionaryFormatter()
 {
     {
         var r = ZeroFormatterSerializer.Convert(new Dictionary <int, string> {
             { 1, "a" }, { 2, "b" }, { 3, "cdefg" }
         });
         r[1].Is("a");
         r[2].Is("b");
         r[3].Is("cdefg");
     }
 }
Exemple #19
0
        public void MyTestMethod()
        {
            var t2 = new Test2 {
                MyProperty = 100, MyProperty1 = 99
            };

            var t = ZeroFormatterSerializer.Convert(t2);

            t.MyProperty.Is(100);
            t.MyProperty1.Is(99);
        }
Exemple #20
0
        static void Main(string[] args)
        {
            var c = ZeroFormatterSerializer.Convert(new StringZ {
                MyProp = "a"
            });

            c.MyProp = "b";

            var re = ZeroFormatterSerializer.Convert(c);

            Console.WriteLine(re.MyProp);
        }
Exemple #21
0
        public void NullCheck2()
        {
            var c = new AllNullClass();

            var c2 = ZeroFormatterSerializer.Convert <AllNullClass>(c);

            c2.MyProperty1.IsNull();
            c2.MyProperty2.IsNull();
            c2.MyProperty3.IsNull();
            c2.MyProperty4.IsNull();
            c2.MyProperty5.IsNull();
            c2.MyProperty6.IsNull();
            c2.MyProperty7.IsNull();
            c2.MyProperty8.IsNull();

            var notnull = new AllNullClass
            {
                MyProperty1 = new Dictionary <int, string> {
                    { 10, "hoge" }, { 999, "hugahuga" }, { 10000, null }
                },
                MyProperty2 = new List <int> {
                    1, 2, 3, 4, 5
                },
                MyProperty3 = new List <string> {
                    "a", "b", "c"
                },
                MyProperty4 = Enumerable.Range(1, 10).ToLookup(x => x % 2 == 0),
                MyProperty5 = new MyFormatClass()
                {
                    MyProperty = 1000
                },
                MyProperty6 = new byte[] { 1, 10, 100 },
                MyProperty7 = "aaa",
                MyProperty8 = new Dictionary <string, int> {
                    { "hoge", 10 }
                }
            };

            var nc = ZeroFormatterSerializer.Convert <AllNullClass>(notnull);

            nc.MyProperty1.OrderBy(x => x.Key).Select(x => Tuple.Create(x.Key, x.Value)).Is(
                Tuple.Create(10, "hoge"), Tuple.Create(999, "hugahuga"), Tuple.Create(10000, (string)null));
            nc.MyProperty2.Is(1, 2, 3, 4, 5);
            nc.MyProperty3.Is("a", "b", "c");
            nc.MyProperty4[true].Is(2, 4, 6, 8, 10);
            nc.MyProperty4[false].Is(1, 3, 5, 7, 9);
            nc.MyProperty5.MyProperty.Is(1000);
            nc.MyProperty6.Is((byte)1, (byte)10, (byte)100);
            nc.MyProperty7.Is("aaa");
            nc.MyProperty8.Count.Is(1);
            nc.MyProperty8["hoge"].Is(10);
        }
Exemple #22
0
        public void WellknownInterfaces()
        {
            var baseObject = new SequenceFormat()
            {
                ArrayFormat      = new[] { new MyStructFixed(1, 10, 3.4f), new MyStructFixed(2, 6, 5.2f) },
                CollectionFormat = new List <int> {
                    1, 10, 100
                },
                DictionaryFormat = new Dictionary <int, int> {
                    { 1, 100 }, { -4, 9999 }
                },
                InterafceDictionaryFormat = new Dictionary <int, int> {
                    { 1, 100 }, { -4, 9999 }
                },
                InterfaceCollectionFormat = new[] { 1, 10, 1000 },
                InterfaceEnumerableFormat = new[] { 1, 2, 3 },
                ReadOnlyCollectionFormat  = new System.Collections.ObjectModel.ReadOnlyCollection <int>(new[] { 1, 10, 100 }),
                LookupFormat = Enumerable.Range(1, 5).ToLookup(x => x % 2 == 0),

                #if !UNITY
                InterfaceSetFormat = new HashSet <int>(new[] { 1, 9099, 3452 }),
                InterfaceReadOnlyCollectionFormat = new[] { 5, 6, 7 },
                ReadOnlyDictionaryFormat          = new System.Collections.ObjectModel.ReadOnlyDictionary <int, int>(new Dictionary <int, int> {
                    { 9, 9999 }
                }),
                InterfaceReadOnlyDictionaryFormat = new System.Collections.ObjectModel.ReadOnlyDictionary <int, int>(new Dictionary <int, int> {
                    { 9, 9999 }
                }),
                #endif
            };

            var converted = ZeroFormatterSerializer.Convert(baseObject, true);

            converted.ArrayFormat[0].MyProperty1.Is(1); converted.ArrayFormat[0].MyProperty2.Is(10); converted.ArrayFormat[0].MyProperty3.Is(3.4f);
            converted.ArrayFormat[1].MyProperty1.Is(2); converted.ArrayFormat[1].MyProperty2.Is(6); converted.ArrayFormat[1].MyProperty3.Is(5.2f);

            converted.CollectionFormat.Is(1, 10, 100);
            converted.DictionaryFormat[1].Is(100); converted.DictionaryFormat[-4].Is(9999);
            converted.InterafceDictionaryFormat[1].Is(100); converted.InterafceDictionaryFormat[-4].Is(9999);
            converted.InterfaceCollectionFormat.Is(1, 10, 1000);
            converted.InterfaceEnumerableFormat.Is(1, 2, 3);
            converted.ReadOnlyCollectionFormat.Is(1, 10, 100);
            converted.LookupFormat[true].Is(2, 4);
            converted.LookupFormat[false].Is(1, 3, 5);

            #if !UNITY
            converted.InterfaceSetFormat.OrderBy(x => x).Is(1, 3452, 9099);
            converted.InterfaceReadOnlyCollectionFormat.Is(1, 10, 100);
            converted.ReadOnlyDictionaryFormat[9].Is(9999);
            converted.InterfaceReadOnlyDictionaryFormat[9].Is(9999);
            #endif
        }
Exemple #23
0
        public void StaticInclude()
        {
            var prop = new StaticProperty()
            {
                HugaHuga = 999, My2 = new[] { new DameClass {
                                                  Ok = 9
                                              } }
            };

            var hoge = ZeroFormatterSerializer.Convert(prop);

            hoge.HugaHuga.Is(999);
            hoge.My2[0].Ok.Is(9);
        }
Exemple #24
0
 public void CollectionFormatter()
 {
     {
         var r = ZeroFormatterSerializer.Convert(new List <int> {
             1, 10, 100, 1000, 10000
         });
         r.Is(1, 10, 100, 1000, 10000);
     }
     {
         var r = ZeroFormatterSerializer.Convert(new HashSet <string> {
             "a", "b", "cdefg"
         });
         r.OrderBy(x => x).Is("a", "b", "cdefg");
     }
 }
        public void MyTestMethod()
        {
            var standard = ZeroFormatterSerializer.Serialize(new Standard {
                MyProperty0 = 100, MyProperty3 = 300
            });

            var large = ZeroFormatterSerializer.Deserialize <Large>(standard);


            large.MyProperty5.Is(0);
            large.MyProperty6.IsNull();
            large.MyProperty10.IsNull();
            large.MyProperty11.IsNull();
            large.MyProperty13.IsNull();
            large.MyProperty15.IsNull();
            large.MyProperty20.Is(0);

            large.MyProperty0  = 99;
            large.MyProperty3  = 49;
            large.MyProperty5  = 999;
            large.MyProperty6  = "hugahuga";
            large.MyProperty10 = new List <int> {
                1, 10, 100
            };
            large.MyProperty11 = Enumerable.Range(1, 10).ToLookup(x => x % 2 == 0);
            large.MyProperty13 = new List <string> {
                "a", "bcde"
            };
            large.MyProperty15 = Enumerable.Range(1, 10).ToDictionary(x => x.ToString());
            large.MyProperty20 = 999999;

            var convert = ZeroFormatterSerializer.Convert(large);


            convert.MyProperty0.Is(99);
            convert.MyProperty3.Is(49);
            convert.MyProperty5.Is(999);
            convert.MyProperty6.Is("hugahuga");
            convert.MyProperty10.Is(new List <int> {
                1, 10, 100
            });
            convert.MyProperty11[true].Is(2, 4, 6, 8, 10);
            convert.MyProperty13.Is(new List <string> {
                "a", "bcde"
            });
            convert.MyProperty15["3"].Is(3);
            convert.MyProperty20.Is(999999);
        }
Exemple #26
0
        public void Includestruct()
        {
            var xs = ZeroFormatterSerializer.Convert(new IncludeStruct
            {
                MyProperty0 = new MyStructFixed(100, 99999999, -123.43f),
                MyProperty1 = new MyStructVariable(100, "hogehoge", -123.43f)
            });

            xs.MyProperty0.MyProperty1.Is(100);
            xs.MyProperty0.MyProperty2.Is(99999999);
            xs.MyProperty0.MyProperty3.Is(-123.43f);

            xs.MyProperty1.MyProperty1.Is(100);
            xs.MyProperty1.MyProperty2.Is("hogehoge");
            xs.MyProperty1.MyProperty3.Is(-123.43f);
        }
Exemple #27
0
        public void Struct()
        {
            {
                var xs = ZeroFormatterSerializer.Serialize <MyStructFixed>(new MyStructFixed(100, 99999999, -123.43f));
                var x  = ZeroFormatterSerializer.Deserialize <MyStructFixed>(xs);
                x.MyProperty1.Is(100);
                x.MyProperty2.Is(99999999);
                x.MyProperty3.Is(-123.43f);

                var xs2 = ZeroFormatterSerializer.Serialize <MyStructFixed?>(new MyStructFixed(100, 99999999, -123.43f));
                var x2  = ZeroFormatterSerializer.Deserialize <MyStructFixed?>(xs2);
                x2.Value.MyProperty1.Is(100);
                x2.Value.MyProperty2.Is(99999999);
                x2.Value.MyProperty3.Is(-123.43f);

                var xs3 = ZeroFormatterSerializer.Serialize <MyStructFixed?>(null);
                var x3  = ZeroFormatterSerializer.Deserialize <MyStructFixed?>(xs3);
                x3.IsNull();

                var formatter = ZeroFormatter.Formatters.Formatter <MyStructFixed> .Default;
                formatter.GetLength().Is(sizeof(int) + sizeof(long) + sizeof(float));

                var formatter2 = ZeroFormatter.Formatters.Formatter <MyStructFixed?> .Default;
                formatter2.GetLength().Is(sizeof(int) + sizeof(long) + sizeof(float) + 1);
            }
            {
                var y = ZeroFormatterSerializer.Convert <MyStructVariable>(new MyStructVariable(100, "hogehoge", -123.43f));
                y.MyProperty1.Is(100);
                y.MyProperty2.Is("hogehoge");
                y.MyProperty3.Is(-123.43f);

                var y2 = ZeroFormatterSerializer.Convert <MyStructVariable?>(new MyStructVariable(100, "hogehoge", -123.43f));
                y2.Value.MyProperty1.Is(100);
                y2.Value.MyProperty2.Is("hogehoge");
                y2.Value.MyProperty3.Is(-123.43f);

                var y3 = ZeroFormatterSerializer.Convert <MyStructVariable?>(null);
                y3.IsNull();

                var formatter = ZeroFormatter.Formatters.Formatter <MyStructVariable> .Default;
                formatter.GetLength().IsNull();

                var formatter2 = ZeroFormatter.Formatters.Formatter <MyStructVariable?> .Default;
                formatter2.GetLength().IsNull();
            }
        }
Exemple #28
0
        public void Extensiblity()
        {
            Formatter.AppendFormatterResolver(t =>
            {
                if (t == typeof(CannotSerialize))
                {
                    return(new CannotSerializeFormatter());
                }

                return(null);
            });

            Formatter.AppendFormatterResolver(t =>
            {
                if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(KeyValuePair <,>))
                {
                    return(Activator.CreateInstance(typeof(KeyValuePairFormatter <,>).MakeGenericType(t.GenericTypeArguments)));
                }

                return(null);
            });

            Formatter.AppendFormatterResolver(t =>
            {
                if (t == typeof(Uri))
                {
                    return(new UriFormatter());
                }

                return(null);
            });

            var a = ZeroFormatterSerializer.Convert(new CannotSerialize(99, "aaa"));

            a.MyProperty1.Is(99);
            a.MyProperty2.Is("aaa");

            var b = ZeroFormatterSerializer.Convert(new KeyValuePair <string, int>("hoge", 1000));

            b.Key.Is("hoge");
            b.Value.Is(1000);

            var c = ZeroFormatterSerializer.Convert(new Uri("http://google.co.jp/"));

            c.ToString().Is("http://google.co.jp/");
        }
        public void FormatterTracking()
        {
            var cleanBytes = ZeroFormatterSerializer.Serialize(new ClassA
            {
                ValueA = new Dictionary <string, ClassB>
                {
                    { "Mogemoge", new ClassB {
                          Value = "Fugafuga"
                      } },
                },
                ValueB = "HogeHoge",
                ValueC = 10000
            });

            // case of dictionary
            {
                var obj1 = ZeroFormatterSerializer.Deserialize <ClassA>(cleanBytes);

                ZeroFormatterSerializer.Convert(obj1).ValueA["Mogemoge"].Value.Is("Fugafuga");
                obj1.ValueA["Mogemoge"].Value = "hugahgua";

                ZeroFormatterSerializer.Convert(obj1).ValueA["Mogemoge"].Value.Is("hugahgua");
            }

            // case of string
            {
                var obj1 = ZeroFormatterSerializer.Deserialize <ClassA>(cleanBytes);

                ZeroFormatterSerializer.Convert(obj1).ValueB.Is("HogeHoge");
                obj1.ValueB = "ABCDEFG";

                ZeroFormatterSerializer.Convert(obj1).ValueB.Is("ABCDEFG");
                ZeroFormatterSerializer.Convert(obj1).ValueB.Is("ABCDEFG");
            }

            // case of int
            {
                var obj1 = ZeroFormatterSerializer.Deserialize <ClassA>(cleanBytes);

                ZeroFormatterSerializer.Convert(obj1).ValueC.Is(10000);
                obj1.ValueC = 9999;

                ZeroFormatterSerializer.Convert(obj1).ValueC.Is(9999);
            }
        }
Exemple #30
0
        public void GenericStruct()
        {
            var ofDouble = new MyGenericStruct <double>(100.4f, -3, 200.5f);

            var ofDouble2 = ZeroFormatterSerializer.Convert(ofDouble);

            ofDouble2.x.Is(100.4f);
            ofDouble2.y.Is(-3);
            ofDouble2.z.Is(200.5f);

            var ofString = new MyGenericStruct <string>("", int.MaxValue, "abc");

            var ofString2 = ZeroFormatterSerializer.Convert(ofString);

            ofString2.x.Is("");
            ofString2.y.Is(int.MaxValue);
            ofString2.z.Is("abc");
        }