【问题标题】:Serializing Supporting Classes VB.NET序列化支持类 VB.NET
【发布时间】:2013-06-20 14:11:01
【问题描述】:

我开始在.NET 框架中了解serialization,但无法找到您应该为返回自定义集合或自定义类对象的属性做什么。在下面的示例中,我的 Items 属性返回自定义集合。我是否还需要向该类添加“datacontract”属性?

如果任何属性返回自定义类类型,还要稍微改变它,那么您必须用datacontract 标记所有这些类(如果它们有属性,则标记为datamember)?

<DataContract()> Public NotInheritable Class MyMainClass
Private pFilters As MyCustomClass

<DataMember()> Public ReadOnly Property Items As MyCustomCollection
    Get
        Return pFilters
    End Get
End Property

Public Class MyCustomCollection
    'Stuff in here
End Class
End Class

【问题讨论】:

    标签: .net vb.net serialization


    【解决方案1】:

    “列表”和“其他所有内容”之间通常存在很大的区别。列表通常通过 IList(-of-T, optional) 和 IEnumerable(-of-T, optional) API 循环遍历其中的项目来处理。所以不,列表通常不需要特殊标记只要它们显然是列表。然而,域实体(“其他一切”)通常确实需要理解 - 意思是“是的,它需要属性”。

    【讨论】:

      猜你喜欢
      • 2019-10-07
      • 2015-06-16
      • 1970-01-01
      • 2014-06-30
      • 1970-01-01
      • 2014-10-28
      • 1970-01-01
      • 2018-08-09
      • 2014-01-23
      相关资源
      最近更新 更多