コード例 #1
0
        internal static IList <MethodInfo> FindConfigurationMethods(IEnumerable <Assembly> configurationAssemblies, Type configType)
        {
            return(configurationAssemblies
                   .SelectMany(a => a.
#if NET40
                               GetExportedTypes()
#else
                               ExportedTypes
#endif
                               .Select(t => t.GetTypeInfo()).Where(t => t.IsSealed && t.IsAbstract && !t.IsNested))
                   .SelectMany(t => t.DeclaredMethods)
                   .Where(m => m.IsStatic && m.IsPublic && m.IsDefined(typeof(ExtensionAttribute), false))
                   .Where(m => m.GetParameters()[0].ParameterType == configType)
                   .ToList());
        }
コード例 #2
0
        /// <summary>
        /// Constructs the view model from the <see cref="Type"/> of the plugin
        /// </summary>
        /// <param name="pluginType">The type of the plugin</param>
        public PluginViewModel(Type pluginType)
        {
            if (pluginType.GetCustomAttributes(typeof(PluginMetadataAttribute), false).FirstOrDefault() is PluginMetadataAttribute pluginMetadata)
            {
                PluginType    = pluginType;
                Name          = pluginMetadata.Name;
                Description   = pluginMetadata.Description;
                Author        = pluginMetadata.Author;
                Version       = pluginMetadata.Version;
                ExportedTypes = pluginMetadata.ExportedTypes;
            }

            ExportedTypesMetadata = (ExportedTypes?.Select(x =>
                                                           GetDecoratingAttributes <ExportedTypeMetadataAttribute>(x).FirstOrDefault())
                                     ?? Enumerable.Empty <ExportedTypeMetadataAttribute>())
                                    .Where(x => x != null)
                                    .Concat(GetDecoratingAttributes <ExportedTypeMetadataAttribute>(PluginType))
                                    .Distinct();
        }