System.Runtime.Remoting.SoapServices.GetXmlTypeForInteropType C# (CSharp) Méthode

GetXmlTypeForInteropType() public static méthode

public static GetXmlTypeForInteropType ( Type type, String &xmlType, String &xmlTypeNamespace ) : bool
type System.Type
xmlType String
xmlTypeNamespace String
Résultat bool
        public static bool GetXmlTypeForInteropType(Type type, 
                                                    out String xmlType, out String xmlTypeNamespace)
        {
            // check table first
            XmlEntry entry = (XmlEntry)_interopTypeToXmlType[type];
            if (entry != null)
            {
                xmlType = entry.Name;
                xmlTypeNamespace = entry.Namespace;
                return true;
            }

            // check soap attribute
            SoapTypeAttribute attr = (SoapTypeAttribute)
                InternalRemotingServices.GetCachedSoapAttribute(type);

            if (attr.IsInteropXmlType())
            {
                xmlType = attr.XmlTypeName;
                xmlTypeNamespace = attr.XmlTypeNamespace;
                return true;
            }
            else
            {
                xmlType = null;
                xmlTypeNamespace = null;
                return false;
            }           
        } // GetXmlTypeForInteropType

Usage Example

Exemple #1
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;
            }
        }