本文整理汇总了C#中HttpError.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# HttpError.ContainsKey方法的具体用法?C# HttpError.ContainsKey怎么用?C# HttpError.ContainsKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpError
的用法示例。
在下文中一共展示了HttpError.ContainsKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExceptionConstructorWithoutDetail_AddsCorrectDictionaryItems
public void ExceptionConstructorWithoutDetail_AddsCorrectDictionaryItems()
{
HttpError error = new HttpError(new ArgumentException("error", new Exception()), false);
Assert.Contains(new KeyValuePair<string, object>("Message", "An error has occurred."), error);
Assert.False(error.ContainsKey("ExceptionMessage"));
Assert.False(error.ContainsKey("ExceptionType"));
Assert.False(error.ContainsKey("StackTrace"));
Assert.False(error.ContainsKey("InnerException"));
}
示例2: OnActionExecuting
/// <summary>
/// Occurs before the action method is invoked.
/// </summary>
/// <param name="actionContext">The action context.</param>
public override void OnActionExecuting( HttpActionContext actionContext )
{
ModelStateDictionary modelState = actionContext.ModelState;
IEntity valueArg = null;
if ( actionContext.ActionArguments.ContainsKey( "value" ) )
{
valueArg = actionContext.ActionArguments["value"] as IEntity;
}
if ( valueArg != null )
{
Type entityType = actionContext.ActionArguments["value"].GetType();
IgnoreModelErrorsAttribute ignoreModelErrorsAttribute = entityType.GetCustomAttributes( typeof( IgnoreModelErrorsAttribute ), true ).FirstOrDefault() as IgnoreModelErrorsAttribute;
if ( ignoreModelErrorsAttribute != null )
{
foreach ( string key in ignoreModelErrorsAttribute.Keys )
{
IEnumerable<string> matchingKeys = modelState.Keys.Where( x => Regex.IsMatch( x, key ) );
foreach ( string matchingKey in matchingKeys )
{
modelState[matchingKey].Errors.Clear();
}
}
}
}
if ( !actionContext.ModelState.IsValid )
{
HttpError httpError = new HttpError();
foreach ( var item in actionContext.ModelState )
{
foreach ( ModelError error in item.Value.Errors )
{
if ( !httpError.ContainsKey( item.Key ) )
{
httpError.Add( item.Key, string.Empty );
httpError[item.Key] += error.ErrorMessage;
}
else
{
httpError[item.Key] += Environment.NewLine + error.ErrorMessage;
}
}
}
actionContext.Response = actionContext.Request.CreateErrorResponse( HttpStatusCode.BadRequest, httpError );
}
}
示例3: HttpErrors_UseCaseInsensitiveComparer
public void HttpErrors_UseCaseInsensitiveComparer(HttpError httpError)
{
var lowercaseKey = "abcd";
var uppercaseKey = "ABCD";
httpError[lowercaseKey] = "error";
Assert.True(httpError.ContainsKey(lowercaseKey));
Assert.True(httpError.ContainsKey(uppercaseKey));
}
示例4: Execute
private HttpResponseMessage Execute()
{
var httpResponseMessage = new HttpResponseMessage();
try
{
var negotiationResult = ContentNegotiator.Negotiate(typeof(HttpError), Request, Formatters);
if (negotiationResult == null)
{
httpResponseMessage.StatusCode = HttpStatusCode.NotAcceptable;
}
else
{
var error = new HttpError("Validation Failed");
foreach (var err in _exception.ValidationErrors)
{
if (!error.ContainsKey(err.ItemName))
{
error.Add(err.ItemName, new Collection<ApiError>());
}
((ICollection<ApiError>)error[err.ItemName]).Add(new ApiError
{
ErrorCode = err.ErrorCode,
Message = err.ErrorMessage
});
}
httpResponseMessage.StatusCode = HttpStatusCode.BadRequest;
httpResponseMessage.Content = new ObjectContent<HttpError>(error, negotiationResult.Formatter, negotiationResult.MediaType);
}
httpResponseMessage.RequestMessage = Request;
}
catch
{
httpResponseMessage.Dispose();
throw;
}
return httpResponseMessage;
}