2011-07-19 10 views
4

私はasmxファイルでXML経由でシリアライズしているVB.NETクラスを持っています。私はシリアル化で無視したいdatamemberに属性を追加しましたが、まだ返されています。私のクラスには<DataContract()>属性があり、すべてのプロパティのDataMember属性はシリアル化する必要があります。私のプロパティの宣言は次のとおりです。私は最終的には、バッキングフィールドに属性を追加すると自動プロパティから、それを変換することでVB.NETでのプロパティのシリアル化の防止

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

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

答えて

9

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

あなたが必要とするのは、だと思います。 – John

+0

[XmlIgnore]は、オブジェクトがasmxページから返されたときにフィールドのシリアル化を停止しました。 – Nick

2

あなたはNonSerialized属性を試してみましたシリアル化を中止するproprtyを得た:

<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 
+0

残念ながら、これは与える: 属性がこの宣言型で有効でないため、属性 'NonSerializedAttribute'を 'Address'に適用できません。 – Echilon

+0

プロパティを変更する必要があります。自動的に実装されないようにプロパティを変更し、バッキングストアにその属性を置きます。私はそれが事実であるとは思わなかった。ここにそれを説明する質問へのリンクがあります。 http://stackoverflow.com/questions/1728367/how-to-prevent-auto-implemented-properties-from-being-serialized – Jay

関連する問題