XmlSchemaClassGenerator
XmlSchemaClassGenerator copied to clipboard
QUESTION: Generate as XmlCdataSection for primate strings/named properties?
Is there a way to have specified properties, or all primitive strings generate as XMLCdataSections?
Currently, I'm having to generate an additional partial class and remember to add an [XMLIgnore] and match the order in the generated partial class (each time I regenerate), which is a little cumbersome but works.
Any better approaches?
Additional partial
/// <summary>
/// Update the generated code to ignore the default
/// [XmlIgnore] public string summary
/// </summary>
[System.ComponentModel.DataAnnotations.MaxLengthAttribute(1000)]
[System.ComponentModel.DataAnnotations.RequiredAttribute(AllowEmptyStrings=true)]
[System.Xml.Serialization.XmlElementAttribute("summary", Order = 10, Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public XmlCDataSection SummaryCData
{
get
{
var doc = new XmlDocument();
return doc.CreateCDataSection(Summary);
}
set
{
Summary = value?.Value;
}
}
Generated
/// <summary>
/// <para xml:lang="en">Maximum length: 1000.</para>
/// </summary>
[System.ComponentModel.DataAnnotations.MaxLengthAttribute(1000)]
[System.ComponentModel.DataAnnotations.RequiredAttribute(AllowEmptyStrings=true)]
[System.Xml.Serialization.XmlElementAttribute("summary", Order=10, Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
[XmlIgnore]
public string Summary { get; set; }
There is currently no support for this. PRs welcome 😄