本文整理汇总了C#中DynamicDictionaryValue.TryParse方法的典型用法代码示例。如果您正苦于以下问题:C# DynamicDictionaryValue.TryParse方法的具体用法?C# DynamicDictionaryValue.TryParse怎么用?C# DynamicDictionaryValue.TryParse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicDictionaryValue
的用法示例。
在下文中一共展示了DynamicDictionaryValue.TryParse方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_implicitly_convert_from_datetime_based_on_given_type_of_string
public void Should_implicitly_convert_from_datetime_based_on_given_type_of_string()
{
//This test is unrealistic in my opinion, but it should still call ToString on the datetime value
//Given
string expected = DateTime.Parse("22 Nov, 2012").ToString(CultureInfo.InvariantCulture);
string notExpected = DateTime.Parse("18 Jun, 2011").ToString(CultureInfo.InvariantCulture);
dynamic value = new DynamicDictionaryValue(DateTime.Parse("22 Nov, 2012"));
//When
string actual = value.TryParse(notExpected);
//Then
Assert.Equal(expected, actual);
}
示例2: Should_implicitly_convert_from_double_based_on_given_type_of_string
public void Should_implicitly_convert_from_double_based_on_given_type_of_string()
{
//Given
const string expected = "134.22";
const string notExpected = "187.34";
dynamic value = new DynamicDictionaryValue(134.22d);
//When
string actual = value.TryParse(notExpected);
//Then
Assert.Equal(expected, actual);
}
示例3: Should_implicitly_convert_from_decimal_based_on_given_type_of_string
public void Should_implicitly_convert_from_decimal_based_on_given_type_of_string()
{
//Given
const string expected = "88.53234423";
const string notExpected = "76.3422";
dynamic value = new DynamicDictionaryValue(88.53234423m);
//When
string actual = value.TryParse(notExpected);
//Then
Assert.Equal(expected, actual);
}
示例4: Should_implicitly_convert_from_string_based_on_given_generic_type_of_datetime
public void Should_implicitly_convert_from_string_based_on_given_generic_type_of_datetime()
{
//Given
DateTime expected = DateTime.Parse("13 Dec, 2012");
dynamic value = new DynamicDictionaryValue("13 December 2012");
//When
DateTime actual = value.TryParse<DateTime>();
//Then
Assert.Equal(expected, actual);
}
示例5: Should_return_default_value_if_implicit_convert_fails_on_datetime
public void Should_return_default_value_if_implicit_convert_fails_on_datetime()
{
//Given
DateTime expected = DateTime.Parse("13 December 2012");
dynamic value = new DynamicDictionaryValue("Rawrrrr");
//When
DateTime actual = value.TryParse(expected);
//Then
Assert.Equal(expected, actual);
}
示例6: Should_implicitly_convert_from_string_based_on_given_generic_type_of_double
public void Should_implicitly_convert_from_string_based_on_given_generic_type_of_double()
{
//Given
const double expected = 37.48d;
dynamic value = new DynamicDictionaryValue("37.48");
//When
double actual = value.TryParse<double>();
//Then
Assert.Equal(expected, actual);
}
示例7: Should_implicitly_convert_from_string_based_on_given_generic_type_of_short
public void Should_implicitly_convert_from_string_based_on_given_generic_type_of_short()
{
//Given
const short expected = (short)13;
dynamic value = new DynamicDictionaryValue("13");
//When
short actual = value.TryParse<short>();
//Then
Assert.Equal(expected, actual);
}
示例8: Should_implicitly_convert_from_string_based_on_given_generic_type_of_decimal
public void Should_implicitly_convert_from_string_based_on_given_generic_type_of_decimal()
{
//Given
const decimal expected = 55.23m;
dynamic value = new DynamicDictionaryValue("55.23");
//When
decimal actual = value.TryParse<decimal>();
//Then
Assert.Equal(expected, actual);
}
示例9: Should_return_default_when_given_string_that_is_not_a_number
public void Should_return_default_when_given_string_that_is_not_a_number()
{
//Given
const int expected = 100;
dynamic value = new DynamicDictionaryValue("4abc2");
//When
int actual = value.TryParse<int>(expected);
//Then
Assert.Equal(expected, actual);
}
示例10: Should_implicitly_convert_from_string_based_on_given_generic_type_of_int
public void Should_implicitly_convert_from_string_based_on_given_generic_type_of_int()
{
//Given
const int expected = 42;
dynamic value = new DynamicDictionaryValue("42");
//When
int actual = value.TryParse<int>();
//Then
Assert.Equal(expected, actual);
}
示例11: Should_implicitly_convert_from_datetime_based_on_given_parameter_type_of_nullable_datetime
public void Should_implicitly_convert_from_datetime_based_on_given_parameter_type_of_nullable_datetime()
{
//Given
DateTime expected = DateTime.Parse ("13 December 2012");
DateTime? notExpected = expected.AddDays (10);
dynamic value = new DynamicDictionaryValue (expected);
//When
DateTime actual = (DateTime)value.TryParse<DateTime?> (notExpected);
//Then
Assert.Equal (expected, actual);
}
示例12: Should_implicitly_convert_from_int_based_on_given_parameter_type_of_nullable_long
public void Should_implicitly_convert_from_int_based_on_given_parameter_type_of_nullable_long()
{
//Given
const int expected = 42;
long? notExpected = 100;
dynamic value = new DynamicDictionaryValue (expected);
//When
int actual = (int)value.TryParse<long?> (notExpected);
//Then
Assert.Equal (expected, actual);
}