using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; namespace Umbraco.Core { internal static class AssemblyExtensions { /// /// Returns the file used to load the assembly /// /// /// public static FileInfo GetAssemblyFile(this Assembly assembly) { var codeBase = assembly.CodeBase; var uri = new Uri(codeBase); var path = uri.LocalPath; return new FileInfo(path); } /// /// Returns true if the assembly is the App_Code assembly /// /// /// public static bool IsAppCodeAssembly(this Assembly assembly) { if (assembly.FullName.StartsWith("App_Code")) { try { Assembly.Load("App_Code"); return true; } catch (FileNotFoundException) { //this will occur if it cannot load the assembly return false; } } return false; } /// /// Returns true if the assembly is the compiled global asax. /// /// /// public static bool IsGlobalAsaxAssembly(this Assembly assembly) { //only way I can figure out how to test is by the name return assembly.FullName.StartsWith("App_global.asax"); } /// /// Returns the file used to load the assembly /// /// /// public static FileInfo GetAssemblyFile(this AssemblyName assemblyName) { var codeBase = assemblyName.CodeBase; var uri = new Uri(codeBase); var path = uri.LocalPath; return new FileInfo(path); } } }