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
static class OperatorModeExtensions | |
{ | |
static bool IsValidForUpdate(this OperatorMode mode) | |
{ | |
return mode == OperatorMode.Admin || mode == OperatorMode.Sysadmin; | |
} | |
// All users can view homepage | |
static bool CanViewHomepage(this OperatorMode mode) | |
{ |
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
static class OperatorModeExtensions | |
{ | |
static bool IsValid(this OperatorMode mode) | |
{ | |
return mode == OperatorMode.Admin || mode == OperatorMode.Sysadmin; | |
} | |
} | |
var validActions = actions.Where(a => a.Operator.IsValid()); |
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
var validActions = actions.Where(a => a.Operator == OperatorMode.Admin || a.Operator == OperatorMode.Sysadmin); |
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
enum OperatorMode | |
{ | |
Anonymous, | |
Member, | |
Operator, | |
Admin, | |
Sysadmin | |
} |
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
class Action | |
{ | |
public string ActionName { get; } | |
public OperatorMode Operator { get; } | |
} | |
List<Action> actions = getOperatorModes(); | |
var validActions = actions.Where(a => a.Operator == OperatorMode.Admin); |
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
enum OperatorMode | |
{ | |
Member, | |
Operator, | |
Admin | |
} |
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
let cb = validate 4 | |
match cb with | |
| Some x -> x() | |
| None -> -1 |
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
// Arbitrary function | |
let doValidate x = | |
x > 3 | |
// Arbitrary execution function | |
let doExecute x = 0 | |
// Validate and return function to execute | |
let validate x = | |
match doValidate x with |
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
class ObjectProcessor4Implementation : ObjectProcessor4 | |
{ | |
public bool CanProcess(DomainObject x, out Func<Result> doProcess) | |
{ | |
if (!this.Validate(x)) | |
{ | |
doProcess = null; | |
return 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
interface ObjectProcessor4 | |
{ | |
bool CanProcess(DomainObject x, out Func<Result> doProcess); | |
} | |
public Result DoProcessing4(ObjectProcessor4 processor, DomainObject x) | |
{ | |
Action doProcess; | |
if (processor.CanProcess(x, out doProcess)) | |
{ |