| | | 1 | | using System.Diagnostics.CodeAnalysis; |
| | | 2 | | using System.Reflection; |
| | | 3 | | |
| | | 4 | | namespace NexusLabs.Needlr.Injection.Reflection.Loaders; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Assembly loader that uses reflection to discover the entry assembly. |
| | | 8 | | /// </summary> |
| | | 9 | | /// <remarks> |
| | | 10 | | /// This loader is not compatible with NativeAOT or trimming. For AOT scenarios, |
| | | 11 | | /// use GeneratedAssemblyProvider from NexusLabs.Needlr.Injection.SourceGen with the Needlr source generator instead. |
| | | 12 | | /// </remarks> |
| | | 13 | | [RequiresUnreferencedCode("ReflectionAssemblyLoader uses reflection to load assemblies. Use GeneratedAssemblyProvider fo |
| | | 14 | | public sealed class ReflectionAssemblyLoader : IAssemblyLoader |
| | | 15 | | { |
| | | 16 | | private readonly FileMatchAssemblyLoader _fileMatchAssemblyLoader; |
| | | 17 | | |
| | | 18 | | [UnconditionalSuppressMessage("SingleFile", "IL3000:Avoid accessing Assembly file path when publishing as a single f |
| | | 19 | | Justification = "This class is only used for non-AOT scenarios where Assembly.Location is available.")] |
| | 362 | 20 | | public ReflectionAssemblyLoader() |
| | | 21 | | { |
| | 362 | 22 | | var filePath = Assembly.GetEntryAssembly()?.Location ?? |
| | 362 | 23 | | throw new InvalidOperationException("Entry assembly location is null."); |
| | 362 | 24 | | var entrypointPath = Path.GetFileName(filePath); |
| | 362 | 25 | | _fileMatchAssemblyLoader = new FileMatchAssemblyLoader( |
| | 362 | 26 | | [AppDomain.CurrentDomain.BaseDirectory], |
| | 362 | 27 | | fileName => |
| | 362 | 28 | | { |
| | 17272 | 29 | | return |
| | 17272 | 30 | | fileName.Equals(entrypointPath, StringComparison.OrdinalIgnoreCase); |
| | 362 | 31 | | }); |
| | 362 | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <inheritdoc /> |
| | | 35 | | public IReadOnlyList<Assembly> LoadAssemblies(bool continueOnAssemblyError) => |
| | 282 | 36 | | _fileMatchAssemblyLoader.LoadAssemblies(continueOnAssemblyError); |
| | | 37 | | } |