public LiteralAttributes(MemberInfo memberInfo, XmlAttributes xmlAtts) :
            this(memberInfo)
        {
            if (xmlAtts == null)
            {
                return;
            }

            Ignore = xmlAtts.XmlIgnore;
            if (!Ignore)
            {
                XmlChoiceIdentifier = xmlAtts.XmlChoiceIdentifier;
                XmlAttribute        = xmlAtts.XmlAttribute;
                XmlArray            = xmlAtts.XmlArray;
                XmlText             = xmlAtts.XmlText;
                XmlEnum             = xmlAtts.XmlEnum;
                DefaultValue        = (xmlAtts.XmlDefaultValue == null) ?
                                      null :
                                      new DefaultValueAttribute(xmlAtts.XmlDefaultValue);

                Xmlns = xmlAtts.Xmlns;
                if (Xmlns)
                {
                    object[] attrs = memberInfo.GetCustomAttributes(s_nsDeclType, false).ToArray();
                    XmlNamespaceDeclaration = (XmlNamespaceDeclarationsAttribute)(attrs.Length > 0 ? attrs[0] : null);
                }
                else
                {
                    XmlNamespaceDeclaration = null;
                }

                // Use if statements here so that the XmlElements collection populated by reflection
                // is eliminated only if the app developer has provided substitute XmlElementAttribute's.
                // Ditto for the XmlArrayItems and XmlAnyElements.
                if (xmlAtts.XmlElements.Count > 0)
                {
                    XmlElements = xmlAtts.XmlElements;
                }

                if (xmlAtts.XmlArrayItems.Count > 0)
                {
                    XmlArrayItems = xmlAtts.XmlArrayItems;
                }

                XmlAnyAttribute = xmlAtts.XmlAnyAttribute;

                if (xmlAtts.XmlAnyElements.Count > 0)
                {
                    XmlAnyElements = xmlAtts.XmlAnyElements;
                }
            }
        }
Example #2
0
 private static void AddXmlAnyElementsPrint(XmlAnyElementAttributes atts, StringBuilder printBuilder)
 {
     if (null != atts)
     {
         foreach (XmlAnyElementAttribute att in atts)
         {
             printBuilder.Append("anyatt");
             printBuilder.Append("/");
             printBuilder.Append(att.Name);
             printBuilder.Append("/");
             printBuilder.Append(att.Namespace);
             printBuilder.Append("::");
         }
     }
     printBuilder.Append("%%");
 }
 public LiteralAttributes(MemberInfo memberInfo)
 {
     foreach (object attr in memberInfo.GetCustomAttributes(false))
     {
         Type type = attr.GetType();
         if (type == s_ignoreType)
         {
             Debug.Assert(false == Ignore, "Too many ignores");
             Ignore = true;
         }
         else if (type == s_choiceType)
         {
             Debug.Assert(XmlChoiceIdentifier == null, "Too many XCIA");
             XmlChoiceIdentifier = (XmlChoiceIdentifierAttribute)attr;
         }
         else if (type == s_elementType)
         {
             if (XmlElements == null)
             {
                 XmlElements = new XmlElementAttributes();
             }
             XmlElements.Add((XmlElementAttribute)attr);
         }
         else if (type == s_attributeType)
         {
             Debug.Assert(XmlAttribute == null, "Too many XAAs");
             XmlAttribute = (XmlAttributeAttribute)attr;
         }
         else if (type == s_arrayType)
         {
             Debug.Assert(XmlArray == null, "Too many XAAs");
             XmlArray = (XmlArrayAttribute)attr;
         }
         else if (type == s_arrayItemType)
         {
             if (XmlArrayItems == null)
             {
                 XmlArrayItems = new XmlArrayItemAttributes();
             }
             XmlArrayItems.Add((XmlArrayItemAttribute)attr);
         }
         else if (type == s_nsDeclType)
         {
             Debug.Assert(XmlNamespaceDeclaration == null, "Too many XNDAs");
             XmlNamespaceDeclaration = (XmlNamespaceDeclarationsAttribute)attr;
             Xmlns = true;
         }
         else if (type == s_textType)
         {
             Debug.Assert(XmlText == null, "Too many XTAs");
             XmlText = (XmlTextAttribute)attr;
         }
         else if (type == s_anyAttrType)
         {
             Debug.Assert(XmlAnyAttribute == null, "Too many XAAAs");
             XmlAnyAttribute = (XmlAnyAttributeAttribute)attr;
         }
         else if (type == s_anyEltType)
         {
             if (XmlAnyElements == null)
             {
                 XmlAnyElements = new XmlAnyElementAttributes();
             }
             XmlAnyElements.Add((XmlAnyElementAttribute)attr);
         }
         else if (type == s_enumType)
         {
             XmlEnum = (XmlEnumAttribute)attr;
         }
         else
         {
             base.processAttribute(attr);
         }
     }
 }