我需要翻译两个DTO类:
public class AddressDto
{
public string Street { get; set; }
public string City { get; set; }
public string PostCode { get: set: }
}
public class CustomerDto
{
public int Number{ get; set; }
public string Name { get; set; }
public AddressDto Address { get: set: }
public CustomerDto()
{
Address = new AddressDto();
}
}
我有一个带绑定源的表单,它绑定到CustomerDto
。我还有一个具有地址字段的自定义控件。这个自定义控件有一个绑定源,绑定到AddressDto
。控件的文本框正确地绑定到地址属性。
该控件公开了以下属性:
[Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
[Browsable(false)]
public object Address
{
get { return bindingSource.DataSource; }
set { bindingSource.DataSource = value; }
}
在一台机器上,
CheckBinding()
没有出现任何错误。然而,在另一台机器上,在运行时尝试打开表单时,会出现上述异常。在设计时,一切都正常。该控件有 3 个
TextBoxes
,设计师添加了以下绑定:this.bindingSource.AllowNew = true;
this.bindingSource.DataSource = typeof(AddressDto);
this.txtStreet.DataBindings.Add(new Binding("Text", this.bindingSource, "Street", true));
this.txtCity.DataBindings.Add(new Binding("Text", this.bindingSource, "City", true));
this.txtPostCode.DataBindings.Add(new Binding("Text", this.bindingSource, "PostCode", true));
有任何想法,问题可能出在哪里?