Created
December 12, 2024 08:33
-
-
Save lostmsu/e3fb9fe2c4cc3eed6c11fdab0a167cd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Obsolete("workaround for https://github.com/microsoft/vs-streamjsonrpc/issues/1084")] | |
public sealed class StreamCloseNoExceptionWorkaround: Stream { | |
readonly Stream wrapped; | |
readonly ILogger log; | |
public StreamCloseNoExceptionWorkaround(Stream wrapped, ILogger log) { | |
this.wrapped = wrapped ?? throw new ArgumentNullException(nameof(wrapped)); | |
this.log = log ?? throw new ArgumentNullException(nameof(log)); | |
} | |
protected override void Dispose(bool disposing) { | |
try { | |
this.wrapped.Dispose(); | |
base.Dispose(disposing); | |
} catch (Exception e) { | |
this.log.LogDebug(e, "Error disposing stream"); | |
} | |
} | |
public override void Flush() => this.wrapped.Flush(); | |
public override int Read(byte[] buffer, int offset, int count) | |
=> this.wrapped.Read(buffer, offset, count); | |
public override long Seek(long offset, SeekOrigin origin) => this.wrapped.Seek(offset, origin); | |
public override void SetLength(long value) => this.wrapped.SetLength(value); | |
public override void Write(byte[] buffer, int offset, int count) | |
=> this.wrapped.Write(buffer, offset, count); | |
public override bool CanRead => this.wrapped.CanRead; | |
public override bool CanSeek => this.wrapped.CanSeek; | |
public override bool CanWrite => this.wrapped.CanWrite; | |
public override long Length => this.wrapped.Length; | |
public override long Position { | |
get => this.wrapped.Position; | |
set => this.wrapped.Position = value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment