Projbook.Core.Snippet.SnippetExtractorFactory.LoadExtensions C# (CSharp) Метод

LoadExtensions() приватный Метод

Loads extensions.
private LoadExtensions ( ) : void
Результат void
        private void LoadExtensions()
        {
            // If the plugin directory doesn't exist, abort plugin loading
            if (!this.extensionDirectory.Exists)
                return;

            // Initialize catalog
            AggregateCatalog catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new DirectoryCatalog(this.extensionDirectory.FullName));

            // Load ISnippetExtractor factories
            string metadataName = "ExportTypeIdentity";
            string targetTypeFullName = typeof(ISnippetExtractor).FullName;
            foreach (ComposablePartDefinition composablePartDefinition in catalog.Parts.AsEnumerable())
            {
                // Look for composable part definition being an ISnippetExtracttor
                if (composablePartDefinition.ExportDefinitions.Any(d =>
                    d.Metadata.ContainsKey(metadataName) &&
                    d.Metadata[metadataName].ToString() == targetTypeFullName))
                {
                    // Fetch the extension type from the composable part definition
                    Type extensionType = ReflectionModelServices.GetPartType(composablePartDefinition).Value;

                    // Try to retrieve syntax attribute
                    SyntaxAttribute syntax = Attribute.GetCustomAttribute(extensionType, typeof(SyntaxAttribute)) as SyntaxAttribute;

                    // Add the extractor type to loaded ones if a syntax attribute is found and the type has a default contructor
                    if (null != syntax && null != extensionType.GetConstructor(Type.EmptyTypes))
                    {
                        // Create extractor factory
                        Func<ISnippetExtractor> extractorFactory = Expression.Lambda<Func<ISnippetExtractor>>(Expression.New(extensionType)).Compile();

                        // Record the created fectory as a loaded one
                        this.loadedExtractorFactories.Add(syntax.Name, extractorFactory);
                    }
                }
            }

            // Lookup in loaded extractors to detect custom default extractor
            Func<ISnippetExtractor> customDefaultExtractorFactory;
            if (this.loadedExtractorFactories.TryGetValue("*", out customDefaultExtractorFactory))
            {
                // Set the custom default extractor
                this.defaultExtractorFactory = customDefaultExtractorFactory;
            }
        }