私はこのようなクラスを持っています:
[Serializable]
public class Structure
{
#region Constants and Fields
/// <summary>
/// The description.
/// </summary>
private string description;
#endregion
/// <summary>
/// Gets or sets the Description of the subclass i.e subtype of structure
/// </summary>
public string Description
{
get
{
return this.description;
}
set
{
this.description = value;
}
}
}
以下のような別のクラスは、上記のクラスを継承します。
[XmlRoot(Namespace = "TestNamespace", ElementName = "OrgStructure")]
public class OrgStructure : Structure
{
private long orgDeptID;
/// <summary>
/// The description
/// </summary>
private string description;
public long OrgDeptID
{
get
{
return this.orgDeptID;
}
set
{
this.orgDeptID= value;
}
}
}
ASMX サービスを WCF に移行して、既存の ASMX クライアントとの互換性を維持しています。したがって、のXmlSerializer
代わりにを使用する必要がありDataContractSerializer
ます。
は、 の応答タイプの ようにOrgStructure
宣言されます。MessageBodyMember
OperationContract
ASMX クライアントは、XML メッセージ内の を想定していません。Description
そこで、派生クラスnew
のプロパティを(演算子を使用して)非表示にして、それに適用しようとしました。それでも、このプロパティをシリアル化します。Description
XmlIgnoreAttribute
(変数の宣言に注意してください。開発者が、基底クラス自体description
に保持するのではなく、派生クラスを再度宣言した理由はわかりません。)protected
XmlSerializer を使用しているときに、派生クラスで基本クラスのプロパティを無視するにはどうすればよいですか? Structure
他のサブタイプがそれを必要とするため、基本クラスでそれを無視することはできません。