diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-08-25 20:01:59 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-08-25 20:01:59 -0400 |
commit | 0b29eb3bc37553aa2e9776e17727ba07018606ea (patch) | |
tree | bb16cc4f680d04fda9db53ea22b818c2858e616f /src/SMAPI/Framework/ModLoading/Symbols/SymbolReaderProvider.cs | |
parent | e3b38a70f8d710af07732b325a6013ed18aa0fb0 (diff) | |
download | SMAPI-0b29eb3bc37553aa2e9776e17727ba07018606ea.tar.gz SMAPI-0b29eb3bc37553aa2e9776e17727ba07018606ea.tar.bz2 SMAPI-0b29eb3bc37553aa2e9776e17727ba07018606ea.zip |
minor refactoring in new symbol code
Diffstat (limited to 'src/SMAPI/Framework/ModLoading/Symbols/SymbolReaderProvider.cs')
-rw-r--r-- | src/SMAPI/Framework/ModLoading/Symbols/SymbolReaderProvider.cs | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/src/SMAPI/Framework/ModLoading/Symbols/SymbolReaderProvider.cs b/src/SMAPI/Framework/ModLoading/Symbols/SymbolReaderProvider.cs index e2a6d21e..02a70f1c 100644 --- a/src/SMAPI/Framework/ModLoading/Symbols/SymbolReaderProvider.cs +++ b/src/SMAPI/Framework/ModLoading/Symbols/SymbolReaderProvider.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using Mono.Cecil; @@ -5,31 +6,48 @@ using Mono.Cecil.Cil; namespace StardewModdingAPI.Framework.ModLoading.Symbols { + /// <summary>Provides assembly symbol readers for Mono.Cecil.</summary> internal class SymbolReaderProvider : ISymbolReaderProvider { + /********* + ** Fields + *********/ + /// <summary>The underlying symbol reader provider.</summary> private readonly ISymbolReaderProvider BaseProvider = new DefaultSymbolReaderProvider(); - private readonly Dictionary<string, Stream> SymbolMapping = new Dictionary<string, Stream>(); + /// <summary>The symbol data loaded by absolute assembly path.</summary> + private readonly Dictionary<string, Stream> SymbolsByAssemblyPath = new Dictionary<string, Stream>(StringComparer.OrdinalIgnoreCase); - public void AddSymbolMapping( string dllName, Stream symbolStream ) + + /********* + ** Public methods + *********/ + /// <summary>Add the symbol file for a given assembly name, if it's not already registered.</summary> + /// <param name="fileName">The assembly file name.</param> + /// <param name="symbolStream">The raw file stream for the symbols.</param> + public void AddSymbolData(string fileName, Stream symbolStream) { - this.SymbolMapping.Add( dllName, symbolStream ); + this.SymbolsByAssemblyPath.Add(fileName, symbolStream); } - public ISymbolReader GetSymbolReader( ModuleDefinition module, string fileName ) + /// <summary>Get a symbol reader for a given module and assembly name.</summary> + /// <param name="module">The loaded assembly module.</param> + /// <param name="fileName">The assembly file name.</param> + public ISymbolReader GetSymbolReader(ModuleDefinition module, string fileName) { - if ( this.SymbolMapping.ContainsKey( module.Name ) ) - return new SymbolReader( module, this.SymbolMapping[ module.Name ] ); - - return this.BaseProvider.GetSymbolReader( module, fileName ); + return this.SymbolsByAssemblyPath.TryGetValue(module.Name, out Stream symbolData) + ? new SymbolReader(module, symbolData) + : this.BaseProvider.GetSymbolReader(module, fileName); } - public ISymbolReader GetSymbolReader( ModuleDefinition module, Stream symbolStream ) + /// <summary>Get a symbol reader for a given module and symbol stream.</summary> + /// <param name="module">The loaded assembly module.</param> + /// <param name="symbolStream">The loaded symbol file stream.</param> + public ISymbolReader GetSymbolReader(ModuleDefinition module, Stream symbolStream) { - if ( this.SymbolMapping.ContainsKey( module.Name ) ) - return new SymbolReader( module, this.SymbolMapping[ module.Name ] ); - - return this.BaseProvider.GetSymbolReader( module, symbolStream ); + return this.SymbolsByAssemblyPath.TryGetValue(module.Name, out Stream symbolData) + ? new SymbolReader(module, symbolData) + : this.BaseProvider.GetSymbolReader(module, symbolStream); } } } |