System.MarshalByRefObject.CanCastToXmlType C# (CSharp) Method

CanCastToXmlType() private method

private CanCastToXmlType ( String xmlTypeName, String xmlTypeNamespace ) : bool
xmlTypeName String
xmlTypeNamespace String
return bool
        internal bool CanCastToXmlType(String xmlTypeName, String xmlTypeNamespace)
        {
            Type castType = SoapServices.GetInteropTypeFromXmlType(xmlTypeName, xmlTypeNamespace);
            if (castType == null)
            {
                String typeNamespace;
                String assemblyName;
                if (!SoapServices.DecodeXmlNamespaceForClrTypeNamespace(xmlTypeNamespace, 
                        out typeNamespace, out assemblyName))
                    return false;

                String typeName;
                if ((typeNamespace != null) && (typeNamespace.Length > 0))
                    typeName = typeNamespace + "." + xmlTypeName;
                else
                    typeName = xmlTypeName;

                try
                {
                    Assembly asm = Assembly.Load(assemblyName);
                    castType = asm.GetType(typeName, false, false);
                }
                catch 
                {
                    return false;
                }
            }

            if (castType != null)
                return castType.IsAssignableFrom(this.GetType());

            return false;
        } // CanCastToXmlType

Usage Example

        [System.Security.SecuritySafeCritical]  // auto-generated
        internal static bool CanCastToXmlTypeHelper(RuntimeType castType, MarshalByRefObject o)
        {
            if (castType == null)
            {
                throw new ArgumentNullException("castType");
            }

            Contract.EndContractBlock();
            // MarshalByRefObject's can only be casted to MarshalByRefObject's or interfaces.
            if (!castType.IsInterface && !castType.IsMarshalByRef)
            {
                return(false);
            }

            // figure out xml type name
            String xmlTypeName      = null;
            String xmlTypeNamespace = null;

            if (!SoapServices.GetXmlTypeForInteropType(castType, out xmlTypeName, out xmlTypeNamespace))
            {
                // There's no registered interop type name, so just use the default.
                xmlTypeName      = castType.Name;
                xmlTypeNamespace =
                    SoapServices.CodeXmlNamespaceForClrTypeNamespace(
                        castType.Namespace, castType.GetRuntimeAssembly().GetSimpleName());
            }

            return(o.CanCastToXmlType(xmlTypeName, xmlTypeNamespace));
        } // CanCastToXmlType
All Usage Examples Of System.MarshalByRefObject::CanCastToXmlType