Created
May 27, 2010 20:48
-
-
Save anonymous/416324 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
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