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
        } // 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 #6
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 #7
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;
            }
        }
        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 #9
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;
        }
Example #10
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