Example #1
0
        public static void PreLoad(Type type)
        {
            // Register soap actions for the methods in the type.
            foreach (MethodInfo method in type.GetMethods())
            {
                RegisterSoapActionForMethodBase(method);
            }

            // Register XML tags for the type, if specified.
            SoapTypeAttribute tattr = (SoapTypeAttribute)
                                      InternalRemotingServices.GetCachedSoapAttribute(type);

            if (tattr.xmlElementWasSet)
            {
                RegisterInteropXmlElement
                    (tattr.XmlElementName, tattr.XmlNamespace, type);
            }
            if (tattr.xmlTypeWasSet)
            {
                RegisterInteropXmlType
                    (tattr.XmlTypeName, tattr.XmlTypeNamespace, type);
            }

            // Load and register the field mapping information.
            lock (typeof(SoapServices))
            {
                if (fields == null)
                {
                    fields = new Hashtable();
                }
                TypeFieldInfo typeInfo = new TypeFieldInfo();
                foreach (FieldInfo field in type.GetFields())
                {
                    SoapFieldAttribute fattr = (SoapFieldAttribute)
                                               InternalRemotingServices.GetCachedSoapAttribute
                                                   (field);
                    if (fattr.IsInteropXmlElement())
                    {
                        if (fattr.UseAttribute)
                        {
                            typeInfo.StoreAttribute
                                (XmlKey(fattr.XmlElementName,
                                        fattr.XmlNamespace),
                                field.Name, field.FieldType);
                        }
                        else
                        {
                            typeInfo.StoreElement
                                (XmlKey(fattr.XmlElementName,
                                        fattr.XmlNamespace),
                                field.Name, field.FieldType);
                        }
                    }
                }
                if (typeInfo.IsPopulated)
                {
                    fields[type] = typeInfo;
                }
            }
        }
Example #2
0
        } // ProcessTypeAttribute

        internal static void ProcessMemberInfoAttribute(MemberInfo memberInfo, SoapAttributeInfo attributeInfo)
        {
            SoapAttribute attr = (SoapAttribute)
                                 InternalRemotingServices.GetCachedSoapAttribute(memberInfo);

            if (attr.Embedded)
            {
                attributeInfo.m_attributeType |= SoapAttributeType.Embedded;
            }

            // check for attribute and other junk
            if (attr is SoapFieldAttribute)
            {
                SoapFieldAttribute fieldAttr = (SoapFieldAttribute)attr;
                if (fieldAttr.UseAttribute)
                {
                    attributeInfo.m_attributeType |= SoapAttributeType.XmlAttribute;
                    attributeInfo.m_elementName    = fieldAttr.XmlElementName;
                    attributeInfo.m_nameSpace      = fieldAttr.XmlNamespace;
                }
                else
                {
                    if (fieldAttr.IsInteropXmlElement())
                    {
                        attributeInfo.m_attributeType |= SoapAttributeType.XmlElement;
                        attributeInfo.m_elementName    = fieldAttr.XmlElementName;
                        attributeInfo.m_nameSpace      = fieldAttr.XmlNamespace;
                    }
                }
            }
        } // ProcessMemberInfoAttribute
        internal static void ProcessMemberInfoAttribute(MemberInfo memberInfo, SoapAttributeInfo attributeInfo)
        {
            SoapAttribute cachedSoapAttribute = InternalRemotingServices.GetCachedSoapAttribute(memberInfo);

            if (cachedSoapAttribute.Embedded)
            {
                attributeInfo.m_attributeType |= SoapAttributeType.Embedded;
            }
            if (cachedSoapAttribute is SoapFieldAttribute)
            {
                SoapFieldAttribute attribute2 = (SoapFieldAttribute)cachedSoapAttribute;
                if (attribute2.UseAttribute)
                {
                    attributeInfo.m_attributeType |= SoapAttributeType.XmlAttribute;
                    attributeInfo.m_elementName    = attribute2.XmlElementName;
                    attributeInfo.m_nameSpace      = attribute2.XmlNamespace;
                }
                else if (attribute2.IsInteropXmlElement())
                {
                    attributeInfo.m_attributeType |= SoapAttributeType.XmlElement;
                    attributeInfo.m_elementName    = attribute2.XmlElementName;
                    attributeInfo.m_nameSpace      = attribute2.XmlNamespace;
                }
            }
        }
Example #4
0
        void WriteClassSchema(XmlTextWriter tw, Type type)
        {
            tw.WriteStartElement("element", MetaData.SchemaNamespace);
            tw.WriteAttributeString("name", type.Name);
            tw.WriteAttributeString("type", GetQualifiedXmlType(tw, type, null));
            tw.WriteEndElement();

            tw.WriteStartElement("complexType", MetaData.SchemaNamespace);
            tw.WriteAttributeString("name", GetXmlType(type));
            if (type.BaseType != null && type.BaseType != typeof(object) && type.BaseType != typeof(ValueType))
            {
                tw.WriteAttributeString("base", GetQualifiedXmlType(tw, type.BaseType, null));
            }

            FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);

            // Element fields

            bool elemsStart = false;

            foreach (FieldInfo fi in fields)
            {
                SoapFieldAttribute att = (SoapFieldAttribute)InternalRemotingServices.GetCachedSoapAttribute(fi);
                if (att.UseAttribute)
                {
                    continue;
                }

                if (!elemsStart)
                {
                    tw.WriteStartElement("all", MetaData.SchemaNamespace);
                    elemsStart = true;
                }
                tw.WriteStartElement("element", MetaData.SchemaNamespace);
                tw.WriteAttributeString("name", att.XmlElementName);
                tw.WriteAttributeString("type", GetQualifiedXmlType(tw, fi.FieldType, type));
                tw.WriteEndElement();
            }
            if (elemsStart)
            {
                tw.WriteEndElement();           // all
            }
            // Attribute fields

            foreach (FieldInfo fi in fields)
            {
                SoapFieldAttribute att = (SoapFieldAttribute)InternalRemotingServices.GetCachedSoapAttribute(fi);
                if (!att.UseAttribute)
                {
                    continue;
                }

                tw.WriteStartElement("attribute", MetaData.SchemaNamespace);
                tw.WriteAttributeString("name", att.XmlElementName);
                tw.WriteAttributeString("type", GetQualifiedXmlType(tw, fi.FieldType, type));
                tw.WriteEndElement();
            }

            tw.WriteEndElement(); // complexType
        }
Example #5
0
        } // RegisterInteropXmlType

        /// <include file='doc\Soap.uex' path='docs/doc[@for="SoapServices.PreLoad"]/*' />
        public static void PreLoad(Type type)
        {
            // register soap action values
            MethodInfo[] methods = type.GetMethods();
            foreach (MethodInfo mi in methods)
            {
                // This will only add an entry to the table if SoapAction was explicitly set
                //   on the SoapMethodAttribute.
                RegisterSoapActionForMethodBase(mi);
            }

            // register interop xml elements and types if specified
            SoapTypeAttribute attr = (SoapTypeAttribute)
                                     InternalRemotingServices.GetCachedSoapAttribute(type);

            if (attr.IsInteropXmlElement())
            {
                RegisterInteropXmlElement(attr.XmlElementName, attr.XmlNamespace, type);
            }
            if (attr.IsInteropXmlType())
            {
                RegisterInteropXmlType(attr.XmlTypeName, attr.XmlTypeNamespace, type);
            }

            // construct field maps for mapping xml elements and attributes back to
            //   the correct type
            int mapCount          = 0;
            XmlToFieldTypeMap map = new XmlToFieldTypeMap();

            foreach (FieldInfo field in type.GetFields())
            {
                SoapFieldAttribute fieldAttr = (SoapFieldAttribute)
                                               InternalRemotingServices.GetCachedSoapAttribute(field);

                if (fieldAttr.IsInteropXmlElement())
                {
                    String xmlName      = fieldAttr.XmlElementName;
                    String xmlNamespace = fieldAttr.XmlNamespace;
                    if (fieldAttr.UseAttribute)
                    {
                        map.AddXmlAttribute(field.FieldType, field.Name, xmlName, xmlNamespace);
                    }
                    else
                    {
                        map.AddXmlElement(field.FieldType, field.Name, xmlName, xmlNamespace);
                    }

                    mapCount++;
                }
            } // foreach field

            // add field map if there is more than one entry
            if (mapCount > 0)
            {
                _xmlToFieldTypeMap[type] = map;
            }
        } // PreLoad
        public static void PreLoad(Type type)
        {
            string   name, namspace;
            TypeInfo tf = _typeInfos [type] as TypeInfo;

            if (tf != null)
            {
                return;
            }

            if (GetXmlTypeForInteropType(type, out name, out namspace))
            {
                RegisterInteropXmlType(name, namspace, type);
            }

            if (GetXmlElementForInteropType(type, out name, out namspace))
            {
                RegisterInteropXmlElement(name, namspace, type);
            }

            lock (_typeInfos.SyncRoot)
            {
                tf = new TypeInfo();
                FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

                foreach (FieldInfo field in fields)
                {
                    SoapFieldAttribute att = (SoapFieldAttribute)InternalRemotingServices.GetCachedSoapAttribute(field);
                    if (!att.IsInteropXmlElement())
                    {
                        continue;
                    }

                    string key = GetNameKey(att.XmlElementName, att.XmlNamespace);
                    if (att.UseAttribute)
                    {
                        if (tf.Attributes == null)
                        {
                            tf.Attributes = new Hashtable();
                        }
                        tf.Attributes [key] = field;
                    }
                    else
                    {
                        if (tf.Elements == null)
                        {
                            tf.Elements = new Hashtable();
                        }
                        tf.Elements [key] = field;
                    }
                }
                _typeInfos [type] = tf;
            }
        }
Example #7
0
        public static void PreLoad(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (!(type is RuntimeType))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"));
            }
            MethodInfo[] methods = type.GetMethods();
            foreach (MethodInfo mb in methods)
            {
                SoapServices.RegisterSoapActionForMethodBase(mb);
            }
            SoapTypeAttribute soapTypeAttribute = (SoapTypeAttribute)InternalRemotingServices.GetCachedSoapAttribute(type);

            if (soapTypeAttribute.IsInteropXmlElement())
            {
                SoapServices.RegisterInteropXmlElement(soapTypeAttribute.XmlElementName, soapTypeAttribute.XmlNamespace, type);
            }
            if (soapTypeAttribute.IsInteropXmlType())
            {
                SoapServices.RegisterInteropXmlType(soapTypeAttribute.XmlTypeName, soapTypeAttribute.XmlTypeNamespace, type);
            }
            int num = 0;

            SoapServices.XmlToFieldTypeMap xmlToFieldTypeMap = new SoapServices.XmlToFieldTypeMap();
            foreach (FieldInfo fieldInfo in type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
            {
                SoapFieldAttribute soapFieldAttribute = (SoapFieldAttribute)InternalRemotingServices.GetCachedSoapAttribute(fieldInfo);
                if (soapFieldAttribute.IsInteropXmlElement())
                {
                    string xmlElementName = soapFieldAttribute.XmlElementName;
                    string xmlNamespace   = soapFieldAttribute.XmlNamespace;
                    if (soapFieldAttribute.UseAttribute)
                    {
                        xmlToFieldTypeMap.AddXmlAttribute(fieldInfo.FieldType, fieldInfo.Name, xmlElementName, xmlNamespace);
                    }
                    else
                    {
                        xmlToFieldTypeMap.AddXmlElement(fieldInfo.FieldType, fieldInfo.Name, xmlElementName, xmlNamespace);
                    }
                    num++;
                }
            }
            if (num > 0)
            {
                SoapServices._xmlToFieldTypeMap[type] = xmlToFieldTypeMap;
            }
        }
Example #8
0
        /// <summary>Preloads the given <see cref="T:System.Type" /> based on values set in a <see cref="T:System.Runtime.Remoting.Metadata.SoapTypeAttribute" /> on the type.</summary>
        /// <param name="type">The <see cref="T:System.Type" /> to preload. </param>
        /// <exception cref="T:System.Security.SecurityException">The immediate caller does not have infrastructure permission. </exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Infrastructure" />
        /// </PermissionSet>
        public static void PreLoad(Type type)
        {
            SoapServices.TypeInfo typeInfo = SoapServices._typeInfos[type] as SoapServices.TypeInfo;
            if (typeInfo != null)
            {
                return;
            }
            string text;
            string text2;

            if (SoapServices.GetXmlTypeForInteropType(type, out text, out text2))
            {
                SoapServices.RegisterInteropXmlType(text, text2, type);
            }
            if (SoapServices.GetXmlElementForInteropType(type, out text, out text2))
            {
                SoapServices.RegisterInteropXmlElement(text, text2, type);
            }
            object syncRoot = SoapServices._typeInfos.SyncRoot;

            lock (syncRoot)
            {
                typeInfo = new SoapServices.TypeInfo();
                FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                foreach (FieldInfo fieldInfo in fields)
                {
                    SoapFieldAttribute soapFieldAttribute = (SoapFieldAttribute)InternalRemotingServices.GetCachedSoapAttribute(fieldInfo);
                    if (soapFieldAttribute.IsInteropXmlElement())
                    {
                        string nameKey = SoapServices.GetNameKey(soapFieldAttribute.XmlElementName, soapFieldAttribute.XmlNamespace);
                        if (soapFieldAttribute.UseAttribute)
                        {
                            if (typeInfo.Attributes == null)
                            {
                                typeInfo.Attributes = new Hashtable();
                            }
                            typeInfo.Attributes[nameKey] = fieldInfo;
                        }
                        else
                        {
                            if (typeInfo.Elements == null)
                            {
                                typeInfo.Elements = new Hashtable();
                            }
                            typeInfo.Elements[nameKey] = fieldInfo;
                        }
                    }
                }
                SoapServices._typeInfos[type] = typeInfo;
            }
        }
Example #9
0
        private void SerializeSimpleObject(
            object currentObject,
            long currentObjectId)
        {
            Type currentType = currentObject.GetType();

            // Value type have to be serialized "on the fly" so
            // SerializeComponent calls SerializeObject when
            // a field of another object is a struct. A node with the field
            // name has already be written so WriteStartElement must not be called
            // again. Fields that are structs are passed to SerializeObject
            // with a id = 0
            if (currentObjectId > 0)
            {
                Element element = _mapper.GetXmlElement(currentType);
                _xmlWriter.WriteStartElement(element.Prefix, element.LocalName, element.NamespaceURI);
                Id(currentObjectId);
            }

            if (currentType == typeof(TimeSpan))
            {
                _xmlWriter.WriteString(SoapTypeMapper.GetXsdValue(currentObject));
            }
            else if (currentType == typeof(string))
            {
                _xmlWriter.WriteString(currentObject.ToString());
            }
            else
            {
                MemberInfo[] memberInfos = FormatterServices.GetSerializableMembers(currentType, _context);
                object[]     objectData  = FormatterServices.GetObjectData(currentObject, memberInfos);

#if FIXED
                for (int i = 0; i < memberInfos.Length; i++)
                {
                    FieldInfo          fieldInfo = (FieldInfo)memberInfos[i];
                    SoapFieldAttribute at        = (SoapFieldAttribute)InternalRemotingServices.GetCachedSoapAttribute(fieldInfo);
                    _xmlWriter.WriteStartElement(XmlConvert.EncodeLocalName(at.XmlElementName));
                    SerializeComponent(
                        objectData[i],
                        IsEncodingNeeded(objectData[i], fieldInfo.FieldType));
                    _xmlWriter.WriteEndElement();
                }
#endif
            }
            if (currentObjectId > 0)
            {
                _xmlWriter.WriteFullEndElement();
            }
        }
        public static void PreLoad(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (!(type is RuntimeType))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"));
            }
            foreach (MethodInfo info in type.GetMethods())
            {
                RegisterSoapActionForMethodBase(info);
            }
            SoapTypeAttribute cachedSoapAttribute = (SoapTypeAttribute)InternalRemotingServices.GetCachedSoapAttribute(type);

            if (cachedSoapAttribute.IsInteropXmlElement())
            {
                RegisterInteropXmlElement(cachedSoapAttribute.XmlElementName, cachedSoapAttribute.XmlNamespace, type);
            }
            if (cachedSoapAttribute.IsInteropXmlType())
            {
                RegisterInteropXmlType(cachedSoapAttribute.XmlTypeName, cachedSoapAttribute.XmlTypeNamespace, type);
            }
            int num = 0;
            XmlToFieldTypeMap map = new XmlToFieldTypeMap();

            foreach (FieldInfo info2 in type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
            {
                SoapFieldAttribute attribute2 = (SoapFieldAttribute)InternalRemotingServices.GetCachedSoapAttribute(info2);
                if (attribute2.IsInteropXmlElement())
                {
                    string xmlElementName = attribute2.XmlElementName;
                    string xmlNamespace   = attribute2.XmlNamespace;
                    if (attribute2.UseAttribute)
                    {
                        map.AddXmlAttribute(info2.FieldType, info2.Name, xmlElementName, xmlNamespace);
                    }
                    else
                    {
                        map.AddXmlElement(info2.FieldType, info2.Name, xmlElementName, xmlNamespace);
                    }
                    num++;
                }
            }
            if (num > 0)
            {
                _xmlToFieldTypeMap[type] = map;
            }
        }
Example #11
0
        public static void PreLoad(Type type)
        {
            foreach (MethodBase method in type.GetMethods())
            {
                SoapServices.RegisterSoapActionForMethodBase(method);
            }
            SoapTypeAttribute cachedSoapAttribute1 = (SoapTypeAttribute)InternalRemotingServices.GetCachedSoapAttribute((object)type);

            if (cachedSoapAttribute1.IsInteropXmlElement())
            {
                SoapServices.RegisterInteropXmlElement(cachedSoapAttribute1.XmlElementName, cachedSoapAttribute1.XmlNamespace, type);
            }
            if (cachedSoapAttribute1.IsInteropXmlType())
            {
                SoapServices.RegisterInteropXmlType(cachedSoapAttribute1.XmlTypeName, cachedSoapAttribute1.XmlTypeNamespace, type);
            }
            int num = 0;

            SoapServices.XmlToFieldTypeMap xmlToFieldTypeMap = new SoapServices.XmlToFieldTypeMap();
            foreach (FieldInfo field in type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
            {
                SoapFieldAttribute cachedSoapAttribute2 = (SoapFieldAttribute)InternalRemotingServices.GetCachedSoapAttribute((object)field);
                if (cachedSoapAttribute2.IsInteropXmlElement())
                {
                    string xmlElementName = cachedSoapAttribute2.XmlElementName;
                    string xmlNamespace   = cachedSoapAttribute2.XmlNamespace;
                    if (cachedSoapAttribute2.UseAttribute)
                    {
                        xmlToFieldTypeMap.AddXmlAttribute(field.FieldType, field.Name, xmlElementName, xmlNamespace);
                    }
                    else
                    {
                        xmlToFieldTypeMap.AddXmlElement(field.FieldType, field.Name, xmlElementName, xmlNamespace);
                    }
                    ++num;
                }
            }
            if (num <= 0)
            {
                return;
            }
            SoapServices._xmlToFieldTypeMap[(object)type] = (object)xmlToFieldTypeMap;
        }
        /// <summary>Gets an appropriate SOAP-related attribute for the specified class member or method parameter. </summary>
        /// <param name="reflectionObject">A class member or method parameter.</param>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Infrastructure" />
        /// </PermissionSet>
        public static SoapAttribute GetCachedSoapAttribute(object reflectionObject)
        {
            object        syncRoot = InternalRemotingServices._soapAttributes.SyncRoot;
            SoapAttribute result;

            lock (syncRoot)
            {
                SoapAttribute soapAttribute = InternalRemotingServices._soapAttributes[reflectionObject] as SoapAttribute;
                if (soapAttribute != null)
                {
                    result = soapAttribute;
                }
                else
                {
                    ICustomAttributeProvider customAttributeProvider = (ICustomAttributeProvider)reflectionObject;
                    object[] customAttributes = customAttributeProvider.GetCustomAttributes(typeof(SoapAttribute), true);
                    if (customAttributes.Length > 0)
                    {
                        soapAttribute = (SoapAttribute)customAttributes[0];
                    }
                    else if (reflectionObject is Type)
                    {
                        soapAttribute = new SoapTypeAttribute();
                    }
                    else if (reflectionObject is FieldInfo)
                    {
                        soapAttribute = new SoapFieldAttribute();
                    }
                    else if (reflectionObject is MethodBase)
                    {
                        soapAttribute = new SoapMethodAttribute();
                    }
                    else if (reflectionObject is ParameterInfo)
                    {
                        soapAttribute = new SoapParameterAttribute();
                    }
                    soapAttribute.SetReflectionObject(reflectionObject);
                    InternalRemotingServices._soapAttributes[reflectionObject] = soapAttribute;
                    result = soapAttribute;
                }
            }
            return(result);
        }
Example #13
0
        public static SoapAttribute GetCachedSoapAttribute(object reflectionObject)
        {
            lock (_soapAttributes.SyncRoot)
            {
                SoapAttribute att = _soapAttributes [reflectionObject] as SoapAttribute;
                if (att != null)
                {
                    return(att);
                }

                ICustomAttributeProvider ap = (ICustomAttributeProvider)reflectionObject;
                object[] atts = ap.GetCustomAttributes(typeof(SoapAttribute), true);
                if (atts.Length > 0)
                {
                    att = (SoapAttribute)atts[0];
                }
                else
                {
                    if (reflectionObject is Type)
                    {
                        att = new SoapTypeAttribute();
                    }
                    else if (reflectionObject is FieldInfo)
                    {
                        att = new SoapFieldAttribute();
                    }
                    else if (reflectionObject is MethodBase)
                    {
                        att = new SoapMethodAttribute();
                    }
                    else if (reflectionObject is ParameterInfo)
                    {
                        att = new SoapParameterAttribute();
                    }
                }

                att.SetReflectionObject(reflectionObject);
                _soapAttributes [reflectionObject] = att;
                return(att);
            }
        }
Example #14
0
        TypeMetadata GetTypeMetadata(Type type)
        {
            TypeMetadata tm = _fieldIndices[type] as TypeMetadata;

            if (tm != null)
            {
                return(tm);
            }

            tm             = new TypeMetadata();
            tm.MemberInfos = FormatterServices.GetSerializableMembers(type, _context);

            tm.Indices = new Hashtable();
            for (int i = 0; i < tm.MemberInfos.Length; i++)
            {
                SoapFieldAttribute at = (SoapFieldAttribute)InternalRemotingServices.GetCachedSoapAttribute(tm.MemberInfos[i]);
                tm.Indices [XmlConvert.EncodeLocalName(at.XmlElementName)] = i;
            }

            _fieldIndices[type] = tm;
            return(tm);
        }
Example #15
0
        // Get the cached SOAP attribute data for an object.
        public static SoapAttribute GetCachedSoapAttribute(Object reflectionObject)
        {
            // Validate the paramter to ensure that it is a
            // legitimate reflection object.
            if (reflectionObject == null)
            {
                return(null);
            }
            else if (!(reflectionObject is MemberInfo) &&
                     !(reflectionObject is ParameterInfo))
            {
                return(null);
            }
            lock (typeof(InternalRemotingServices))
            {
                Object   attr;
                Object[] attrs;

                // Look for a cached value from last time.
                if (attributeHash == null)
                {
                    attributeHash = new Hashtable();
                }
                else if ((attr = attributeHash[reflectionObject]) != null)
                {
                    return(attr as SoapAttribute);
                }

                // Get the attribute information from the type.
                if (reflectionObject is Type)
                {
                    attrs = ((Type)reflectionObject).GetCustomAttributes
                                (typeof(SoapTypeAttribute), true);
                    if (attrs == null || attrs.Length < 1)
                    {
                        attr = new SoapTypeAttribute();
                    }
                    else
                    {
                        attr = attrs[0];
                    }
                }
                else if (reflectionObject is MethodBase)
                {
                    attrs = ((MethodBase)reflectionObject)
                            .GetCustomAttributes
                                (typeof(SoapMethodAttribute), true);
                    if (attrs == null || attrs.Length < 1)
                    {
                        attr = new SoapMethodAttribute();
                    }
                    else
                    {
                        attr = attrs[0];
                    }
                }
                else if (reflectionObject is FieldInfo)
                {
                    attrs = ((FieldInfo)reflectionObject)
                            .GetCustomAttributes
                                (typeof(SoapFieldAttribute), true);
                    if (attrs == null || attrs.Length < 1)
                    {
                        attr = new SoapFieldAttribute();
                    }
                    else
                    {
                        attr = attrs[0];
                    }
                }
                else if (reflectionObject is ParameterInfo)
                {
                    attrs = ((ParameterInfo)reflectionObject)
                            .GetCustomAttributes
                                (typeof(SoapParameterAttribute), true);
                    if (attrs == null || attrs.Length < 1)
                    {
                        attr = new SoapParameterAttribute();
                    }
                    else
                    {
                        attr = attrs[0];
                    }
                }
                else
                {
                    attrs = ((MemberInfo)reflectionObject)
                            .GetCustomAttributes(typeof(SoapAttribute), true);
                    if (attrs == null || attrs.Length < 1)
                    {
                        attr = new SoapAttribute();
                    }
                    else
                    {
                        attr = attrs[0];
                    }
                }
                ((SoapAttribute)attr).SetReflectInfo(reflectionObject);
                return((SoapAttribute)attr);
            }
        }
Example #16
0
        [System.Security.SecurityCritical]  // auto-generated
        public static void PreLoad(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            Contract.EndContractBlock();

            if (!(type is RuntimeType))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"));
            }

            // register soap action values
            MethodInfo[] methods = type.GetMethods();
            foreach (MethodInfo mi in methods)
            {
                // This will only add an entry to the table if SoapAction was explicitly set
                //   on the SoapMethodAttribute.
                RegisterSoapActionForMethodBase(mi);
            }

            // register interop xml elements and types if specified
            SoapTypeAttribute attr = (SoapTypeAttribute)
                                     InternalRemotingServices.GetCachedSoapAttribute(type);

            if (attr.IsInteropXmlElement())
            {
                RegisterInteropXmlElement(attr.XmlElementName, attr.XmlNamespace, type);
            }
            if (attr.IsInteropXmlType())
            {
                RegisterInteropXmlType(attr.XmlTypeName, attr.XmlTypeNamespace, type);
            }

            // construct field maps for mapping xml elements and attributes back to
            //   the correct type
            int mapCount          = 0;
            XmlToFieldTypeMap map = new XmlToFieldTypeMap();

            foreach (FieldInfo field in type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly))
            {
                SoapFieldAttribute fieldAttr = (SoapFieldAttribute)
                                               InternalRemotingServices.GetCachedSoapAttribute(field);

                if (fieldAttr.IsInteropXmlElement())
                {
                    String xmlName      = fieldAttr.XmlElementName;
                    String xmlNamespace = fieldAttr.XmlNamespace;
                    if (fieldAttr.UseAttribute)
                    {
                        map.AddXmlAttribute(field.FieldType, field.Name, xmlName, xmlNamespace);
                    }
                    else
                    {
                        map.AddXmlElement(field.FieldType, field.Name, xmlName, xmlNamespace);
                    }

                    mapCount++;
                }
            } // foreach field

            // add field map if there is more than one entry
            if (mapCount > 0)
            {
                _xmlToFieldTypeMap[type] = map;
            }
        } // PreLoad