Exemplo n.º 1
0
        internal static void LoadXmlFormatExtensions(Type[] extensionTypes, XmlAttributeOverrides overrides, XmlSerializerNamespaces namespaces)
        {
            Hashtable table = new Hashtable();

            foreach (Type extensionType in extensionTypes)
            {
                object[] attrs = extensionType.GetCustomAttributes(typeof(XmlFormatExtensionAttribute), false);
                if (attrs.Length == 0)
                {
                    throw new ArgumentException(Res.GetString(Res.RequiredXmlFormatExtensionAttributeIsMissing1, extensionType.FullName), "extensionTypes");
                }
                XmlFormatExtensionAttribute extensionAttr = (XmlFormatExtensionAttribute)attrs[0];
                foreach (Type extensionPointType in extensionAttr.ExtensionPoints)
                {
                    XmlAttributes xmlAttrs = (XmlAttributes)table[extensionPointType];
                    if (xmlAttrs == null)
                    {
                        xmlAttrs = new XmlAttributes();
                        table.Add(extensionPointType, xmlAttrs);
                    }
                    XmlElementAttribute xmlAttr = new XmlElementAttribute(extensionAttr.ElementName, extensionType);
                    xmlAttr.Namespace = extensionAttr.Namespace;
                    xmlAttrs.XmlElements.Add(xmlAttr);
                }
                attrs = extensionType.GetCustomAttributes(typeof(XmlFormatExtensionPrefixAttribute), false);
                string[]  prefixes = new string[attrs.Length];
                Hashtable nsDefs   = new Hashtable();
                for (int i = 0; i < attrs.Length; i++)
                {
                    XmlFormatExtensionPrefixAttribute prefixAttr = (XmlFormatExtensionPrefixAttribute)attrs[i];
                    prefixes[i] = prefixAttr.Prefix;
                    nsDefs.Add(prefixAttr.Prefix, prefixAttr.Namespace);
                }
                Array.Sort(prefixes, InvariantComparer.Default);
                for (int i = 0; i < prefixes.Length; i++)
                {
                    namespaces.Add(prefixes[i], (string)nsDefs[prefixes[i]]);
                }
            }
            foreach (Type extensionPointType in table.Keys)
            {
                XmlFormatExtensionPointAttribute attr = GetExtensionPointAttribute(extensionPointType);
                XmlAttributes xmlAttrs = (XmlAttributes)table[extensionPointType];
                if (attr.AllowElements)
                {
                    xmlAttrs.XmlAnyElements.Add(new XmlAnyElementAttribute());
                }
                overrides.Add(extensionPointType, attr.MemberName, xmlAttrs);
            }
        }
Exemplo n.º 2
0
        internal static void LoadXmlFormatExtensions(Type[] extensionTypes, XmlAttributeOverrides overrides, XmlSerializerNamespaces namespaces)
        {
            Hashtable table = new Hashtable();

            table.Add(typeof(ServiceDescription), new XmlAttributes());
            table.Add(typeof(Import), new XmlAttributes());
            table.Add(typeof(Port), new XmlAttributes());
            table.Add(typeof(Service), new XmlAttributes());
            table.Add(typeof(FaultBinding), new XmlAttributes());
            table.Add(typeof(InputBinding), new XmlAttributes());
            table.Add(typeof(OutputBinding), new XmlAttributes());
            table.Add(typeof(OperationBinding), new XmlAttributes());
            table.Add(typeof(Binding), new XmlAttributes());
            table.Add(typeof(OperationFault), new XmlAttributes());
            table.Add(typeof(OperationInput), new XmlAttributes());
            table.Add(typeof(OperationOutput), new XmlAttributes());
            table.Add(typeof(Operation), new XmlAttributes());
            table.Add(typeof(PortType), new XmlAttributes());
            table.Add(typeof(Message), new XmlAttributes());
            table.Add(typeof(MessagePart), new XmlAttributes());
            table.Add(typeof(Types), new XmlAttributes());
            Hashtable extensions = new Hashtable();

            foreach (Type extensionType in extensionTypes)
            {
                if (extensions[extensionType] != null)
                {
                    continue;
                }
                extensions.Add(extensionType, extensionType);
                object[] attrs = extensionType.GetCustomAttributes(typeof(XmlFormatExtensionAttribute), false);
                if (attrs.Length == 0)
                {
                    throw new ArgumentException(SR.Format(SR.RequiredXmlFormatExtensionAttributeIsMissing1, extensionType.FullName), nameof(extensionTypes));
                }
                XmlFormatExtensionAttribute extensionAttr = (XmlFormatExtensionAttribute)attrs[0];
                foreach (Type extensionPointType in extensionAttr.ExtensionPoints)
                {
                    XmlAttributes xmlAttrs = (XmlAttributes)table[extensionPointType];
                    if (xmlAttrs == null)
                    {
                        xmlAttrs = new XmlAttributes();
                        table.Add(extensionPointType, xmlAttrs);
                    }
                    XmlElementAttribute xmlAttr = new XmlElementAttribute(extensionAttr.ElementName, extensionType);
                    xmlAttr.Namespace = extensionAttr.Namespace;
                    xmlAttrs.XmlElements.Add(xmlAttr);
                }
                attrs = extensionType.GetCustomAttributes(typeof(XmlFormatExtensionPrefixAttribute), false);
                string[]  prefixes = new string[attrs.Length];
                Hashtable nsDefs   = new Hashtable();
                for (int i = 0; i < attrs.Length; i++)
                {
                    XmlFormatExtensionPrefixAttribute prefixAttr = (XmlFormatExtensionPrefixAttribute)attrs[i];
                    prefixes[i] = prefixAttr.Prefix;
                    nsDefs.Add(prefixAttr.Prefix, prefixAttr.Namespace);
                }
                Array.Sort(prefixes, InvariantComparer.Default);
                for (int i = 0; i < prefixes.Length; i++)
                {
                    namespaces.Add(prefixes[i], (string)nsDefs[prefixes[i]]);
                }
            }
            foreach (Type extensionPointType in table.Keys)
            {
                XmlFormatExtensionPointAttribute attr = GetExtensionPointAttribute(extensionPointType);
                XmlAttributes xmlAttrs = (XmlAttributes)table[extensionPointType];
                if (attr.AllowElements)
                {
                    xmlAttrs.XmlAnyElements.Add(new XmlAnyElementAttribute());
                }
                overrides.Add(extensionPointType, attr.MemberName, xmlAttrs);
            }
        }
        internal static void LoadXmlFormatExtensions(Type[] extensionTypes, XmlAttributeOverrides overrides, XmlSerializerNamespaces namespaces)
        {
            Hashtable hashtable = new Hashtable();

            hashtable.Add(typeof(ServiceDescription), new XmlAttributes());
            hashtable.Add(typeof(Import), new XmlAttributes());
            hashtable.Add(typeof(Port), new XmlAttributes());
            hashtable.Add(typeof(Service), new XmlAttributes());
            hashtable.Add(typeof(FaultBinding), new XmlAttributes());
            hashtable.Add(typeof(InputBinding), new XmlAttributes());
            hashtable.Add(typeof(OutputBinding), new XmlAttributes());
            hashtable.Add(typeof(OperationBinding), new XmlAttributes());
            hashtable.Add(typeof(Binding), new XmlAttributes());
            hashtable.Add(typeof(OperationFault), new XmlAttributes());
            hashtable.Add(typeof(OperationInput), new XmlAttributes());
            hashtable.Add(typeof(OperationOutput), new XmlAttributes());
            hashtable.Add(typeof(Operation), new XmlAttributes());
            hashtable.Add(typeof(PortType), new XmlAttributes());
            hashtable.Add(typeof(Message), new XmlAttributes());
            hashtable.Add(typeof(MessagePart), new XmlAttributes());
            hashtable.Add(typeof(Types), new XmlAttributes());
            Hashtable hashtable2 = new Hashtable();

            foreach (Type type in extensionTypes)
            {
                if (hashtable2[type] == null)
                {
                    hashtable2.Add(type, type);
                    object[] customAttributes = type.GetCustomAttributes(typeof(XmlFormatExtensionAttribute), false);
                    if (customAttributes.Length == 0)
                    {
                        throw new ArgumentException(Res.GetString("RequiredXmlFormatExtensionAttributeIsMissing1", new object[] { type.FullName }), "extensionTypes");
                    }
                    XmlFormatExtensionAttribute attribute = (XmlFormatExtensionAttribute)customAttributes[0];
                    foreach (Type type2 in attribute.ExtensionPoints)
                    {
                        XmlAttributes attributes = (XmlAttributes)hashtable[type2];
                        if (attributes == null)
                        {
                            attributes = new XmlAttributes();
                            hashtable.Add(type2, attributes);
                        }
                        XmlElementAttribute attribute2 = new XmlElementAttribute(attribute.ElementName, type)
                        {
                            Namespace = attribute.Namespace
                        };
                        attributes.XmlElements.Add(attribute2);
                    }
                    customAttributes = type.GetCustomAttributes(typeof(XmlFormatExtensionPrefixAttribute), false);
                    string[]  array      = new string[customAttributes.Length];
                    Hashtable hashtable3 = new Hashtable();
                    for (int i = 0; i < customAttributes.Length; i++)
                    {
                        XmlFormatExtensionPrefixAttribute attribute3 = (XmlFormatExtensionPrefixAttribute)customAttributes[i];
                        array[i] = attribute3.Prefix;
                        hashtable3.Add(attribute3.Prefix, attribute3.Namespace);
                    }
                    Array.Sort(array, System.InvariantComparer.Default);
                    for (int j = 0; j < array.Length; j++)
                    {
                        namespaces.Add(array[j], (string)hashtable3[array[j]]);
                    }
                }
            }
            foreach (Type type3 in hashtable.Keys)
            {
                XmlFormatExtensionPointAttribute extensionPointAttribute = GetExtensionPointAttribute(type3);
                XmlAttributes attributes2 = (XmlAttributes)hashtable[type3];
                if (extensionPointAttribute.AllowElements)
                {
                    attributes2.XmlAnyElements.Add(new XmlAnyElementAttribute());
                }
                overrides.Add(type3, extensionPointAttribute.MemberName, attributes2);
            }
        }