/// <summary> /// Transforms the specified input assembly. /// </summary> /// <param name="inputAssemblyPath">The input assembly path.</param> /// <param name="outputPath">The output path.</param> /// <param name="transformerOptions">The transformer options.</param> /// <param name="filesCreated">The files created.</param> public void Transform(string inputAssemblyPath, string outputPath, SymbioticTransformerOptions transformerOptions, out IReadOnlyCollection <string> filesCreated) { if (string.IsNullOrEmpty(inputAssemblyPath) || !File.Exists(inputAssemblyPath)) { throw new ArgumentException($"The specified input assembly path does not exist: '{inputAssemblyPath}'.", nameof(inputAssemblyPath)); } if (string.IsNullOrEmpty(outputPath)) { throw new ArgumentException($"The specified output path is not valid: '{outputPath}'.", nameof(outputPath)); } if (transformerOptions == null) { throw new ArgumentNullException(nameof(transformerOptions)); } using (AssemblyResolutionManager assemblyResolver = TsAssemblyResolutionManager.Create(inputAssemblyPath, transformerOptions)) { TsTypeManager typeManager = new TsTypeManager(); Assembly assembly = Assembly.LoadFrom(inputAssemblyPath); IReadOnlyList <Assembly> assemblies = typeManager.DiscoverAssemblies(assembly); IReadOnlyList <Type> types = typeManager.DiscoverTypes(assemblies); IReadOnlyList <TsTypeSymbol> typeSymbols = typeManager.ResolveTypeSymbols(types); IFileSink fileSink = new DirectoryFileSink(outputPath); AuditingFileSink auditingFileSink = new AuditingFileSink(fileSink); TsSymbolWriter symbolWriter = new TsSymbolWriter(auditingFileSink); symbolWriter.WriteSymbols(typeSymbols); filesCreated = auditingFileSink.FilesCreated; } }
/// <summary> /// Creates an <see cref="AssemblyResolutionManager"/> and registers the handlers for /// the specified <see cref="AssemblyLoadContext"/>. /// </summary> /// <returns>An <see cref="AssemblyResolutionManager"/>.</returns> public static AssemblyResolutionManager Create(AssemblyLoadContext assembloyLoadContext) { AssemblyResolutionManager assemblyResolver = new AssemblyResolutionManager(assembloyLoadContext); assemblyResolver.RegisterHandlers(); return(assemblyResolver); }
/// <summary> /// Creates a <see cref="AssemblyResolutionManager"/> from the specified assembly lookup paths and options. /// </summary> /// <param name="assemblyLookupPaths">The assembly lookup paths.</param> /// <param name="transformerOptions">The transformer options.</param> /// <returns>A <see cref="AssemblyResolutionManager"/>.</returns> public static AssemblyResolutionManager Create(IEnumerable <string> assemblyLookupPaths, SymbioticTransformerOptions transformerOptions) { AssemblyResolutionManager assemblyResolver = AssemblyResolutionManager.CreateDefault(); if (!string.IsNullOrEmpty(transformerOptions.AssemblyReferencesFilePath)) { string[] assemblyPaths = File.ReadAllLines(transformerOptions.AssemblyReferencesFilePath); assemblyResolver.AddAssemblyResolver(StaticAssemblyResolver.Create(assemblyPaths)); } foreach (string lookupPath in assemblyLookupPaths) { assemblyResolver.AddAssemblyResolver(PathAssemblyResolver.Create(Path.GetDirectoryName(lookupPath))); } return(assemblyResolver); }