防止在VB.NET中序列化属性

时间:2011-07-19 11:30:55

标签: asp.net vb.net web-services serialization asmx

我有一个VB.NET类,我在asmx文件中通过XML序列化。我已经在序列化中添加了我想要忽略的数据库的属性,但它仍然被返回。我的类上还有<DataContract()>属性,应该序列化所有属性的DataMember属性。我的财产声明是:

    <ScriptIgnore()> _
    <IgnoreDataMember()> _
    Public Property Address() As SomeObject

2 个答案:

答案 0 :(得分:11)

通过向支持字段添加属性并将其从自动属性转换,我最终得到了停止序列化的权利:

<NonSerialized()> _
Private _address As SomeObject = Nothing
<ScriptIgnore()> _
<IgnoreDataMember()> _
<Xmlignore()>
Public Property address() As SomeObject
    Get
        Return _address
    End Get
    Set(ByVal value As SomeObject)
        _address = value
    End Set
End Property

答案 1 :(得分:2)

您是否尝试过NonSerialized属性:

<NonSerialized()> _
Public Property Address() As SomeObject

http://msdn.microsoft.com/en-us/library/system.nonserializedattribute.aspx