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


C# NameValueCollection.CreateObject方法代码示例

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


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

示例1: CreateValidObject

        public void CreateValidObject(string value)
        {
            var collection = new NameValueCollection
            {
                {"TestConfigWithAnnotations.Int", value},
            };

            collection.CreateObject<TestConfigWithAnnotations>();
        }
开发者ID:tdupont750,项目名称:ConfigurationExtensions,代码行数:9,代码来源:NameValueCollectionExtensionsTests.cs

示例2: CreateComplexObject

        public void CreateComplexObject()
        {
            var collection = new NameValueCollection
            {
                {"TestConfig.Test.Int", "3"},
                {"TestConfig.ListOfInt[0]", "4"},
                {"TestConfig.ListOfInt[1]", "5"},
                {"TestConfig.ListOfTestConfig[2].Int", "6"},
                {"TestConfig.ListOfTestConfig[2].String", "Arg"},
                {"TestConfig.ListOfTestConfig[1].Int", "7"},
                {"TestConfig.MapOfInt[Hello]", "8"},
                {"TestConfig.MapOfInt[World]", "9"},
            };

            var result = collection.CreateObject<TestConfig>();

            Assert.NotNull(result);

            Assert.NotNull(result.Test);
            Assert.Equal(3, result.Test.Int);

            Assert.NotNull(result.ListOfInt);
            Assert.Equal(2, result.ListOfInt.Count);
            Assert.Equal(4, result.ListOfInt[0]);
            Assert.Equal(5, result.ListOfInt[1]);

            Assert.NotNull(result.ListOfTestConfig);
            Assert.Equal(2, result.ListOfTestConfig.Count);
            Assert.NotNull(result.ListOfTestConfig[0]);
            Assert.Equal(7, result.ListOfTestConfig[0].Int);
            Assert.NotNull(result.ListOfTestConfig[1]);
            Assert.Equal(6, result.ListOfTestConfig[1].Int);
            Assert.Equal("Arg", result.ListOfTestConfig[1].String);

            Assert.NotNull(result.MapOfInt);
            Assert.Equal(2, result.MapOfInt.Count);
            Assert.Equal(8, result.MapOfInt["Hello"]);
            Assert.Equal(9, result.MapOfInt["World"]);
        }
开发者ID:tdupont750,项目名称:ConfigurationExtensions,代码行数:39,代码来源:NameValueCollectionExtensionsTests.cs

示例3: CreateObjectDictionary

        public void CreateObjectDictionary()
        {
            var collection = new NameValueCollection
            {
                {"A[A].Int", "1"},
                {"Something", "Else"},
                {"A[BB].String", "Hello"},
                {"A[CCC].Enum", "Goodnight"},
            };

            var result = collection.CreateObject<Dictionary<string, TestConfig>>("A");

            Assert.NotNull(result);
            Assert.Equal(3, result.Count);
            Assert.Equal(1, result["A"].Int);
            Assert.Equal("Hello", result["BB"].String);
            Assert.Equal(TestEnum.Goodnight, result["CCC"].Enum);
        }
开发者ID:tdupont750,项目名称:ConfigurationExtensions,代码行数:18,代码来源:NameValueCollectionExtensionsTests.cs

示例4: CreateObjectList

        public void CreateObjectList()
        {
            var collection = new NameValueCollection
            {
                {"Something", "Else"},
                {"TestConfig.ListOfTestConfig[2].Int", "6"},
                {"TestConfig.ListOfTestConfig[2].String", "Arg"},
                {"TestConfig.ListOfTestConfig[1].Int", "7"},
            };

            var result = collection.CreateObject<TestConfig>();

            Assert.NotNull(result);
            Assert.NotNull(result.ListOfTestConfig);
            Assert.Equal(2, result.ListOfTestConfig.Count);
            Assert.NotNull(result.ListOfTestConfig[0]);
            Assert.Equal(7, result.ListOfTestConfig[0].Int);
            Assert.NotNull(result.ListOfTestConfig[1]);
            Assert.Equal(6, result.ListOfTestConfig[1].Int);
            Assert.Equal("Arg", result.ListOfTestConfig[1].String);
        }
开发者ID:tdupont750,项目名称:ConfigurationExtensions,代码行数:21,代码来源:NameValueCollectionExtensionsTests.cs

示例5: CreateInvalidObjectWithoutValidation

        public void CreateInvalidObjectWithoutValidation()
        {
            var collection = new NameValueCollection
            {
                {"TestConfigWithAnnotations.Int", "42"},
                {"TestConfigWithAnnotations.IsEnabled", "false"},
            };

            collection.CreateObject<TestConfigWithAnnotations>();
        }
开发者ID:tdupont750,项目名称:ConfigurationExtensions,代码行数:10,代码来源:NameValueCollectionExtensionsTests.cs

示例6: CreateInvalidObject

        public void CreateInvalidObject(string value)
        {
            var collection = new NameValueCollection
            {
                {"TestConfigWithAnnotations.Int", value},
            };

            Assert.Throws<ValidationException>(
                () =>
                {
                    collection.CreateObject<TestConfigWithAnnotations>();
                });
        }
开发者ID:tdupont750,项目名称:ConfigurationExtensions,代码行数:13,代码来源:NameValueCollectionExtensionsTests.cs

示例7: CreateIntList

        public void CreateIntList()
        {
            var collection = new NameValueCollection
            {
                {"A[1]", "1"},
                {"A[2]", "2"},
                {"Something", "Else"},
                {"A[4]", "4"},
            };

            var result = collection.CreateObject<List<int>>("A");

            Assert.NotNull(result);
            Assert.Equal(3, result.Count);
            Assert.Equal(1, result[0]);
            Assert.Equal(2, result[1]);
            Assert.Equal(4, result[2]);
        }
开发者ID:tdupont750,项目名称:ConfigurationExtensions,代码行数:18,代码来源:NameValueCollectionExtensionsTests.cs

示例8: CreateIntDictionary

        public void CreateIntDictionary()
        {
            var collection = new NameValueCollection
            {
                {"A[A]", "1"},
                {"Something", "Else"},
                {"A[BB]", "22"},
                {"A[CCC]", "333"},
            };

            var result = collection.CreateObject<Dictionary<string, int>>("A");

            Assert.NotNull(result);
            Assert.Equal(3, result.Count);
            Assert.Equal(1, result["A"]);
            Assert.Equal(22, result["BB"]);
            Assert.Equal(333, result["CCC"]);
        }
开发者ID:tdupont750,项目名称:ConfigurationExtensions,代码行数:18,代码来源:NameValueCollectionExtensionsTests.cs

示例9: CreateInt

        public void CreateInt()
        {
            var collection = new NameValueCollection
            {
                {"A", "1"},
            };

            var result = collection.CreateObject<int>("A");
            Assert.Equal(1, result);
        }
开发者ID:tdupont750,项目名称:ConfigurationExtensions,代码行数:10,代码来源:NameValueCollectionExtensionsTests.cs


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