问题
Nullable value with xsd.exe generated class answers why the generated class has a *Specified field and property, and how it's used for serializing an XML file, but how am I able to set this value during deserialization?
I have a generated class as defined below:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.33440")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.caiso.com/soa/2006-06-13/StandardOutput.xsd")]
public partial class EventLog {
private System.DateTime creationTimeField;
private bool creationTimeFieldSpecified;
/// <remarks/>
public System.DateTime creationTime {
get {
return this.creationTimeField;
}
set {
this.creationTimeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool creationTimeSpecified {
get {
return this.creationTimeFieldSpecified;
}
set {
this.creationTimeFieldSpecified = value;
}
}
}
You can see that this.creationTimeFieldSpecified;
is not set in the setter of creationTime
. How then, using xsd.exe, can I generate a class such that I can deserialize an XML, and check whether the value is supplied or not?
I am aware of other tools: xsd2code, wscfblue, XmlSchemaClassGenerator, etc; but with each release or update of Visual Studio, it's possible something changed, or the Add-In isn't supported. I would like to know if there is a way to generate the class such that deserialization can take advantage of these properties.
Dislaimer:
I do not have access to change the xsd, they can be updated at any time for any reason requiring a re-generation of the classes, and the resultant class can be many thousands of lines long, manual intervention is not-desired.
来源:https://stackoverflow.com/questions/32610770/deserialization-of-nullable-value-with-xsd-exe-generated-class