/// <summary> /// Loads an IL Library from the specified file. /// </summary> /// <param name="FilePath">The path to the file to load as an IL Library.</param> /// <returns>The loaded IL Library.</returns> private static ILLibrary LoadILLibraryFromFile(string FilePath) { if (string.IsNullOrWhiteSpace(FilePath)) { Logger.LogError(Errors.Loader_LibraryPathNullOrEmpty_ErrorCode, FilePath, 0, Errors.ErrorMessages[Errors.Loader_LibraryPathNullOrEmpty_ErrorCode]); return(null); } else if (!File.Exists(FilePath)) { Logger.LogError(Errors.Loader_LibraryFileDoesntExist_ErrorCode, FilePath, 0, Errors.ErrorMessages[Errors.Loader_LibraryFileDoesntExist_ErrorCode]); return(null); } try { ILLibrary result = new ILLibrary(); result.TheAssembly = Assembly.LoadFrom(FilePath); return(result); } catch (Exception ex) { Logger.LogError(Errors.Loader_UnexpectedError_ErrorCode, FilePath, 0, string.Format( Errors.ErrorMessages[Errors.Loader_UnexpectedError_ErrorCode], ex.Message, ex.StackTrace)); } return(null); }
/// <summary> /// Loads an IL Library from the specified file and scans types within the library. /// </summary> /// <param name="FilePath">The path to the file to load as an IL Library.</param> /// <returns>The loaded IL Library.</returns> public static ILLibrary LoadILLibrary(string FilePath) { ILLibrary TheLibrary = LoadILLibraryFromFile(FilePath); if (TheLibrary != null) { LoadDependencies(TheLibrary); Types.TypeScanner.ScanTypes(TheLibrary); } return(TheLibrary); }
/// <summary> /// Loads all the dependencies of a library. /// </summary> /// <param name="aLibrary">The library to load dependencies of.</param> /// <returns>The number of dependencies loaded.</returns> public static int LoadDependencies(ILLibrary aLibrary) { if (aLibrary == null) { return(0); } int DependenciesLoaded = 0; Assembly RootAssembly = aLibrary.TheAssembly; AssemblyName[] refAssemblyNames = RootAssembly.GetReferencedAssemblies(); foreach (AssemblyName aRefName in refAssemblyNames) { if (IsAssemblyFullNameIgnored(aRefName.FullName)) { continue; } string refFilePath = Path.Combine(Path.GetDirectoryName(RootAssembly.Location), aRefName.Name + ".dll"); ILLibrary refLibrary = LoadILLibrary(refFilePath); if (refLibrary == null) { throw new NullReferenceException("Loaded dependency library was null!"); } else { if (LibraryCache.ContainsKey(refLibrary.ToString())) { aLibrary.Dependencies.Add(LibraryCache[refLibrary.ToString()]); } else { aLibrary.Dependencies.Add(refLibrary); LibraryCache.Add(refLibrary.ToString(), refLibrary); } } } return(DependenciesLoaded); }