S
Shapper
Hello,
I am trying to do the following:
MyObject.If(x => x.ID == 10, new MyAction("ID10")).If(x => x.Value < 20, new MyAction("Value20")).DoSomethingWithMyAction();
MyObject is an object with a few properties which I need to check ...
DoSomethingWithMyAction() is a MyAction extension that does something with the MyAction of the first condition that fails.
It could be something like:
public static If<T>(this T myobject, Func<T, Boolean> predicate, MyAction action) where T : MyObject {
if (predicate(myobject)
// Return ??? >> Move to Next If
else
// Return action
} // If
Then DoSomethingWithMyAction() would simply be a MyAction extension.
My problems are:
1 - How to chain the IFs;
2 - How to make DoSomethingWithMyAction() use the MyAction of the first IF to fail.
Thank You,
Miguel
I am trying to do the following:
MyObject.If(x => x.ID == 10, new MyAction("ID10")).If(x => x.Value < 20, new MyAction("Value20")).DoSomethingWithMyAction();
MyObject is an object with a few properties which I need to check ...
DoSomethingWithMyAction() is a MyAction extension that does something with the MyAction of the first condition that fails.
It could be something like:
public static If<T>(this T myobject, Func<T, Boolean> predicate, MyAction action) where T : MyObject {
if (predicate(myobject)
// Return ??? >> Move to Next If
else
// Return action
} // If
Then DoSomethingWithMyAction() would simply be a MyAction extension.
My problems are:
1 - How to chain the IFs;
2 - How to make DoSomethingWithMyAction() use the MyAction of the first IF to fail.
Thank You,
Miguel