コード例 #1
0
        /// <summary>
        /// Searches for extensions in a particular file and tries to load them.
        /// </summary>
        /// <param name="file">The file to load.</param>
        /// <param name="extension">The extension that the file contains</param>
        /// <returns>Returns an array of loading results, indicating which extension loaded succesfully and which didn't.</returns>
        public ExtensionLoadResult[] LoadExtensions(ExtensionLibraryData file)
        {
            try
            {
                if (LoadedExtensions.FirstOrDefault(x => x.GetType().Assembly.Location.Equals(file.GetAbsolutePath(), StringComparison.OrdinalIgnoreCase)) != null)
                {
                    throw new InvalidOperationException("The extension library is already loaded.");
                }

                var extensionTypes = SearchExtensionTypes(file);

                if (extensionTypes.Length == 0)
                {
                    throw new BadImageFormatException(string.Format("No extension classes found in file {0}", file));
                }

                var results = new ExtensionLoadResult[extensionTypes.Length];
                for (int i = 0; i < extensionTypes.Length; i++)
                {
                    results[i] = LoadExtension(extensionTypes[i]);
                }
                return(results);
            }
            catch (Exception ex)
            {
                return(new ExtensionLoadResult[] { new ExtensionLoadResult(file.GetAbsolutePath(), ex) });
            }
        }
コード例 #2
0
        /// <summary>
        /// Searches for extension types in a specific file.
        /// </summary>
        /// <param name="file">The file to search for extensions.</param>
        /// <returns>Returns an array of types that are extensions.</returns>
        public Type[] SearchExtensionTypes(ExtensionLibraryData file)
        {
            var extensionTypes = new List <Type>();

            var assembly = Assembly.LoadFile(file.GetAbsolutePath());

            foreach (Type type in assembly.GetTypes())
            {
                if (type.BaseType == typeof(LiteExtension))
                {
                    extensionTypes.Add(type);
                }
            }

            return(extensionTypes.ToArray());
        }
コード例 #3
0
        /// <summary>
        /// Searches for extension types in a specific file.
        /// </summary>
        /// <param name="file">The file to search for extensions.</param>
        /// <returns>Returns an array of types that are extensions.</returns>
        public Type[] SearchExtensionTypes(ExtensionLibraryData file)
        {
            var extensionTypes = new List <Type>();

            var assembly = Assembly.LoadFile(file.GetAbsolutePath());

            _resolvedAssemblies.Add(assembly.FullName, assembly);

            foreach (Type type in assembly.GetTypes())
            {
                if (!type.IsAbstract && type.BaseType.IsBasedOn(typeof(LiteExtension)))
                {
                    extensionTypes.Add(type);
                }
            }

            return(extensionTypes.ToArray());
        }