コード例 #1
0
        public void GetMemberInfo_SimpleTestItem_ReturnsMemberInfoList()
        {
            var memberInfo = FormatterUtils.GetMemberInfo(typeof(SimpleTestItem));

            Assert.IsNotNull(memberInfo);
            Assert.AreEqual(2, memberInfo.Count);
        }
コード例 #2
0
        protected virtual object GetFieldOrPropertyValue(object rowObject, string name)
        {
            var rowValue = FormatterUtils.GetFieldOrPropertyValue(rowObject, name);

            if (rowValue is DateTimeOffset)
            {
                return(FormatterUtils.ConvertFromDateTimeOffset((DateTimeOffset)rowValue));
            }

            else if (rowObject is Dictionary <string, object> )
            {
                return((rowObject as Dictionary <string, object>)[name]);
            }

            else if (FormatterUtils.IsExcelSupportedType(rowValue))
            {
                return(rowValue);
            }

            else if ((rowValue is IEnumerable <object>))
            {
                return(rowValue);
            }
            // return string.Join(",", rowValue as IEnumerable<object>);

            return(rowValue == null || DBNull.Value.Equals(rowValue)
                ? string.Empty
                : rowValue.ToString());
        }
コード例 #3
0
        public T[] Deserialize(ref JsonReader <TSymbol> reader)
        {
            T[] temp = null;
            T[] result;
            try
            {
                temp = ArrayPool <T> .Shared.Rent(4);

                reader.ReadBeginArrayOrThrow();
                var count = 0;
                while (!reader.TryReadIsEndArrayOrValueSeparator(ref count)) // count is already preincremented, as it counts the separators
                {
                    if (count == temp.Length)
                    {
                        FormatterUtils.GrowArray(ref temp);
                    }

                    temp[count - 1] = ElementFormatter.Deserialize(ref reader);
                }

                result = count == 0 ? Array.Empty <T>() : FormatterUtils.CopyArray(temp, count);
            }
            finally
            {
                if (temp != null)
                {
                    ArrayPool <T> .Shared.Return(temp);
                }
            }

            return(result);
        }
コード例 #4
0
        public void GetMemberInfo_SimpleTestItem_ReturnsMemberInfoList()
        {
            var memberInfo = FormatterUtils.GetMemberInfo(typeof(SimpleTestItem));

            memberInfo.Should().NotBeNull();
            memberInfo.Count.Should().Be(2);
        }
コード例 #5
0
        public void GetFieldOrPropertyValueT_AnonymousObject_ReturnsPropertyValues()
        {
            var obj = new { prop1 = "test", prop2 = 2.0, prop3 = DateTime.Today };

            FormatterUtils.GetFieldOrPropertyValue <string>(obj, "prop1").Should().Be(obj.prop1);
            FormatterUtils.GetFieldOrPropertyValue <double>(obj, "prop2").Should().Be(obj.prop2);
            FormatterUtils.GetFieldOrPropertyValue <DateTime>(obj, "prop3").Should().Be(obj.prop3);
        }
コード例 #6
0
        public void GetAttribute_ExcelDocumentAttributeOfComplexTestItem_ExcelDocumentAttribute()
        {
            var complexTestItem = typeof(ComplexTestItem);
            var excelAttribute  = FormatterUtils.GetAttribute <ExcelDocumentAttribute>(complexTestItem);

            excelAttribute.Should().NotBeNull();
            excelAttribute.FileName.Should().Be("Complex test item");
        }
コード例 #7
0
        public void GetEnumerableItemType_ArrayOfSimpleTestItem_ReturnsTestItemType()
        {
            var testItemArray = typeof(SimpleTestItem[]);
            var itemType      = FormatterUtils.GetEnumerableItemType(testItemArray);

            itemType.Should().NotBeNull();
            itemType.Should().Be(typeof(SimpleTestItem));
        }
コード例 #8
0
        public void GetEnumerableItemType_IEnumerableOfSimpleTestItem_ReturnsTestItemType()
        {
            var testItemList = typeof(IEnumerable <SimpleTestItem>);
            var itemType     = FormatterUtils.GetEnumerableItemType(testItemList);

            itemType.Should().NotBeNull();
            itemType.Should().Be(typeof(SimpleTestItem));
        }
コード例 #9
0
        public void GetAttribute_ExcelColumnAttributeOfComplexTestItemValue2_ExcelColumnAttribute()
        {
            var value2         = typeof(ComplexTestItem).GetMember("Value2")[0];
            var excelAttribute = FormatterUtils.GetAttribute <ExcelColumnAttribute>(value2);

            Assert.IsNotNull(excelAttribute);
            Assert.AreEqual(2, excelAttribute.Order);
        }
コード例 #10
0
        public void GetMemberInfo_AnonymousType_ReturnsMemberInfoList()
        {
            var anonymous  = new { prop1 = "value1", prop2 = "value2" };
            var memberInfo = FormatterUtils.GetMemberInfo(anonymous.GetType());

            Assert.IsNotNull(memberInfo);
            Assert.AreEqual(2, memberInfo.Count);
        }
コード例 #11
0
        public void GetAttribute_ExcelDocumentAttributeOfComplexTestItem_ExcelDocumentAttribute()
        {
            var complexTestItem = typeof(ComplexTestItem);
            var excelAttribute  = FormatterUtils.GetAttribute <ExcelDocumentAttribute>(complexTestItem);

            Assert.IsNotNull(excelAttribute);
            Assert.AreEqual("Complex test item", excelAttribute.FileName);
        }
コード例 #12
0
        public void GetFieldOrPropertyValueT_AnonymousObject_ReturnsPropertyValues()
        {
            var obj = new { prop1 = "test", prop2 = 2.0, prop3 = DateTime.Today };

            Assert.AreEqual(obj.prop1, FormatterUtils.GetFieldOrPropertyValue <string>(obj, "prop1"));
            Assert.AreEqual(obj.prop2, FormatterUtils.GetFieldOrPropertyValue <double>(obj, "prop2"));
            Assert.AreEqual(obj.prop3, FormatterUtils.GetFieldOrPropertyValue <DateTime>(obj, "prop3"));
        }
コード例 #13
0
        public void GetEnumerableItemType_IEnumerableOfSimpleTestItem_ReturnsTestItemType()
        {
            var testItemList = typeof(IEnumerable <SimpleTestItem>);
            var itemType     = FormatterUtils.GetEnumerableItemType(testItemList);

            Assert.IsNotNull(itemType);
            Assert.AreEqual(typeof(SimpleTestItem), itemType);
        }
コード例 #14
0
        public void GetEnumerableItemType_ArrayOfSimpleTestItem_ReturnsTestItemType()
        {
            var testItemArray = typeof(SimpleTestItem[]);
            var itemType      = FormatterUtils.GetEnumerableItemType(testItemArray);

            Assert.IsNotNull(itemType);
            Assert.AreEqual(typeof(SimpleTestItem), itemType);
        }
コード例 #15
0
        public void GetMemberInfo_AnonymousType_ReturnsMemberInfoList()
        {
            var anonymous  = new { prop1 = "value1", prop2 = "value2" };
            var memberInfo = FormatterUtils.GetMemberInfo(anonymous.GetType());

            memberInfo.Should().NotBeNull();
            memberInfo.Count.Should().Be(2);
        }
コード例 #16
0
        public void GetAttribute_ExcelColumnAttributeOfComplexTestItemValue2_ExcelColumnAttribute()
        {
            var value2         = typeof(ComplexTestItem).GetMember("Value2")[0];
            var excelAttribute = FormatterUtils.GetAttribute <ExcelColumnAttribute>(value2);

            excelAttribute.Should().NotBeNull();
            excelAttribute.Order.Should().Be(2);
        }
コード例 #17
0
        public void GetMemberNames_SimpleTestItem_ReturnsMemberNamesInOrder()
        {
            var memberNames = FormatterUtils.GetMemberNames(typeof(SimpleTestItem));

            memberNames.Should().NotBeNull();
            memberNames.Count.Should().Be(2);
            memberNames[0].Should().Be("Value1");
            memberNames[1].Should().Be("Value2");
        }
コード例 #18
0
        public void MemberOrder_SimpleTestItem_ReturnsMemberOrder()
        {
            var testItemType = typeof(SimpleTestItem);
            var value1       = testItemType.GetMember("Value1")[0];
            var value2       = testItemType.GetMember("Value2")[0];

            FormatterUtils.MemberOrder(value1).Should().Be(-1, "Value1 should have order -1.");
            FormatterUtils.MemberOrder(value2).Should().Be(-1, "Value2 should have order -1.");
        }
コード例 #19
0
        public void GetMemberNames_SimpleTestItem_ReturnsMemberNamesInOrder()
        {
            var memberNames = FormatterUtils.GetMemberNames(typeof(SimpleTestItem));

            Assert.IsNotNull(memberNames);
            Assert.AreEqual(2, memberNames.Count);
            Assert.AreEqual("Value1", memberNames[0]);
            Assert.AreEqual("Value2", memberNames[1]);
        }
コード例 #20
0
        public void MemberOrder_SimpleTestItem_ReturnsMemberOrder()
        {
            var testItemType = typeof(SimpleTestItem);
            var value1       = testItemType.GetMember("Value1")[0];
            var value2       = testItemType.GetMember("Value2")[0];

            Assert.AreEqual(-1, FormatterUtils.MemberOrder(value1), "Value1 should have order -1.");
            Assert.AreEqual(-1, FormatterUtils.MemberOrder(value2), "Value2 should have order -1.");
        }
コード例 #21
0
        public void IsSimpleType_ComplexTypes_ReturnsFalse()
        {
            var anonymous = new { prop = "val" };

            Assert.IsFalse(FormatterUtils.IsSimpleType(anonymous.GetType()));
            Assert.IsFalse(FormatterUtils.IsSimpleType(typeof(Array)));
            Assert.IsFalse(FormatterUtils.IsSimpleType(typeof(IEnumerable <>)));
            Assert.IsFalse(FormatterUtils.IsSimpleType(typeof(object)));
            Assert.IsFalse(FormatterUtils.IsSimpleType(typeof(SimpleTestItem)));
        }
コード例 #22
0
        public void GetMemberNames_AnonymousType_ReturnsMemberNamesInOrderDefined()
        {
            var anonymous   = new { prop1 = "value1", prop2 = "value2" };
            var memberNames = FormatterUtils.GetMemberNames(anonymous.GetType());

            Assert.IsNotNull(memberNames);
            Assert.AreEqual(2, memberNames.Count);
            Assert.AreEqual("prop1", memberNames[0]);
            Assert.AreEqual("prop2", memberNames[1]);
        }
コード例 #23
0
        public void GetEnumerableItemType_ListOfAnonymousObject_ReturnsTestItemType()
        {
            var anonymous = new { prop1 = "value1", prop2 = "value2" };
            var anonymousList = new[] { anonymous }.ToList();

            var itemType = FormatterUtils.GetEnumerableItemType(anonymousList.GetType());

            itemType.Should().NotBeNull();
            itemType.Should().Be(anonymous.GetType());
        }
コード例 #24
0
        public void GetMemberNames_AnonymousType_ReturnsMemberNamesInOrderDefined()
        {
            var anonymous   = new { prop1 = "value1", prop2 = "value2" };
            var memberNames = FormatterUtils.GetMemberNames(anonymous.GetType());

            memberNames.Should().NotBeNull();
            memberNames.Count.Should().Be(2);
            memberNames[0].Should().Be("prop1");
            memberNames[1].Should().Be("prop2");
        }
コード例 #25
0
        public void GetEnumerableItemType_ListOfAnonymousObject_ReturnsTestItemType()
        {
            var anonymous = new { prop1 = "value1", prop2 = "value2" };
            var anonymousList = new[] { anonymous }.ToList();

            var itemType = FormatterUtils.GetEnumerableItemType(anonymousList.GetType());

            Assert.IsNotNull(itemType);
            Assert.AreEqual(anonymous.GetType(), itemType);
        }
コード例 #26
0
        public void GetMemberNames_ComplexTestItem_ReturnsMemberNamesInOrder()
        {
            var memberNames = FormatterUtils.GetMemberNames(typeof(ComplexTestItem));

            memberNames.Should().NotBeNull();
            memberNames.Count.Should().Be(5);
            memberNames[0].Should().Be("Value4");
            memberNames[1].Should().Be("Value1");
            memberNames[2].Should().Be("Value5");
            memberNames[3].Should().Be("Value3");
            memberNames[4].Should().Be("Value2");
        }
コード例 #27
0
        public void GetMemberNames_ComplexTestItem_ReturnsMemberNamesInOrder()
        {
            var memberNames = FormatterUtils.GetMemberNames(typeof(ComplexTestItem));

            Assert.IsNotNull(memberNames);
            Assert.AreEqual(5, memberNames.Count);
            Assert.AreEqual("Value4", memberNames[0]);
            Assert.AreEqual("Value1", memberNames[1]);
            Assert.AreEqual("Value5", memberNames[2]);
            Assert.AreEqual("Value3", memberNames[3]);
            Assert.AreEqual("Value2", memberNames[4]);
        }
コード例 #28
0
        public void MemberOrder_ComplexTestItem_ReturnsMemberOrder()
        {
            var testItemType = typeof(ComplexTestItem);
            var value1       = testItemType.GetMember("Value1")[0];
            var value2       = testItemType.GetMember("Value2")[0];
            var value3       = testItemType.GetMember("Value3")[0];
            var value4       = testItemType.GetMember("Value4")[0];
            var value5       = testItemType.GetMember("Value5")[0];
            var value6       = testItemType.GetMember("Value6")[0];

            Assert.AreEqual(-1, FormatterUtils.MemberOrder(value1), "Value1 should have order -1.");
            Assert.AreEqual(2, FormatterUtils.MemberOrder(value2), "Value2 should have order 2.");
            Assert.AreEqual(1, FormatterUtils.MemberOrder(value3), "Value3 should have order 1.");
            Assert.AreEqual(-2, FormatterUtils.MemberOrder(value4), "Value4 should have order -2.");
            Assert.AreEqual(-1, FormatterUtils.MemberOrder(value5), "Value5 should have order -1.");
            Assert.AreEqual(-1, FormatterUtils.MemberOrder(value6), "Value6 should have order -1.");
        }
コード例 #29
0
        public void MemberOrder_ComplexTestItem_ReturnsMemberOrder()
        {
            var testItemType = typeof(ComplexTestItem);
            var value1       = testItemType.GetMember("Value1")[0];
            var value2       = testItemType.GetMember("Value2")[0];
            var value3       = testItemType.GetMember("Value3")[0];
            var value4       = testItemType.GetMember("Value4")[0];
            var value5       = testItemType.GetMember("Value5")[0];
            var value6       = testItemType.GetMember("Value6")[0];

            FormatterUtils.MemberOrder(value1).Should().Be(-1, "Value1 should have order -1.");
            FormatterUtils.MemberOrder(value2).Should().Be(2, "Value2 should have order 2.");
            FormatterUtils.MemberOrder(value3).Should().Be(1, "Value3 should have order 1.");
            FormatterUtils.MemberOrder(value4).Should().Be(-2, "Value4 should have order -2.");
            FormatterUtils.MemberOrder(value5).Should().Be(-1, "Value5 should have order -1.");
            FormatterUtils.MemberOrder(value6).Should().Be(-1, "Value6 should have order -1.");
        }
コード例 #30
0
        public void GetFieldOrPropertyValueT_ComplexTestItem_ReturnsPropertyValues()
        {
            var obj = new ComplexTestItem()
            {
                Value1 = "Value 1",
                Value2 = DateTime.Today,
                Value3 = true,
                Value4 = 100.1,
                Value5 = TestEnum.Second,
                Value6 = "Value 6"
            };

            Assert.AreEqual(obj.Value1, FormatterUtils.GetFieldOrPropertyValue <string>(obj, "Value1"));
            Assert.AreEqual(obj.Value2, FormatterUtils.GetFieldOrPropertyValue <DateTime>(obj, "Value2"));
            Assert.AreEqual(obj.Value3, FormatterUtils.GetFieldOrPropertyValue <bool>(obj, "Value3"));
            Assert.AreEqual(obj.Value4, FormatterUtils.GetFieldOrPropertyValue <double>(obj, "Value4"));
            Assert.AreEqual(obj.Value5, FormatterUtils.GetFieldOrPropertyValue <TestEnum>(obj, "Value5"));
            Assert.AreEqual(obj.Value6, FormatterUtils.GetFieldOrPropertyValue <string>(obj, "Value6"));
        }