我有一个类是通过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