ResOkIf(Boolean, String) Method
Returns back the Err if this is Err.
Otherwise, returns Ok if
okCondition holds; Err if it does not hold.
Especially useful in fluent input validation.
static Res<User> Login(string username, string passwordHash)
{
return OkIf(!string.IsNullOrEmpty(username)) // validate username
.OkIf(!string.IsNullOrEmpty(passwordHash)) // validate password-hash
.OkIf(userRepo.ContainsKey(username)) // further validate user
.Map(() => GetUser(username, password)); // finally map into actual result;
// any Err in validation steps will directly be mapped to Err, avoiding GetUser call.
}
Namespace: Orx.Fun.ResultAssembly: Orx.Fun.Result (in Orx.Fun.Result.dll) Version: 1.3.0+344c8bdd6f720ccfb2d8db7c61b76cf02be18f5f
public Res OkIf(
bool okCondition,
string strOkCondition = ""
)
- okCondition Boolean
- Condition that should hold to get an Ok, rather than Err.
- strOkCondition String (Optional)
- Name of the condition; to be appended to the error message if it does not hold. Omitting the argument will automatically be filled with the condition's expression in the caller side.
Res