本文整理汇总了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>();
}
示例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"]);
}
示例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);
}
示例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);
}
示例5: CreateInvalidObjectWithoutValidation
public void CreateInvalidObjectWithoutValidation()
{
var collection = new NameValueCollection
{
{"TestConfigWithAnnotations.Int", "42"},
{"TestConfigWithAnnotations.IsEnabled", "false"},
};
collection.CreateObject<TestConfigWithAnnotations>();
}
示例6: CreateInvalidObject
public void CreateInvalidObject(string value)
{
var collection = new NameValueCollection
{
{"TestConfigWithAnnotations.Int", value},
};
Assert.Throws<ValidationException>(
() =>
{
collection.CreateObject<TestConfigWithAnnotations>();
});
}
示例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]);
}
示例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"]);
}
示例9: CreateInt
public void CreateInt()
{
var collection = new NameValueCollection
{
{"A", "1"},
};
var result = collection.CreateObject<int>("A");
Assert.Equal(1, result);
}