文字列にシリアライズ可能なリスト クラスを作成できます。
テストされていない例:
public class AddressList : IList<IPAdress>
{
public string Serialized { get; private set; }
private List<IPAddress> _innerList = new List<IPAddress>();
//To be informed when the list is modified.
public event EventHandler OnModified;
public AddressList(string serializedString)
{
//Init the collection from the serialized string
}
public void Add(IPAdress item)
{
_innerList.Add(item)
//Update the serialized string
UpdateString();
}
public void Remove(IPAdress item)
{
_innerList.Remove(item);
//Update the serialized string
UpdateString();
}
private void UpdateString()
{
//Do your update job.
//Call the event.
if (OnModified != null)
OnModified(this, EventArgs.Empty);
}
//Rest of IList implementation....
}
次に、あなたのエンティティで:
public partial class MyEntity
{
private AddressList _addresses;
public IList<IPAdress> Adresses
{
get
{
if (_addresses == null)
{
_addresses = new AddressList(HostList);
//When the list is modified, you want to update your property.
_addresses.OnModified += delegate(object sender, EventArgs e)
{
HostList = ((AddressList) sender).Serialized;
};
}
return _adresses;
}
}
}
このようにして、リストにアイテムを追加/削除すると、文字列が「自動的に」更新されます。