public void TestRestrictingFields()
        {
            var obj = new BizObj
            {
                AInt            = 10,
                AShort          = 9,
                AStr            = "hello",
                ADec            = 10.2M,
                ABool           = true,
                ADateTime       = DateTime.MaxValue,
                ADouble         = 1.23,
                AFloat          = (float)1.5,
                ADateTimeOffset = DateTimeOffset.MaxValue
            };
            var fieldsToSerialize = Serializer <BizObj> .BuildFieldEnabledArray();

            fieldsToSerialize[Serializer <BizObj> .IndexOfProperty("AStr")]   = false;
            fieldsToSerialize[Serializer <BizObj> .IndexOfProperty("AFloat")] = false;
            var values = Serializer <BizObj> .ToValues(obj, fieldsToSerialize);

            Assert.AreEqual(7, values.Length);
            Assert.AreEqual(obj.AInt, values[0]);
            Assert.AreEqual(obj.AShort, values[1]);
            Assert.AreEqual(obj.ADec, values[2]);
            Assert.AreEqual(obj.ABool, values[3]);
            Assert.AreEqual(obj.ADateTime, values[4]);
            Assert.AreEqual(obj.ADouble, values[5]);
            Assert.AreEqual(obj.ADateTimeOffset, values[6]);
        }
        public void TestBasicSerialization()
        {
            var obj = new BizObj
            {
                AInt            = 10,
                AShort          = 9,
                AStr            = "hello",
                ADec            = 10.2M,
                ABool           = true,
                ADateTime       = DateTime.MaxValue,
                ADouble         = 1.23,
                AFloat          = (float)1.5,
                ADateTimeOffset = DateTimeOffset.MaxValue
            };
            var values = Serializer <BizObj> .ToValues(obj);

            Assert.AreEqual(9, values.Length);
            Assert.AreEqual(obj.AInt, values[0]);
            Assert.AreEqual(obj.AShort, values[1]);
            Assert.AreEqual(obj.AStr, values[2]);
            Assert.AreEqual(obj.ADec, values[3]);
            Assert.AreEqual(obj.ABool, values[4]);
            Assert.AreEqual(obj.ADateTime, values[5]);
            Assert.AreEqual(obj.ADouble, values[6]);
            Assert.AreEqual(obj.AFloat, values[7]);
            Assert.AreEqual(obj.ADateTimeOffset, values[8]);
        }
        public void TestSerializationPerformance()
        {
            var obj = new BizObj
            {
                AInt            = 10,
                AShort          = 9,
                AStr            = "hello",
                ADec            = 10.2M,
                ABool           = true,
                ADateTime       = DateTime.MaxValue,
                ADouble         = 1.23,
                AFloat          = (float)1.5,
                ADateTimeOffset = DateTimeOffset.MaxValue
            };
            var serializer = new Serializer <BizObj>();
            var values     = new object[serializer.FieldCount];

            Assert.AreEqual(9, serializer.GetFieldCount(obj));
            for (var i = 0; i < 1000000; i++)
            {
                Serializer <BizObj> .ToValues(obj, values);
            }
        }
        public void TestBuildingSerializerWithMapAndSerializerInstanceOfObject()
        {
            var map = new[]
            {
                "AShort",
                "AInt",
                "ADouble",
                "AFloat",
                "ADateTimeOffset",
                "ABool",
                "ADateTime"
            };
            var obj = new BizObj
            {
                AInt            = 10,
                AShort          = 9,
                AStr            = "hello",
                ADec            = 10.2M,
                ABool           = true,
                ADateTime       = DateTime.MaxValue,
                ADouble         = 1.23,
                AFloat          = (float)1.5,
                ADateTimeOffset = DateTimeOffset.MaxValue
            };
            var indexMap = Serializer <object> .BuildFieldMap(obj, map);

            var fieldsToSerialize = Serializer <object> .BuildFieldEnabledArray(obj);

            fieldsToSerialize[Serializer <object> .IndexOfProperty(obj, "AInt")] = false;
            var serializer = new Serializer <object>
            {
                FieldMap      = indexMap,
                OnOffsEnabled = fieldsToSerialize
            };

            Assert.ThrowsException <InvalidOperationException>(() => serializer.ToValues(obj));
        }
        public void TestBuildingSerializerWithMap()
        {
            var map = new[]
            {
                "AShort",
                "AInt",
                "ADouble",
                "AFloat",
                "ADateTimeOffset",
                "ABool",
                "ADateTime"
            };
            var indexMap = Serializer <BizObj> .BuildFieldMap(map);

            var obj = new BizObj
            {
                AInt            = 10,
                AShort          = 9,
                AStr            = "hello",
                ADec            = 10.2M,
                ABool           = true,
                ADateTime       = DateTime.MaxValue,
                ADouble         = 1.23,
                AFloat          = (float)1.5,
                ADateTimeOffset = DateTimeOffset.MaxValue
            };
            var values = Serializer <BizObj> .ToValues(obj, null, indexMap);

            Assert.AreEqual(obj.AShort, values[0]);
            Assert.AreEqual(obj.AInt, values[1]);
            Assert.AreEqual(obj.ADouble, values[2]);
            Assert.AreEqual(obj.AFloat, values[3]);
            Assert.AreEqual(obj.ADateTimeOffset, values[4]);
            Assert.AreEqual(obj.ABool, values[5]);
            Assert.AreEqual(obj.ADateTime, values[6]);
        }