public virtual XmlQualifiedName GetXmlQualifiedName(Type type, out string prefix)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            string typeNamespace = type.Namespace ?? String.Empty;
            string assemblyName  = (type.Assembly != null && type.Assembly != this.localAssembly) ? type.Assembly.FullName : String.Empty;

            int key = typeNamespace.GetHashCode() ^ assemblyName.GetHashCode();

            if (!this.clrNamespaceBasedMappings.TryGetValue(key, out WorkflowMarkupSerializerMapping mappingForType))
            {
                WorkflowMarkupSerializerMapping.GetMappingFromType(this, type, out mappingForType, out IList <WorkflowMarkupSerializerMapping> collectedMappings);
                AddMappings(new List <WorkflowMarkupSerializerMapping>(new WorkflowMarkupSerializerMapping[] { mappingForType }));
                AddMappings(collectedMappings);
            }

            string typeName = WorkflowMarkupSerializer.EnsureMarkupExtensionTypeName(type);

            //Make sure that while writting the workflow namespaces will always be the default
            prefix = (mappingForType.Prefix.Equals(StandardXomlKeys.WorkflowPrefix, StringComparison.Ordinal)) ? String.Empty : mappingForType.Prefix;
            return(new XmlQualifiedName(typeName, mappingForType.XmlNamespace));
        }
Ejemplo n.º 2
0
        public virtual XmlQualifiedName GetXmlQualifiedName(Type type, out string prefix)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            string str  = (type.Namespace != null) ? type.Namespace : string.Empty;
            string str2 = ((type.Assembly != null) && (type.Assembly != this.localAssembly)) ? type.Assembly.FullName : string.Empty;
            WorkflowMarkupSerializerMapping mapping = null;
            int key = str.GetHashCode() ^ str2.GetHashCode();

            if (!this.clrNamespaceBasedMappings.TryGetValue(key, out mapping))
            {
                IList <WorkflowMarkupSerializerMapping> collectedMappings = null;
                WorkflowMarkupSerializerMapping.GetMappingFromType(this, type, out mapping, out collectedMappings);
                this.AddMappings(new List <WorkflowMarkupSerializerMapping>(new WorkflowMarkupSerializerMapping[] { mapping }));
                this.AddMappings(collectedMappings);
            }
            string name = WorkflowMarkupSerializer.EnsureMarkupExtensionTypeName(type);

            prefix = mapping.Prefix.Equals("wf", StringComparison.Ordinal) ? string.Empty : mapping.Prefix;
            return(new XmlQualifiedName(name, mapping.XmlNamespace));
        }
        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);
        }
Ejemplo n.º 4
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);
        }