本文整理汇总了C#中Binder.BindTo1方法的典型用法代码示例。如果您正苦于以下问题:C# Binder.BindTo1方法的具体用法?C# Binder.BindTo1怎么用?C# Binder.BindTo1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Binder
的用法示例。
在下文中一共展示了Binder.BindTo1方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: can_bind1_to_string_int_and_bool
public void can_bind1_to_string_int_and_bool()
{
var binder = new Binder();
var pairs = new KeyValuePair<string, string>[]
{
new KeyValuePair<string,string> ("TheInteger", "2"),
new KeyValuePair<string, string>("TheString","123"),
new KeyValuePair<string, string>("TheFlag","true")
};
var a = binder.BindTo1<A>(pairs);
Assert.AreEqual(2, a.TheInteger);
Assert.AreEqual("123", a.TheString);
Assert.AreEqual(true, a.TheFlag);
}
示例2: bind1_when_member_has_invalid_type_throws_exception
public void bind1_when_member_has_invalid_type_throws_exception()
{
var binder = new Binder();
var pairs = new KeyValuePair<string, string>[]
{
new KeyValuePair<string,string> ("AnInteger", "2"),
new KeyValuePair<string, string>("AString","123"),
new KeyValuePair<string, string>("ThePoint","1,2")
};
try
{
var b = binder.BindTo1<B>(pairs);
}
catch (InvalidMemberTypeException ex)
{
Assert.AreEqual(typeof(B).GetField("ThePoint"), ex.MemberInfo);
Assert.AreEqual(typeof(B).GetField("ThePoint").FieldType, ex.MemberType);
throw ex;
}
}