public virtual Type GetType(XmlQualifiedName xmlQualifiedName)
        {
            if (xmlQualifiedName == null)
            {
                throw new ArgumentNullException("xmlQualifiedName");
            }

            string xmlns    = xmlQualifiedName.Namespace;
            string typeName = WorkflowMarkupSerializer.EnsureMarkupExtensionTypeName(xmlQualifiedName);


            // first check our cache
            cachedXmlQualifiedNameTypes.TryGetValue(xmlQualifiedName, out Type resolvedType);

            if (resolvedType == null)
            {
                // lookup in well known types
                resolvedType = WorkflowMarkupSerializerMapping.ResolveWellKnownTypes(this, xmlns, typeName);
            }

            if (resolvedType == null)
            {
                //Lookup existing mapping
                if (!this.xmlNamespaceBasedMappings.TryGetValue(xmlns, out List <WorkflowMarkupSerializerMapping> xmlnsMappings))
                {
                    WorkflowMarkupSerializerMapping.GetMappingsFromXmlNamespace(this, xmlns, out IList <WorkflowMarkupSerializerMapping> matchingMappings, out IList <WorkflowMarkupSerializerMapping> collectedMappings);
                    AddMappings(matchingMappings);
                    AddMappings(collectedMappings);

                    xmlnsMappings = new List <WorkflowMarkupSerializerMapping>(matchingMappings);
                }

                foreach (WorkflowMarkupSerializerMapping xmlnsMapping in xmlnsMappings)
                {
                    string assemblyName = xmlnsMapping.AssemblyName;
                    string clrNamespace = xmlnsMapping.ClrNamespace;

                    // append dot net namespace name
                    string fullTypeName = xmlQualifiedName.Name;
                    if (clrNamespace.Length > 0)
                    {
                        fullTypeName = clrNamespace + "." + xmlQualifiedName.Name;
                    }

                    // Work around  for component model assembly
                    if (assemblyName.Equals(Assembly.GetExecutingAssembly().FullName, StringComparison.Ordinal))
                    {
                        resolvedType = Assembly.GetExecutingAssembly().GetType(fullTypeName);
                    }
                    else if (assemblyName.Length == 0)
                    {
                        if (this.localAssembly != null)
                        {
                            resolvedType = this.localAssembly.GetType(fullTypeName);
                        }
                    }
                    else
                    {
                        string assemblyQualifiedName = fullTypeName;
                        if (assemblyName.Length > 0)
                        {
                            assemblyQualifiedName += (", " + assemblyName);
                        }

                        // now grab the actual type
                        try
                        {
                            resolvedType = GetType(assemblyQualifiedName);
                        }
                        catch
                        {
                            //
                        }

                        if (resolvedType == null)
                        {
                            resolvedType = GetType(fullTypeName);
                            if (resolvedType != null && !resolvedType.AssemblyQualifiedName.Equals(assemblyQualifiedName, StringComparison.Ordinal))
                            {
                                resolvedType = null;
                            }
                        }
                    }

                    //We found the type
                    if (resolvedType != null)
                    {
                        cachedXmlQualifiedNameTypes[xmlQualifiedName] = resolvedType;
                        break;
                    }
                }
            }

            return(resolvedType);
        }
Exemple #2
0
        public virtual Type GetType(XmlQualifiedName xmlQualifiedName)
        {
            if (xmlQualifiedName == null)
            {
                throw new ArgumentNullException("xmlQualifiedName");
            }
            string xmlns    = xmlQualifiedName.Namespace;
            string typeName = WorkflowMarkupSerializer.EnsureMarkupExtensionTypeName(xmlQualifiedName);
            Type   type     = null;

            this.cachedXmlQualifiedNameTypes.TryGetValue(xmlQualifiedName, out type);
            if (type == null)
            {
                type = WorkflowMarkupSerializerMapping.ResolveWellKnownTypes(this, xmlns, typeName);
            }
            if (type == null)
            {
                List <WorkflowMarkupSerializerMapping> list = null;
                if (!this.xmlNamespaceBasedMappings.TryGetValue(xmlns, out list))
                {
                    IList <WorkflowMarkupSerializerMapping> matchingMappings  = null;
                    IList <WorkflowMarkupSerializerMapping> collectedMappings = null;
                    WorkflowMarkupSerializerMapping.GetMappingsFromXmlNamespace(this, xmlns, out matchingMappings, out collectedMappings);
                    this.AddMappings(matchingMappings);
                    this.AddMappings(collectedMappings);
                    list = new List <WorkflowMarkupSerializerMapping>(matchingMappings);
                }
                foreach (WorkflowMarkupSerializerMapping mapping in list)
                {
                    string assemblyName = mapping.AssemblyName;
                    string clrNamespace = mapping.ClrNamespace;
                    string name         = xmlQualifiedName.Name;
                    if (clrNamespace.Length > 0)
                    {
                        name = clrNamespace + "." + xmlQualifiedName.Name;
                    }
                    if (assemblyName.Equals(Assembly.GetExecutingAssembly().FullName, StringComparison.Ordinal))
                    {
                        type = Assembly.GetExecutingAssembly().GetType(name);
                    }
                    else if (assemblyName.Length == 0)
                    {
                        if (this.localAssembly != null)
                        {
                            type = this.localAssembly.GetType(name);
                        }
                    }
                    else
                    {
                        string str6 = name;
                        if (assemblyName.Length > 0)
                        {
                            str6 = str6 + ", " + assemblyName;
                        }
                        try
                        {
                            type = this.GetType(str6);
                        }
                        catch
                        {
                        }
                        if (type == null)
                        {
                            type = this.GetType(name);
                            if ((type != null) && !type.AssemblyQualifiedName.Equals(str6, StringComparison.Ordinal))
                            {
                                type = null;
                            }
                        }
                    }
                    if (type != null)
                    {
                        this.cachedXmlQualifiedNameTypes[xmlQualifiedName] = type;
                        return(type);
                    }
                }
            }
            return(type);
        }