Esempio n. 1
0
 private static void DiscoverFactories()
 {
     if (Factories.s_Factories == null)
     {
         Factories.s_Factories = new Dictionary <string, Func <IUxmlAttributes, CreationContext, VisualElement> >();
         CoreFactories.RegisterAll();
     }
 }
Esempio n. 2
0
 private static void DiscoverFactories()
 {
     if (Factories.s_Factories == null)
     {
         Factories.s_Factories = new Dictionary <string, Func <IUxmlAttributes, CreationContext, VisualElement> >();
         CoreFactories.RegisterAll();
         AppDomain        currentDomain = AppDomain.CurrentDomain;
         HashSet <string> hashSet       = new HashSet <string>(ScriptingRuntime.GetAllUserAssemblies());
         Assembly[]       assemblies    = currentDomain.GetAssemblies();
         for (int i = 0; i < assemblies.Length; i++)
         {
             Assembly assembly = assemblies[i];
             if (hashSet.Contains(assembly.GetName().Name + ".dll"))
             {
                 try
                 {
                     Type[] types = assembly.GetTypes();
                     for (int j = 0; j < types.Length; j++)
                     {
                         Type type = types[j];
                         if (typeof(IUxmlFactory).IsAssignableFrom(type))
                         {
                             IUxmlFactory uxmlFactory = (IUxmlFactory)Activator.CreateInstance(type);
                             Factories.RegisterFactory(uxmlFactory.CreatesType.FullName, new Func <IUxmlAttributes, CreationContext, VisualElement>(uxmlFactory.Create));
                         }
                     }
                 }
                 catch (TypeLoadException ex)
                 {
                     Debug.LogWarningFormat("Error while loading types from assembly {0}: {1}", new object[]
                     {
                         assembly.FullName,
                         ex
                     });
                 }
             }
         }
     }
 }
Esempio n. 3
0
        private static void DiscoverFactories()
        {
            if (s_Factories != null)
            {
                return;
            }

            s_Factories = new Dictionary <string, Func <IUxmlAttributes, CreationContext, VisualElement> >();
            CoreFactories.RegisterAll();

            AppDomain        currentDomain  = AppDomain.CurrentDomain;
            HashSet <string> userAssemblies = new HashSet <string>(ScriptingRuntime.GetAllUserAssemblies());

            foreach (Assembly assembly in currentDomain.GetAssemblies())
            {
                if (!userAssemblies.Contains(assembly.GetName().Name + ".dll"))
                {
                    continue;
                }

                try
                {
                    foreach (var type in assembly.GetTypes())
                    {
                        if (typeof(IUxmlFactory).IsAssignableFrom(type))
                        {
                            var factory = (IUxmlFactory)Activator.CreateInstance(type);
                            RegisterFactory(factory.CreatesType.FullName, factory.Create);
                        }
                    }
                }
                catch (TypeLoadException e)
                {
                    Debug.LogWarningFormat("Error while loading types from assembly {0}: {1}", assembly.FullName, e);
                }
            }
        }