Example #1
0
        private void LoadTypes(Assembly assembly)
        {
            Type[] types;
            try
            {
                types = assembly.GetTypes();
            }
            catch (ReflectionTypeLoadException ex)
            {
                foreach (var item in ex.LoaderExceptions)
                {
                    // TODO: show warning/error
                }
                types = ex.Types;
            }

            MediaManager.RegisterHandlersFromTypes(types);
            IconProviders.RegisterProvidersFromTypes(types);
            ControlPanels.RegisterPanelsFromTypes(types);

            shutdownActions.AddRange(from type in types
                                     from method in type.GetMethods()
                                     where (method.IsStatic && method.GetParameters().Length == 0 &&
                                            method.GetCustomAttributes(typeof(ShutdownAttribute), true).Cast <ShutdownAttribute>().Count() > 0)
                                     select(new Action(() => method.Invoke(null, null))));

            SettingsWindow.Tabs.AddRange(from type in types
                                         where type.GetInterfaces().Contains(typeof(ISettingsTab))
                                         select type);
        }
Example #2
0
 /// <summary>
 /// Gets the icon provider by its type or null if the type is not registered.
 /// </summary>
 /// <param name="type">The type of the icon provider to get.</param>
 /// <returns>An icon provider of type <paramref name="type"/>, or null if none can be found.</returns>
 public static object GetProvider(Type type)
 {
     return(IconProviders.FirstOrDefault(x => x.GetType() == type));
 }
Example #3
0
 /// <summary>
 /// Gets the icon provider by its type or null if the type is not registered.
 /// </summary>
 /// <typeparam name="T">The type of the icon provider to get.</typeparam>
 /// <returns>An icon provider of type <typeparamref name="T"/>, or null if none can be found.</returns>
 public static T GetProvider <T>() where T : IconProvider
 {
     return(IconProviders.FirstOrDefault(x => x is T) as T);
 }