我有一個類是通過wsdl.exe自動生成的,我需要將[System.Xml.Serialization.XmlIgnoreAttribute()]屬性添加到其中一個屬性,但我無法直接將該類修改爲它不時再生。添加C#屬性到wsdl.exe生成的屬性?
有沒有辦法做到這一點?我已經嘗試尋找繼承,部分類和反射的解決方案,但沒有運氣。 由於客戶的限制,我堅持使用.NET Framework 2.0。
(爲什麼我需要在這裏做的更多細節:Prevent timezone conversion on deserialization of DateTime value,我將在部分類的字符串屬性)
編輯:請求的代碼段是一個簡單的,因爲這:
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://common.ws.model.plx.ids.it/")]
public partial class publication {
private System.DateTime dateFromField;
//[System.Xml.Serialization.XmlIgnoreAttribute()] I would like to add this
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public System.DateTime dateFrom {
get {
return this.dateFromField;
}
set {
this.dateFromField = value;
}
}
///// This method has been moved in the other partial class
//[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, ElementName = "dateFrom")]
//public string dateFromString
//{
// get
// {
// return XmlConvert.ToString(dateFrom, XmlDateTimeSerializationMode.RoundtripKind);
// }
// set
// {
// dateFrom = DateTimeOffset.Parse(value).DateTime;
// }
//}
}
爲什麼繼承在這種情況下不起作用?你看了作文嗎?請提供您的WSDL類的縮寫片段以及您想要設置屬性的屬性。 – 2013-03-13 14:40:08
我認爲http://stackoverflow.com/questions/10174519/how-can-i-use-attributes-on-a-property-defined-in-the-other-half-of-a-partial-cl回答你的問題題。它使用MetadataType。 – 2013-03-13 14:42:42
繼承將無法工作,因爲該對象是由服務調用實例化的,所以我仍然會得到基類。 – capitano666 2013-03-13 14:44:24