コード例 #1
0
 private void OnAssemblyLoading(AssemblyLoadingEventArgs e)
 {
     if (this.AssemblyLoading != null)
     {
         this.AssemblyLoading(this, e);
     }
 }
コード例 #2
0
        /// <summary>
        /// Attempts to load an instance of the given file if it matches SourceFileExtensionMappings or CompiledFileExtensions
        /// </summary>
        /// <param name="filename">Full name of file to load</param>
        public void LoadExtension(string filename)
        {
            // Fire off the loading event, gives consumer a chance to cancel the loading
            AssemblyLoadingEventArgs eargs = new AssemblyLoadingEventArgs(filename);

            OnAssemblyLoading(eargs);

            // If the event consumer cancelled it, no need to continue for this file
            if (eargs.Cancel)
            {
                return;
            }

            // Get the extension of the file
            string extension = new FileInfo(filename).Extension.TrimStart('.').Trim().ToLower();

            // Check to see if the extension is in the list of source file extensions
            // This allows us to pair up an extension with a particular language it should be compiled in
            // Primative but otherwise how do we know what to compile it as?  We could do some deep analysis of file content,
            // but that is beyond the scope of this library in my opinion
            if (SourceFileExtensionMappings.ContainsKey(extension) || SourceFileExtensionMappings.ContainsKey("." + extension))
            {
                SourceFileLanguage language = SourceFileLanguage.CSharp;

                // Get the matching language
                if (SourceFileExtensionMappings.ContainsKey(extension))
                {
                    language = SourceFileExtensionMappings[extension];
                }
                else
                {
                    language = SourceFileExtensionMappings["." + extension];
                }

                // Obviously it's a source file, so load it
                this.LoadSourceFile(filename, language);
            }
            else if (CompiledFileExtensions.Contains(extension) || CompiledFileExtensions.Contains("." + extension))
            {
                // It's in the compiled file extension list, so just load it
                this.LoadCompiledFile(filename);
            }
        }