Created
April 17, 2019 11:54
-
-
Save TjeuKayim/aabfbaa2278e8c1ae3f698e01dcd20b9 to your computer and use it in GitHub Desktop.
System.IO Lazy Delegation
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
public class LazyReader : TextReader | |
{ | |
private readonly Lazy<TextReader> _lazyReader; | |
public LazyReader(Lazy<TextReader> lazyReader) | |
{ | |
_lazyReader = lazyReader; | |
} | |
public object GetLifetimeService() => _lazyReader.Value.GetLifetimeService(); | |
public object InitializeLifetimeService() => _lazyReader.Value.InitializeLifetimeService(); | |
public ObjRef CreateObjRef(Type requestedType) => _lazyReader.Value.CreateObjRef(requestedType); | |
public void Close() => _lazyReader.Value.Close(); | |
public void Dispose() => _lazyReader.Value.Dispose(); | |
public int Peek() => _lazyReader.Value.Peek(); | |
public int Read() => _lazyReader.Value.Read(); | |
public int Read(char[] buffer, int index, int count) => _lazyReader.Value.Read(buffer, index, count); | |
public string ReadToEnd() => _lazyReader.Value.ReadToEnd(); | |
public int ReadBlock(char[] buffer, int index, int count) => _lazyReader.Value.ReadBlock(buffer, index, count); | |
public string ReadLine() => _lazyReader.Value.ReadLine(); | |
public Task<string> ReadLineAsync() => _lazyReader.Value.ReadLineAsync(); | |
public Task<string> ReadToEndAsync() => _lazyReader.Value.ReadToEndAsync(); | |
public Task<int> ReadAsync(char[] buffer, int index, int count) => _lazyReader.Value.ReadAsync(buffer, index, count); | |
public Task<int> ReadBlockAsync(char[] buffer, int index, int count) => _lazyReader.Value.ReadBlockAsync(buffer, index, count); | |
} |
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
public class LazyStream : Stream | |
{ | |
private readonly Lazy<Stream> _lazyStream; | |
public LazyStream(Lazy<Stream> lazyStream) | |
{ | |
_lazyStream = lazyStream; | |
} | |
public override void Flush() => _lazyStream.Value.Flush(); | |
public override long Seek(long offset, SeekOrigin origin) => _lazyStream.Value.Seek(offset, origin); | |
public override void SetLength(long value) => _lazyStream.Value.SetLength(value); | |
public override int Read(byte[] buffer, int offset, int count) => _lazyStream.Value.Read(buffer, offset, count); | |
public override void Write(byte[] buffer, int offset, int count) => _lazyStream.Value.Write(buffer, offset, count); | |
public override bool CanRead => _lazyStream.Value.CanRead; | |
public override bool CanSeek => _lazyStream.Value.CanSeek; | |
public override bool CanWrite => _lazyStream.Value.CanWrite; | |
public override long Length => _lazyStream.Value.Length; | |
public override long Position | |
{ | |
get => _lazyStream.Value.Position; | |
set => _lazyStream.Value.Position = value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment