我正在从第三方消费大型业务对象。这些对象是通过WSDL和xsd文件提供的,因此我无法更改对象,因为这些对象将通过WCF服务调用返回。
鉴于我无法更改对象,我无法使用DataMember属性注释属性或直接控制这些对象的序列化。
我想解决的问题是这个。如果其中一个业务对象中的日期时间对象的值为DateTime.MinValue,是否可以从XML序列化中排除该数据而不实现完全定制的序列化实现?如果有办法告诉默认的XML序列化程序根据其值忽略对象?
Reference.cs中大型业务对象的一部分示例
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.33440")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://XXXX")]
public partial class DocumentBusinessProperty : object, System.ComponentModel.INotifyPropertyChanged {
private string documentBusinessPropertyNameField;
private string[] documentBusinessPropertyValueField;
private System.DateTime documentBusinessPropertyDateField;
private bool documentBusinessPropertyDateFieldSpecified;
private bool documentBusinessPropertyIndicatorField;
private bool documentBusinessPropertyIndicatorFieldSpecified;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
public string DocumentBusinessPropertyName {
get {
return this.documentBusinessPropertyNameField;
}
set {
this.documentBusinessPropertyNameField = value;
this.RaisePropertyChanged("DocumentBusinessPropertyName");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("DocumentBusinessPropertyValue", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
public string[] DocumentBusinessPropertyValue {
get {
return this.documentBusinessPropertyValueField;
}
set {
this.documentBusinessPropertyValueField = value;
this.RaisePropertyChanged("DocumentBusinessPropertyValue");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType="date", Order=2)]
public System.DateTime DocumentBusinessPropertyDate {
get {
return this.documentBusinessPropertyDateField;
}
set {
this.documentBusinessPropertyDateField = value;
this.RaisePropertyChanged("DocumentBusinessPropertyDate");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool DocumentBusinessPropertyDateSpecified {
get {
return this.documentBusinessPropertyDateFieldSpecified;
}
set {
this.documentBusinessPropertyDateFieldSpecified = value;
this.RaisePropertyChanged("DocumentBusinessPropertyDateSpecified");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
public bool DocumentBusinessPropertyIndicator {
get {
return this.documentBusinessPropertyIndicatorField;
}
set {
this.documentBusinessPropertyIndicatorField = value;
this.RaisePropertyChanged("DocumentBusinessPropertyIndicator");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool DocumentBusinessPropertyIndicatorSpecified {
get {
return this.documentBusinessPropertyIndicatorFieldSpecified;
}
set {
this.documentBusinessPropertyIndicatorFieldSpecified = value;
this.RaisePropertyChanged("DocumentBusinessPropertyIndicatorSpecified");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}