Skip to content

anonymous /gist:416324

public class Program
{
public static void Main()
{
var reader1 = new FileFormatReader1();
var reader2 = new FileFormatReader2();
reader1.Successor = reader2;
//The building of the above could be done automatically from an ordered list of FileFormatReaders
string messageBody = "";
reader1.SetMessageBody("some file contents", ref messageBody);
}
}
public abstract class FileFormatReader {
public abstract void SetMessageBody(string fileContents, ref string body);
public FileFormatReader Successor { get; set; }
protected void ContinueWithSuccessor(string fileContents, ref string body)
{
if(Successor != null)
Successor.SetMessageBody(fileContents, ref body);
}
}
public class FileFormatReader1 : FileFormatReader
{
public override void SetMessageBody(string fileContents, ref string body)
{
if(false)
{
body = "messageBody";
}
else
{
ContinueWithSuccessor(fileContents, ref body);
}
}
}
public class FileFormatReader2 : FileFormatReader
{
public override void SetMessageBody(string fileContents, ref string body)
{
if(true)
{
body = "messageBody";
}
else
{
ContinueWithSuccessor(fileContents, ref body);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.