Skip to content

Instantly share code, notes, and snippets.

@rauhryan
Created June 11, 2012 15:14
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 rauhryan/2910589 to your computer and use it in GitHub Desktop.
Save rauhryan/2910589 to your computer and use it in GitHub Desktop.
// 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())
}
}
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);
}
}
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