示例#1
0
        public static ExtensionMethodSet AddType(PythonContext context, ExtensionMethodSet /*!*/ existingSet, PythonType /*!*/ type)
        {
            Assert.NotNull(existingSet, type);

            lock (existingSet) {
                AssemblyLoadInfo assemblyLoadInfo;
                Assembly         assembly = type.UnderlyingSystemType.Assembly;
                if (existingSet._loadedAssemblies.TryGetValue(assembly, out assemblyLoadInfo))
                {
                    if (assemblyLoadInfo.IsFullAssemblyLoaded ||
                        (assemblyLoadInfo.Types != null && assemblyLoadInfo.Types.Contains(type)) ||
                        (assemblyLoadInfo.Namespaces != null && assemblyLoadInfo.Namespaces.Contains(type.UnderlyingSystemType.Namespace)))
                    {
                        // type is already in this set.
                        return(existingSet);
                    }
                }

                var dict = NewInfoOrCopy(existingSet);
                if (!dict.TryGetValue(assembly, out assemblyLoadInfo))
                {
                    dict[assembly] = assemblyLoadInfo = new AssemblyLoadInfo(assembly);
                }

                if (assemblyLoadInfo.Types == null)
                {
                    assemblyLoadInfo.Types = new HashSet <PythonType>();
                }

                assemblyLoadInfo.Types.Add(type);
                return(context.UniqifyExtensions(new ExtensionMethodSet(dict)));
            }
        }
示例#2
0
        public static ExtensionMethodSet AddNamespace(PythonContext context, ExtensionMethodSet /*!*/ existingSet, NamespaceTracker /*!*/ ns)
        {
            Assert.NotNull(existingSet, ns);

            lock (existingSet) {
                AssemblyLoadInfo asmInfo;

                Dictionary <Assembly, AssemblyLoadInfo> newDict = null;
                foreach (var assembly in ns.PackageAssemblies)
                {
                    if (existingSet != null && existingSet._loadedAssemblies.TryGetValue(assembly, out asmInfo))
                    {
                        if (asmInfo.IsFullAssemblyLoaded)
                        {
                            // full assembly is already in this set.
                            continue;
                        }

                        if (asmInfo.Namespaces == null || !asmInfo.Namespaces.Contains(ns.Name))
                        {
                            if (newDict == null)
                            {
                                newDict = NewInfoOrCopy(existingSet);
                            }
                            if (newDict[assembly].Namespaces == null)
                            {
                                newDict[assembly].Namespaces = new HashSet <string>();
                            }
                            newDict[assembly].Namespaces.Add(ns.Name);
                        }
                    }
                    else
                    {
                        if (newDict == null)
                        {
                            newDict = NewInfoOrCopy(existingSet);
                        }
                        var newAsmInfo = newDict[assembly] = new AssemblyLoadInfo(assembly);
                        newAsmInfo.Namespaces = new HashSet <string>();
                        newAsmInfo.Namespaces.Add(ns.Name);
                    }
                }
                if (newDict != null)
                {
                    return(context.UniqifyExtensions(new ExtensionMethodSet(newDict)));
                }
                return(existingSet);
            }
        }