using System.IO;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Pdb;
namespace StardewModdingAPI.Framework.ModLoading.Symbols
{
/// Reads symbol data for an assembly.
internal class SymbolReader : ISymbolReader
{
/*********
** Fields
*********/
/// The module for which to read symbols.
private readonly ModuleDefinition Module;
/// The symbol file stream.
private readonly Stream Stream;
/// The underlying symbol reader.
private ISymbolReader Reader;
/*********
** Public methods
*********/
/// Construct an instance.
/// The module for which to read symbols.
/// The symbol file stream.
public SymbolReader(ModuleDefinition module, Stream stream)
{
this.Module = module;
this.Stream = stream;
this.Reader = new NativePdbReaderProvider().GetSymbolReader(module, stream);
}
/// Get the symbol writer provider for the assembly.
public ISymbolWriterProvider GetWriterProvider()
{
return new PortablePdbWriterProvider();
}
/// Process a debug header in the symbol file.
/// The debug header.
public bool ProcessDebugHeader(ImageDebugHeader header)
{
try
{
return this.Reader.ProcessDebugHeader(header);
}
catch
{
this.Reader.Dispose();
this.Reader = new PortablePdbReaderProvider().GetSymbolReader(this.Module, this.Stream);
return this.Reader.ProcessDebugHeader(header);
}
}
/// Read the method debug information for a method in the assembly.
/// The method definition.
public MethodDebugInformation Read(MethodDefinition method)
{
return this.Reader.Read(method);
}
///
public void Dispose()
{
this.Reader.Dispose();
}
}
}