本文整理汇总了C#中System.Collections.Specialized.NameValueCollection.ToObject方法的典型用法代码示例。如果您正苦于以下问题:C# NameValueCollection.ToObject方法的具体用法?C# NameValueCollection.ToObject怎么用?C# NameValueCollection.ToObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Specialized.NameValueCollection
的用法示例。
在下文中一共展示了NameValueCollection.ToObject方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MissingProperty
public void MissingProperty()
{
// Arrange
var appSettings = new NameValueCollection(ConfigurationManager.AppSettings);
appSettings.Add("Extra property", "whatever");
// Act
var actual = appSettings.ToObject<FlatData>();
}
示例2: MissingPropertySafe
public void MissingPropertySafe()
{
// Arrange
var appSettings = new NameValueCollection(ConfigurationManager.AppSettings);
appSettings.Add("Extra property", "whatever");
var expected = new FlatData
{
Id = new Guid("366f4bd3-6717-4b14-9c79-70515296df7e"),
Date = new DateTime(1999, 1, 1),
Enum = Enumeration.Two,
Text = "level 1",
};
// Act
var actual = appSettings.ToObject<FlatData>();
// Assert
Assert.AreEqual(expected.Id, actual.Id);
Assert.AreEqual(expected.Date, actual.Date);
Assert.AreEqual(expected.Enum, actual.Enum);
Assert.AreEqual(expected.Text, actual.Text);
}
示例3: MissingValue
public void MissingValue()
{
// Arrange
var appSettings = new NameValueCollection(ConfigurationManager.AppSettings);
appSettings.Remove("Text");
// Act
var actual = appSettings.ToObject<FlatData>();
}
示例4: Single
public void Single()
{
// Arrange
var expected = new SingleData { Id = new Guid("366f4bd3-6717-4b14-9c79-70515296df7e") };
var appSettings = new NameValueCollection(ConfigurationManager.AppSettings);
appSettings.Remove("Date");
appSettings.Remove("Enum");
appSettings.Remove("Text");
appSettings.Remove("Array");
// Act
var actual = appSettings.ToObject<SingleData>();
// Assert
Assert.AreEqual(expected.Id, actual.Id);
}