Skip to content

Instantly share code, notes, and snippets.

Created May 27, 2010 20:48
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 anonymous/416324 to your computer and use it in GitHub Desktop.
Save anonymous/416324 to your computer and use it in GitHub Desktop.
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