Пример #1
0
        /// <summary>
        /// Scans an assembly for exported namespaces, adding them to the
        /// mapping of valid namespaces. Note that for a given namespace
        /// a.b.c.d, each of a, a.b, a.b.c and a.b.c.d are considered to
        /// be valid namespaces (to better match Python import semantics).
        /// </summary>
        internal static void ScanAssembly(Assembly assembly)
        {
            // A couple of things we want to do here: first, we want to
            // gather a list of all of the namespaces contributed to by
            // the assembly.

            Type[] types = assembly.GetTypes();
            foreach (Type t in types)
            {
                string ns = t.Namespace ?? "";
                if (!namespaces.ContainsKey(ns))
                {
                    string[] names = ns.Split('.');
                    var      s     = "";
                    for (var n = 0; n < names.Length; n++)
                    {
                        s = n == 0 ? names[0] : s + "." + names[n];
                        namespaces.TryAdd(s, new ConcurrentDictionary <Assembly, string>());
                    }
                }

                if (ns != null)
                {
                    namespaces[ns].TryAdd(assembly, string.Empty);
                }

                if (ns != null && t.IsGenericTypeDefinition)
                {
                    GenericUtil.Register(t);
                }
            }
        }
Пример #2
0
        //===================================================================
        // Scans an assembly for exported namespaces, adding them to the
        // mapping of valid namespaces. Note that for a given namespace
        // a.b.c.d, each of a, a.b, a.b.c and a.b.c.d are considered to
        // be valid namespaces (to better match Python import semantics).
        //===================================================================

        static void ScanAssembly(Assembly assembly)
        {
            // A couple of things we want to do here: first, we want to
            // gather a list of all of the namespaces contributed to by
            // the assembly.

            Type[] types = assembly.GetTypes();
            for (int i = 0; i < types.Length; i++)
            {
                Type   t  = types[i];
                string ns = t.Namespace;
                if ((ns != null) && (!namespaces.ContainsKey(ns)))
                {
                    string[] names = ns.Split('.');
                    string   s     = "";
                    for (int n = 0; n < names.Length; n++)
                    {
                        s = (n == 0) ? names[0] : s + "." + names[n];
                        if (!namespaces.ContainsKey(s))
                        {
                            namespaces.Add(s,
                                           new Dictionary <Assembly, string>()
                                           );
                        }
                    }
                }

                if (ns != null && !namespaces[ns].ContainsKey(assembly))
                {
                    namespaces[ns].Add(assembly, String.Empty);
                }

                if (t.IsGenericTypeDefinition)
                {
                    GenericUtil.Register(t);
                }
            }
        }
Пример #3
0
        //===================================================================
        // Scans an assembly for exported namespaces, adding them to the
        // mapping of valid namespaces. Note that for a given namespace
        // a.b.c.d, each of a, a.b, a.b.c and a.b.c.d are considered to
        // be valid namespaces (to better match Python import semantics).
        //===================================================================

        static void ScanAssembly(Assembly assembly)
        {
            // A couple of things we want to do here: first, we want to
            // gather a list of all of the namespaces contributed to by
            // the assembly.

            Type[] types = assembly.GetTypes();
            for (int i = 0; i < types.Length; i++)
            {
                Type   t  = types[i];
                string ns = t.Namespace;
                if ((ns != null) && (!namespaces.ContainsKey(ns)))
                {
                    string[] names = ns.Split('.');
                    string   s     = "";
                    for (int n = 0; n < names.Length; n++)
                    {
                        s = (n == 0) ? names[0] : s + "." + names[n];
                        if (!namespaces.ContainsKey(s))
                        {
                            namespaces.Add(s,
                                           new Dictionary <Assembly, string>()
                                           );
                        }
                    }
                }

                if (ns != null && !namespaces[ns].ContainsKey(assembly))
                {
                    namespaces[ns].Add(assembly, String.Empty);
                }

                if (t.IsGenericTypeDefinition)
                {
                    GenericUtil.Register(t);
//                      Dictionary<string, string> map = null;
//                      generics.TryGetValue(t.Namespace, out map);
//                      if (map == null) {
//                          map = new Dictionary<string, string>();
//                          generics[t.Namespace] = map;
//                      }
//                      string bname = t.Name;
//                      string mapped = null;
//                      int tick = bname.IndexOf("`");
//                      if (tick > -1) {
//                          bname = bname.Substring(0, tick);
//                      }
//                      map.TryGetValue(bname, out mapped);
//                      if (mapped == null) {
//                          map[bname] = t.Name;
//                      }
                }

//                  if (t.IsGenericTypeDefinition) {
//                      List<string> snames = null;
//                      special.TryGetValue(t.Namespace, out snames);
//                      if (snames == null) {
//                          snames = new List<string>(8);
//                          special[t.Namespace] = snames;
//                      }
//                      snames.Add(t.Name);
//                  }
            }
        }