Skip to content

Instantly share code, notes, and snippets.

@KallDrexx
Last active December 30, 2016 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KallDrexx/21cbdab26f952a78d48d1938f41717f2 to your computer and use it in GitHub Desktop.
Save KallDrexx/21cbdab26f952a78d48d1938f41717f2 to your computer and use it in GitHub Desktop.
public interface IStringReader
{
IEnumerable<string> GetStrings();
}
public class InMemoryStringReader : IStringReader
{
private readonly string[] _strings;
public InMemoryStringReader(string[] strings)
{
_strings = strings;
}
public IEnumerable<string> GetStrings()
{
return _strings;
}
}
public class NetworkStringReader : IStringReader
{
private readonly TcpClient _client;
private readonly StreamReader _reader;
public NetworkStringReader(TcpClient client)
{
_client = client;
_reader = new StreamReader(client.GetStream());
}
public IEnumerable<string> GetStrings()
{
yield return _reader.ReadLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment