Example #1
0
 /// <summary>
 /// Gets an array of all the instantiatable <see cref="IElementAdderMenuCommand{TContext}"/>
 /// implementations that are annotated with <see cref="ElementAdderMenuCommandAttribute"/>.
 private static IEnumerable <Type> GetAnnotatedCommandTypes <TContext>()
 {
     return
         (from type in TypeMeta.DiscoverImplementations <IElementAdderMenuCommand <TContext> >()
          where type.IsClass && type.IsDefined(typeof(ElementAdderMenuCommandAttribute), false)
          select type);
 }
Example #2
0
        /// <summary>
        /// Discovers all of the available installer types for a given service.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <returns>
        /// An array of zero-or-more non-abstract installer types.
        /// </returns>
        public static Type[] DiscoverInstallerTypes(IServiceDescriptor service)
        {
            if (s_ServiceInstallerTypes == null)
            {
                s_ServiceInstallerTypes = TypeMeta.DiscoverImplementations <ZenjectServiceInstaller>();
            }

            var genericInstallerType = typeof(ZenjectServiceInstaller <>).MakeGenericType(service.ServiceType);

            return(s_ServiceInstallerTypes
                   .Where(installerType => genericInstallerType.IsAssignableFrom(installerType))
                   .Where(installerType => !installerType.IsAbstract && installerType.IsClass)
                   .ToArray());
        }
Example #3
0
        /// <summary>
        /// Populates a menu with concrete element types.
        /// </summary>
        /// <param name="menu">Editor menu.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="menu"/> is <c>null</c>.
        /// </exception>
        public void PopulateWithConcreteTypes(EditorMenu menu)
        {
            ExceptionUtility.CheckArgumentNotNull(menu, "menu");

            menu.AddSeparator();

            foreach (var concreteType in ApplyTypeFilter(TypeMeta.DiscoverImplementations(this.ElementContractType)))
            {
                menu.AddCommand(this.FormatTypeDisplayName(concreteType))
                .Enabled(this.ElementAdder != null && this.ElementAdder.CanAddElement(concreteType))
                .Action(() => {
                    if (this.ElementAdder.CanAddElement(concreteType))
                    {
                        this.ElementAdder.AddElement(concreteType);
                    }
                });
            }
        }
Example #4
0
 private static Type[] GetDiscoverablePackageLanguageTypes()
 {
     return(TypeMeta.DiscoverImplementations <PackageLanguage>()
            .Where(type => Attribute.IsDefined(type, typeof(DiscoverablePackageLanguageAttribute)))
            .ToArray());
 }