123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using SmartCoalApplication.Base;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SmartCoalApplication
- {
- public static class Do
- {
- public static void Test<T>(
- T value,
- Function<bool, T> testFn,
- Procedure<T> ifTrueFn,
- Procedure<T> ifFalseFn)
- {
- (testFn(value) ? ifTrueFn : ifFalseFn)(value);
- }
- public static void GenerateTest<T>(
- Function<T> generate,
- Function<bool, T> test,
- Procedure<T> ifTrue,
- Procedure<T> ifFalse)
- {
- Test(generate(), test, ifTrue, ifFalse);
- }
- public static bool TryBool(Procedure actionProcedure)
- {
- try
- {
- actionProcedure();
- return true;
- }
- catch (Exception)
- {
- return false;
- }
- }
- public static T TryCatch<T>(
- Function<T> actionFunction,
- Function<T, Exception> catchClause)
- {
- T returnVal;
- try
- {
- returnVal = actionFunction();
- }
- catch (Exception ex)
- {
- returnVal = catchClause(ex);
- }
- return returnVal;
- }
- }
- }
|