本文整理匯總了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;
}
}