当前位置: 首页>>代码示例>>C#>>正文


C# Dictionary.ToObject方法代码示例

本文整理汇总了C#中Dictionary.ToObject方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.ToObject方法的具体用法?C# Dictionary.ToObject怎么用?C# Dictionary.ToObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dictionary的用法示例。


在下文中一共展示了Dictionary.ToObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToObjectEnumPropertyFromString

        public void ToObjectEnumPropertyFromString()
        {
            var dict = new Dictionary<string, object>()
            {
                { "EnumProperty", "One" },
            };

            var value = dict.ToObject<ClassType>();
            Assert.Equal(EnumType.One, value.EnumProperty);
        }
开发者ID:rmagruder,项目名称:Simple.OData.Client,代码行数:10,代码来源:DictionaryExtensionsTests.cs

示例2: ToObjectPrimitiveProperties

        public void ToObjectPrimitiveProperties()
        {
            var dict = new Dictionary<string, object>()
            {
                { "StringProperty", "a" }, 
                { "IntProperty", 1 },
            };

            var value = dict.ToObject<ClassType>();
            Assert.Equal("a", value.StringProperty);
            Assert.Equal(1, value.IntProperty);
        }
开发者ID:rmagruder,项目名称:Simple.OData.Client,代码行数:12,代码来源:DictionaryExtensionsTests.cs

示例3: AsObjectUnknownProperty

        public void AsObjectUnknownProperty()
        {
            var dict = new Dictionary<string, object>()
            {
                { "StringProperty", "a" }, 
                { "IntProperty", 1 },
                { "UnknownProperty", "u" }
            };

            var value = dict.ToObject<ClassType>();
            Assert.Equal("a", value.StringProperty);
            Assert.Equal(1, value.IntProperty);
        }
开发者ID:jaykrz,项目名称:Simple.OData.Client,代码行数:13,代码来源:DictionaryExtensionsTests.cs

示例4: AsObjectPrivateSetter

        public void AsObjectPrivateSetter()
        {
            var dict = new Dictionary<string, object>()
            {
                { "StringProperty", "a" }, 
                { "IntProperty", 1 },
                { "StringPropertyPrivateSetter", "p" }
            };

            var value = dict.ToObject<ClassType>();
            Assert.Equal("a", value.StringProperty);
            Assert.Equal(1, value.IntProperty);
            Assert.Equal("p", value.StringPropertyPrivateSetter);
        }
开发者ID:jaykrz,项目名称:Simple.OData.Client,代码行数:14,代码来源:DictionaryExtensionsTests.cs

示例5: AsObjectField

        public void AsObjectField()
        {
            var dict = new Dictionary<string, object>()
            {
                { "StringProperty", "a" }, 
                { "IntProperty", 1 },
                { "StringField", "f" }
            };

            var value = dict.ToObject<ClassType>();
            Assert.Equal("a", value.StringProperty);
            Assert.Equal(1, value.IntProperty);
            Assert.Equal(null, value.StringField);
        }
开发者ID:jaykrz,项目名称:Simple.OData.Client,代码行数:14,代码来源:DictionaryExtensionsTests.cs

示例6: DifferentTypes

        public void DifferentTypes()
        {
            // Arrange
            var dict = new Dictionary<string, string>()
            {
                { "Id", "11" }, // Should be a Guid
                { "Date", "1999-01-01" },
                { "Enum", "One" },
                { "Array", "1,2,3" },
                { "Text", "eleven" },
            };

            // Act
            dict.ToObject<RecursiveData>();
        }
开发者ID:tallesl,项目名称:net-Object,代码行数:15,代码来源:StringDictionaryTests.cs

示例7: DifferentTypes

        public void DifferentTypes()
        {
            // Arrange
            var dict = new Dictionary<string, object>()
            {
                { "Id", 11 }, // Should be a Guid
                { "Date", new DateTime(1999, 1, 1) },
                { "Enum", Enumeration.One },
                { "Array", new[] { 1, 2, 3, } },
                { "Text", "eleven" },
            };

            // Act
            dict.ToObject<RecursiveData>();
        }
开发者ID:tallesl,项目名称:net-Object,代码行数:15,代码来源:ObjectDictionaryTests.cs

示例8: ToObjectDynamicODataEntry

        public void ToObjectDynamicODataEntry()
        {
            var _ = ODataDynamic.Expression;
            var dict = new Dictionary<string, object>()
            {
                { "StringProperty", "a" }, 
                { "IntProperty", 1 },
            };

            dynamic value = dict.ToObject<ODataEntry>(true);
            Assert.Equal("a", value.StringProperty);
            Assert.Equal(1, value.IntProperty);
        }
开发者ID:rmagruder,项目名称:Simple.OData.Client,代码行数:13,代码来源:DictionaryExtensionsTests.cs

示例9: MapsFromDictionaryNonGeneric

 public void MapsFromDictionaryNonGeneric()
 {
     var dictionary = new Dictionary<string, object> { { "PublicProperty", "Public Property" }, { "IgnoreMe", "la la la" } };
     var testClass = dictionary.ToObject(typeof(TestClass)) as TestClass;
     Assert.AreEqual("Public Property", testClass.PublicProperty);
 }
开发者ID:garrypas,项目名称:EasyReflection,代码行数:6,代码来源:DictionaryExtensionsTests.cs

示例10: ToObjectCompoundCollectionProperty

        public void ToObjectCompoundCollectionProperty()
        {
            var dict = new Dictionary<string, object>()
            {
                { "StringProperty", "a" }, 
                { "IntProperty", 1 },
                { "CompoundCollectionProperty", new[]
                    {
                        new Dictionary<string, object>() { { "StringProperty", "x" }, { "IntProperty", 1 } }, 
                        new Dictionary<string, object>() { { "StringProperty", "y" }, { "IntProperty", 2 } },
                        new Dictionary<string, object>() { { "StringProperty", "z" }, { "IntProperty", 3 } },
                    } 
                }
            };

            var value = dict.ToObject<ClassType>();
            Assert.Equal("a", value.StringProperty);
            Assert.Equal(1, value.IntProperty);
            for (var index = 0; index < 3; index++)
            {
                var kv = (dict["CompoundCollectionProperty"] as IList<IDictionary<string, object>>)[index];
                Assert.Equal(kv["StringProperty"], value.CompoundCollectionProperty[index].StringProperty);
                Assert.Equal(kv["IntProperty"], value.CompoundCollectionProperty[index].IntProperty);
            }
        }
开发者ID:rmagruder,项目名称:Simple.OData.Client,代码行数:25,代码来源:DictionaryExtensionsTests.cs

示例11: ToObjectODataEntry

        public void ToObjectODataEntry()
        {
            var dict = new Dictionary<string, object>()
            {
                { "StringProperty", "a" }, 
                { "IntProperty", 1 },
            };

            var value = dict.ToObject<ODataEntry>(false);
            Assert.Equal("a", value["StringProperty"]);
            Assert.Equal(1, value["IntProperty"]);
        }
开发者ID:rmagruder,项目名称:Simple.OData.Client,代码行数:12,代码来源:DictionaryExtensionsTests.cs

示例12: ToObjectIntCollection

        public void ToObjectIntCollection()
        {
            var dict = new Dictionary<string, object>()
            {
                { "StringProperty", "a" }, 
                { "IntProperty", 1 },
                { "IntCollectionProperty", new [] {1, 2, 3}  }
            };

            var value = dict.ToObject<ClassType>();
            Assert.Equal("a", value.StringProperty);
            Assert.Equal(1, value.IntProperty);
            for (var index = 0; index < 3; index++)
            {
                Assert.Equal((dict["IntCollectionProperty"] as IList<int>)[index], value.IntCollectionProperty[index]);
            }
        }
开发者ID:rmagruder,项目名称:Simple.OData.Client,代码行数:17,代码来源:DictionaryExtensionsTests.cs

示例13: ToObjectCompoundProperty

        public void ToObjectCompoundProperty()
        {
            var dict = new Dictionary<string, object>()
            {
                { "StringProperty", "a" }, 
                { "IntProperty", 1 },
                { "CompoundProperty", new Dictionary<string, object>() { { "StringProperty", "z" }, { "IntProperty", 0 } }  }
            };

            var value = dict.ToObject<ClassType>();
            Assert.Equal("a", value.StringProperty);
            Assert.Equal(1, value.IntProperty);
            Assert.Equal("z", value.CompoundProperty.StringProperty);
            Assert.Equal(0, value.CompoundProperty.IntProperty);
        }
开发者ID:rmagruder,项目名称:Simple.OData.Client,代码行数:15,代码来源:DictionaryExtensionsTests.cs

示例14: NestedDictionary

        public void NestedDictionary()
        {
            var expected = new RecursiveData
            {
                Id = new Guid("366f4bd3-6717-4b14-9c79-70515296df7e"),
                Date = new DateTime(1999, 1, 1),
                Enum = Enumeration.One,
                Text = "level 1",
                Array = new[] { 1, 2, 3, },
                Nested = new RecursiveData
                {
                    Id = new Guid("e591be31-289f-4a99-ba67-288ea24b7d7e"),
                    Date = new DateTime(1999, 2, 2),
                    Enum = Enumeration.Two,
                    Text = "level 2",
                    Array = new[] { 4, 5, 6, },
                    Nested = null,
                },
            };

            var dict = new Dictionary<string, object>()
            {
                // 1st level
                { "Id", expected.Id },
                { "Date", expected.Date },
                { "Enum", expected.Enum },
                { "Text", expected.Text },
                { "Array", expected.Array },

                // 2nd level
                {
                    "Nested",
                    new Dictionary<string, object>
                    {
                        { "Id", expected.Nested.Id },
                        { "Date", expected.Nested.Date },
                        { "Enum", expected.Nested.Enum },
                        { "Text", expected.Nested.Text },
                        { "Array", expected.Nested.Array },
                        { "Nested", expected.Nested.Nested },
                    }
                }
            };

            var actual = dict.ToObject<RecursiveData>();

            // 1st level
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.Date, actual.Date);
            Assert.AreEqual(expected.Enum, actual.Enum);
            Assert.AreEqual(expected.Text, actual.Text);
            CollectionAssert.AreEqual(expected.Array, actual.Array);

            // 2nd level
            Assert.AreEqual(expected.Nested.Id, actual.Nested.Id);
            Assert.AreEqual(expected.Nested.Date, actual.Nested.Date);
            Assert.AreEqual(expected.Nested.Enum, actual.Nested.Enum);
            Assert.AreEqual(expected.Nested.Text, actual.Nested.Text);
            CollectionAssert.AreEqual(expected.Nested.Array, actual.Nested.Array);
        }
开发者ID:tallesl,项目名称:net-Object,代码行数:60,代码来源:ObjectDictionaryTests.cs

示例15: ToObject_WhenDictionaryContainsDataWhichCannotBeMatched2_MustThrowInvalidOperationException

        public void ToObject_WhenDictionaryContainsDataWhichCannotBeMatched2_MustThrowInvalidOperationException()
        {
            var dictionary = new Dictionary<string, object> { { "Name", "Marbach" }, { "Street", "Elsewhere" }};

            Assert.Throws<InvalidOperationException>(() => dictionary.ToObject<Input>());
        }
开发者ID:dmetzgar,项目名称:Ninject.Extensions.Wf,代码行数:6,代码来源:IDictionaryExtensionsTest.cs


注:本文中的Dictionary.ToObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。