Created
June 11, 2012 15:14
-
-
Save rauhryan/2910589 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
// avoid duplicate primitives, use an object instead | |
// Func<string, string, bool, bool, bool> becomes Func<Foo, bool> | |
public class Foo | |
{ | |
public string ErrorMessage {get;set;} | |
public string SuccessMessage {get;set;} | |
} | |
public static bool dynamicMethodGeneration(Func<Foo, bool> success, Func<Foo, bool> onError) | |
{ | |
//dostuff | |
if(doStuff()){ | |
success(new Foo()) | |
} | |
else | |
{ | |
onError(new Foo()) | |
} | |
} |
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
dynamicMethodGeneration( | |
//normal processing lambda | |
(stringParam1, stringParam2, boolParam1, boolParam1) => | |
{ | |
Console.WriteLine(stringParam1); | |
Console.WriteLine(stringParam2); | |
return true; | |
}, | |
//error processing lambda | |
(stringParam1, stringParam2, boolParam1, boolParam1) => | |
{ | |
Console.WriteLine(stringParam1); | |
Console.WriteLine(stringParam2); | |
return false; | |
}, | |
true , false); | |
public static bool dynamicMethodGeneration(Func<String, String, bool, bool, returnBool> normalProcessing, | |
Func<String, String, bool, bool, returnBool> errorProcessing, bool error, bool normal) | |
{ | |
IWebElement returnElement = null; | |
if (error)//PROCESSING ON ERROR | |
{ | |
return errorProcessing(new String("Hello World Normal 1."), new String("Hello World Normal 2."), true, false); | |
}//NORMAL PROCESSING | |
else if (normal) | |
{ | |
return normalProcessing(new String("Hello World Error 1."), new String("Hello World Error 2."), true, false); | |
} | |
} |
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
dynamicMethodGeneration( | |
//normal processing lambda | |
(stringParam1, stringParam2, boolParam1, boolParam1) => | |
{ | |
Console.WriteLine(stringParam1); | |
Console.WriteLine(stringParam2); | |
return true; | |
}, | |
//error processing lambda | |
(stringParam1, stringParam2, boolParam1, boolParam1) => | |
{ | |
Console.WriteLine(stringParam1); | |
Console.WriteLine(stringParam2); | |
return false; | |
}, | |
true , false); | |
public static bool dynamicMethodGeneration(Func<String, String, bool, bool, returnBool> normalProcessing, | |
Func<String, String, bool, bool, returnBool> errorProcessing, bool error, bool normal) | |
{ | |
IWebElement returnElement = null; | |
if (error)//PROCESSING ON ERROR | |
{ | |
return errorProcessing(new String("Hello World Normal 1."), new String("Hello World Normal 2."), true, false); | |
}//NORMAL PROCESSING | |
else if (normal) | |
{ | |
return normalProcessing(new String("Hello World Error 1."), new String("Hello World Error 2."), true, false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment