0

我正在寻找一种将 Silverlight 对象持久保存到用户 PC 上的方法,然后对它们进行重新水化,以便用户可以完成对它们的编辑。

序列化DataContractSerializer并坚持IsolatedStorageFile工作正常。但是,反序列化会导致问题。这是导致失败的代码:

private string _FirstNames = string.Empty;
public string FirstNames
{
    get { return _FirstNames; }
    set
    {
        new PersonNameValidator().Validate(value);  //<-- BOOM 8(
        Set(ref _FirstNames, value, () => this.FirstNames);
    }
}

反序列化器调用属性设置器,后者又抛出异常并中止反序列化。

我已经尝试显式应用DataContract//属性DataMemberIgnoreDataMember但是它不能很好地与私有字段一起使用:

System.Security.SecurityException 发生 Message="The data contract type 'Trident.Model.Journey.JourneyApplication' cannot be serialized because the member '_TravellerSavingsAmount' is not public. 将成员设为 public 将修复此错误。或者,您可以将其设为“

如何在反序列化期间绕过属性设置器?

我想让我的课程专注于该领域,而不是受到基础设施问题的污染。

4

1 回答 1

0

几个想法:

  • 序列化仅用于序列化的属性,从而绕过任何验证
  • 序列化父类并使用派生类进行验证
于 2009-09-24T13:53:14.720 回答