Skip to content

QUESTION: Generate as XmlCdataSection for primate strings/named properties? #547

Open

Description

@mistyn8

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; }

Activity

  1. mganss commented on Mar 6, 2025

    @mganss
    Owner

    There is currently no support for this. PRs welcome 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions