XmlAttribute(Form="Qualified") causes error on string(s)

Dec 5, 2010 at 1:52 PM

When running the code generator with GenerateXmlAttributes turned on  the attributes of type string where generating a compile error requiring a 'new' for non-static entities.  Which is unusual in its self.  So I was able to narrow it down to the attribute field:  Form = Qualified.  if removed it will compile, if not I get the exception.   Below is the changes I've made locally, I hope this helps.  Please use as you see fit.

Thank You

-Thomas

 GeneratorParams.cs:  @ Line 197:  Added:

        /// <summary>
        /// Gets or sets a value indicating wheter the Attribute field "Form" should be removed from Members.
        /// </summary>
        [Category("Serialize")]
        [DefaultValue(false)]
        [Description("Indicating whether if generate will remove Form=Qualified")]
        public bool RemoveFormQualified { get; set; } 
CodeExtension.cs:  @ Line 147:  Added:
        if (GeneratorContext.GeneratorParams.Serialization.RemoveFormQualified)
        {
           foreach(CodeTypeMember ctm in type.Members)
{ this.RemoveFormQualified(ctm.CustomAttributes);
} }
CodeExtension.cs:  @ Line 2064:  Added:
        /// <summary>
        /// Removes the Form="Qualified" XML Attribute Attribute
        /// </summary>
        /// <param name="customAttributes">
        /// The custom Attributes
        /// </param>
        protected virtual void RemoveFormQualified(CodeAttributeDeclarationCollection customAttributes)
        {
            var codeAttributes = new List<CodeAttributeDeclaration>();
            CodeAttributeDeclaration deleteCAA = null;
            foreach (var attribute in customAttributes)
            {
                var attrib = attribute as CodeAttributeDeclaration;
                if (attrib == null) 
                { 
                    continue; 
                }
                if (attrib.Name == "System.Xml.Serialization.XmlAttributeAttribute")
                {
                    foreach (CodeAttributeArgument caa in attrib.Arguments)
                    {
                        if (caa.Name == "Form" && ((System.CodeDom.CodeFieldReferenceExpression)(caa.Value)).FieldName == "Qualified")
                        {
                            deleteCAA = attrib;
                            break;
                        }
                    }
                }
                if (deleteCAA != null)
                {
                    break;
                }
            }
            if (deleteCAA != null) customAttributes.Remove(deleteCAA);
        }