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