本文整理汇总了C#中OperationContext.ThrowIfEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# OperationContext.ThrowIfEmpty方法的具体用法?C# OperationContext.ThrowIfEmpty怎么用?C# OperationContext.ThrowIfEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OperationContext
的用法示例。
在下文中一共展示了OperationContext.ThrowIfEmpty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckCaptcha
public bool CheckCaptcha(OperationContext context, string captcha)
{
context.ThrowIfEmpty(captcha, ClientFaultCodes.ValueMissing, "captcha", "Captcha is missing.");
//Magic captch allows testers or unit tests to bypass captcha
if (captcha == _settings.MagicCaptcha)
return true;
if (_recaptchaService != null) {
string clientIp = context.WebContext == null ? null : context.WebContext.IPAddress;
_recaptchaService.Verify(captcha, clientIp); //will throw if not valid
}
return true;
}
示例2: CheckUserName
private string CheckUserName(OperationContext context, string userName)
{
context.ThrowIfEmpty(userName, ClientFaultCodes.ValueMissing, "UserName", userName, "User name may not be empty");
userName = userName.Trim().ToLowerInvariant();
context.ThrowIf(userName.Length < 3, LoginFaultCodes.UserNameTooShort, "UserName", userName, "User name is too short");
return userName;
}
示例3: CheckPasswordStrength
private void CheckPasswordStrength(OperationContext context, string password)
{
context.ThrowIfEmpty(password, ClientFaultCodes.InvalidValue, "password", "Password may not be empty.");
context.ThrowIf(password.Length > 100, ClientFaultCodes.InvalidValue, "password", "Password too long, max size: 100.");
var pwdStrength = EvaluatePasswordStrength(password);
var pwdOk = pwdStrength >= _settings.RequiredPasswordStrength;
context.ThrowIf(!pwdOk, LoginFaultCodes.WeakPassword, "Password", "Password does not meet strength criteria");
}