忽略属性二进制序列化 [英] Ignore binary serialization on a property

查看:115
本文介绍了忽略属性二进制序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个常规的C#POCO。在一流水平,我装修的对象与 [序列化()]



这是说,我是使用LINQ的总和()的属性之一,我在系列化收到错误。如果可能的话,我想只是简单地忽略此属性。但是, [XmlIgnore()] 仅用于XML序列化,而不是二进制。 ?任何意见或想法



中的代码是这样的,在这里我想忽略 ValueTotal

  [序列化()] 
公共类Foo
{
公众的IList<数>订购数量{搞定;组; }

众长ValueTotal
{
{返回Nums.Sum(X => x.value); }
}
}


解决方案

欺骗和使用方法

  [序列化()] 
公共类Foo
{
公众的IList<数字与GT;订购数量{搞定;组; }

众长GetValueTotal()
{
返回Nums.Sum(X => x.value);
}
}


I have a regular C# POCO. At the class level, I am decorating the object with [Serializable()].

That said, I am using the Linq Sum() on one of the properties and I am receiving an error upon serialization. If possible, I would like to just simply ignore this property. However, the [XmlIgnore()] is only for Xml Serialization, not Binary. Any ideas or thoughts?

The code is something like this, where I would like to ignore ValueTotal:

[Serializable()]
public class Foo
{
  public IList<Number> Nums { get; set; }

  public long ValueTotal
  {
    get { return Nums.Sum(x => x.value); }
  }
}

解决方案

Cheat and use a method

[Serializable()]
public class Foo
{
  public IList<Number> Nums { get; set; }

  public long GetValueTotal()
  {
    return Nums.Sum(x => x.value);
  }
}

这篇关于忽略属性二进制序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆