changed contract.assert to debug.assert

This commit is contained in:
Ajay Bhargav Baaskaran 2014-11-18 12:55:27 -08:00
parent f470fa6d74
commit e21f157095
28 changed files with 100 additions and 104 deletions

View File

@ -3,7 +3,7 @@
using System;
using System.Collections.Concurrent;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
@ -84,12 +84,12 @@ namespace Microsoft.AspNet.Mvc
/// </remarks>
public static Func<object, object> MakeFastPropertyGetter(PropertyInfo propertyInfo)
{
Contract.Assert(propertyInfo != null);
Debug.Assert(propertyInfo != null);
var getMethod = propertyInfo.GetMethod;
Contract.Assert(getMethod != null);
Contract.Assert(!getMethod.IsStatic);
Contract.Assert(getMethod.GetParameters().Length == 0);
Debug.Assert(getMethod != null);
Debug.Assert(!getMethod.IsStatic);
Debug.Assert(getMethod.GetParameters().Length == 0);
// Instance methods in the CLR can be turned into static methods where the first parameter
// is open over "target". This parameter is always passed by reference, so we have a code
@ -135,15 +135,15 @@ namespace Microsoft.AspNet.Mvc
/// </remarks>
public static Action<object, object> MakeFastPropertySetter(PropertyInfo propertyInfo)
{
Contract.Assert(propertyInfo != null);
Contract.Assert(!propertyInfo.DeclaringType.GetTypeInfo().IsValueType);
Debug.Assert(propertyInfo != null);
Debug.Assert(!propertyInfo.DeclaringType.GetTypeInfo().IsValueType);
var setMethod = propertyInfo.SetMethod;
Contract.Assert(setMethod != null);
Contract.Assert(!setMethod.IsStatic);
Contract.Assert(setMethod.ReturnType == typeof(void));
Debug.Assert(setMethod != null);
Debug.Assert(!setMethod.IsStatic);
Debug.Assert(setMethod.ReturnType == typeof(void));
var parameters = setMethod.GetParameters();
Contract.Assert(parameters.Length == 1);
Debug.Assert(parameters.Length == 1);
// Instance methods in the CLR can be turned into static methods where the first parameter
// is open over "target". This parameter is always passed by reference, so we have a code

View File

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.Framework.DependencyInjection;
@ -58,7 +58,7 @@ namespace Microsoft.AspNet.Mvc
// Add the cookie to the request based context.
// This is useful if the cookie needs to be reloaded in the context of the same request.
var contextAccessor = httpContext.RequestServices.GetRequiredService<IContextAccessor<AntiForgeryContext>>();
Contract.Assert(contextAccessor.Value == null, "AntiForgeryContext should be set only once per request.");
Debug.Assert(contextAccessor.Value == null, "AntiForgeryContext should be set only once per request.");
contextAccessor.SetValue(new AntiForgeryContext() { CookieToken = token });
var serializedToken = _serializer.Serialize(token);

View File

@ -2,8 +2,8 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
@ -152,7 +152,7 @@ namespace Microsoft.AspNet.Mvc
oldCookieToken = newCookieToken = _generator.GenerateCookieToken();
}
Contract.Assert(_validator.IsCookieTokenValid(oldCookieToken));
Debug.Assert(_validator.IsCookieTokenValid(oldCookieToken));
var formToken = _generator.GenerateFormToken(
httpContext,

View File

@ -4,7 +4,6 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
@ -75,7 +74,7 @@ namespace Microsoft.AspNet.Mvc
return false;
}
Contract.Assert(this._data.Length == other._data.Length);
Debug.Assert(this._data.Length == other._data.Length);
return AreByteArraysEqual(this._data, other._data);
}
@ -88,7 +87,7 @@ namespace Microsoft.AspNet.Mvc
{
// Since data should contain uniformly-distributed entropy, the
// first 32 bits can serve as the hash code.
Contract.Assert(_data != null && _data.Length >= (32 / 8));
Debug.Assert(_data != null && _data.Length >= (32 / 8));
return BitConverter.ToInt32(_data, 0);
}

View File

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Security.Claims;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core;
@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Mvc
ClaimsIdentity identity,
AntiForgeryToken cookieToken)
{
Contract.Assert(IsCookieTokenValid(cookieToken));
Debug.Assert(IsCookieTokenValid(cookieToken));
var formToken = new AntiForgeryToken()
{

View File

@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.HeaderValueAbstractions;
@ -246,7 +246,7 @@ namespace Microsoft.AspNet.Mvc.Description
else
{
// We will never call this method with templateParameter == null && parameterDescriptor == null
Contract.Assert(parameterDescriptor != null);
Debug.Assert(parameterDescriptor != null);
}
if (parameterDescription.Type != null)

View File

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Linq;
namespace System.Collections.Generic
@ -10,7 +10,7 @@ namespace System.Collections.Generic
{
public static T[] AsArray<T>(this IEnumerable<T> values)
{
Contract.Assert(values != null);
Debug.Assert(values != null);
var array = values as T[];
if (array == null)

View File

@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;
@ -110,7 +110,7 @@ namespace Microsoft.AspNet.Mvc
// pipeline.
await InvokeExceptionFilter();
Contract.Assert(_exceptionContext != null);
Debug.Assert(_exceptionContext != null);
if (_exceptionContext.Exception != null)
{
// Exception filters only run when there's an exception - unsetting it will short-circuit
@ -124,7 +124,7 @@ namespace Microsoft.AspNet.Mvc
// pipeline.
await InvokeExceptionFilter();
Contract.Assert(_exceptionContext != null);
Debug.Assert(_exceptionContext != null);
if (_exceptionContext.Exception != null)
{
// Exception filters only run when there's an exception - unsetting it will short-circuit
@ -139,21 +139,21 @@ namespace Microsoft.AspNet.Mvc
//
// 1) Call the filter (if we have an exception)
// 2) No-op (if we don't have an exception)
Contract.Assert(_exceptionContext == null);
Debug.Assert(_exceptionContext == null);
_exceptionContext = new ExceptionContext(ActionContext, _filters);
try
{
await InvokeActionAuthorizationFilters();
Contract.Assert(_authorizationContext != null);
Debug.Assert(_authorizationContext != null);
if (_authorizationContext.Result == null)
{
// Authorization passed, run authorization filters and the action
await InvokeActionMethodWithFilters();
// Action filters might 'return' an unahndled exception instead of throwing
Contract.Assert(_actionExecutedContext != null);
Debug.Assert(_actionExecutedContext != null);
if (_actionExecutedContext.Exception != null && !_actionExecutedContext.ExceptionHandled)
{
_exceptionContext.Exception = _actionExecutedContext.Exception;
@ -182,8 +182,8 @@ namespace Microsoft.AspNet.Mvc
private async Task InvokeAuthorizationFilter()
{
// We should never get here if we already have a result.
Contract.Assert(_authorizationContext != null);
Contract.Assert(_authorizationContext.Result == null);
Debug.Assert(_authorizationContext != null);
Debug.Assert(_authorizationContext.Result == null);
var current = _cursor.GetNextFilter<IAuthorizationFilter, IAsyncAuthorizationFilter>();
if (current.FilterAsync != null)
@ -223,7 +223,7 @@ namespace Microsoft.AspNet.Mvc
private async Task<ActionExecutedContext> InvokeActionMethodFilter()
{
Contract.Assert(_actionExecutingContext != null);
Debug.Assert(_actionExecutingContext != null);
if (_actionExecutingContext.Result != null)
{
// If we get here, it means that an async filter set a result AND called next(). This is forbidden.
@ -298,7 +298,7 @@ namespace Microsoft.AspNet.Mvc
_resultExecutingContext = new ResultExecutingContext(ActionContext, _filters, result);
await InvokeActionResultFilter();
Contract.Assert(_resultExecutingContext != null);
Debug.Assert(_resultExecutingContext != null);
if (_resultExecutedContext.Exception != null && !_resultExecutedContext.ExceptionHandled)
{
// There's an unhandled exception in filters
@ -315,7 +315,7 @@ namespace Microsoft.AspNet.Mvc
private async Task<ResultExecutedContext> InvokeActionResultFilter()
{
Contract.Assert(_resultExecutingContext != null);
Debug.Assert(_resultExecutingContext != null);
if (_resultExecutingContext.Cancel == true)
{
// If we get here, it means that an async filter set cancel == true AND called next().
@ -383,7 +383,7 @@ namespace Microsoft.AspNet.Mvc
{
await InvokeActionResult();
Contract.Assert(_resultExecutedContext == null);
Debug.Assert(_resultExecutedContext == null);
_resultExecutedContext = new ResultExecutedContext(
_resultExecutingContext,
_filters,

View File

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.DependencyInjection;
@ -97,8 +97,8 @@ namespace Microsoft.AspNet.Mvc.Filters
private void ApplyFilterToContainer(object actualFilter, IFilter filterMetadata)
{
Contract.Assert(actualFilter != null, "actualFilter should not be null");
Contract.Assert(filterMetadata != null, "filterMetadata should not be null");
Debug.Assert(actualFilter != null, "actualFilter should not be null");
Debug.Assert(filterMetadata != null, "filterMetadata should not be null");
var container = actualFilter as IFilterContainer;

View File

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core;
@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Mvc
// users understand they should call the per request scoped middleware
// or set HttpContext.Services manually
var services = context.HttpContext.RequestServices;
Contract.Assert(services != null);
Debug.Assert(services != null);
// Verify if AddMvc was done before calling UseMvc
// We use the MvcMarkerService to make sure if all the services were added.
@ -92,7 +92,7 @@ namespace Microsoft.AspNet.Mvc
private async Task InvokeActionAsync(RouteContext context, ActionDescriptor actionDescriptor)
{
var services = context.HttpContext.RequestServices;
Contract.Assert(services != null);
Debug.Assert(services != null);
var actionContext = new ActionContext(context.HttpContext, context.RouteData, actionDescriptor);

View File

@ -4,7 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Net;
@ -96,7 +96,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
if (metadata != null)
{
// CheckBoxFor() case. That API does not support passing isChecked directly.
Contract.Assert(!isChecked.HasValue);
Debug.Assert(!isChecked.HasValue);
if (metadata.Model != null)
{
@ -312,10 +312,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
else
{
// RadioButtonFor() case. That API does not support passing isChecked directly.
Contract.Assert(!isChecked.HasValue);
Debug.Assert(!isChecked.HasValue);
// Need a value to determine isChecked.
Contract.Assert(value != null);
Debug.Assert(value != null);
var model = metadata.Model;
var valueString = Convert.ToString(value, CultureInfo.CurrentCulture);

View File

@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using Microsoft.AspNet.Mvc.Internal.DecisionTree;
namespace Microsoft.AspNet.Mvc.Routing
@ -73,7 +73,7 @@ namespace Microsoft.AspNet.Mvc.Routing
}
else if (hasNonCatchAll)
{
Contract.Assert(filtered != null);
Debug.Assert(filtered != null);
filtered.Add(action);
}
else

View File

@ -3,7 +3,6 @@
using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Linq;
using Microsoft.AspNet.Routing.Template;
@ -25,7 +24,7 @@ namespace Microsoft.AspNet.Mvc.Routing
var segment = template.Segments[i];
var digit = ComputeDigit(segment);
Contract.Assert(digit >= 0 && digit < 10);
Debug.Assert(digit >= 0 && digit < 10);
precedence += Decimal.Divide(digit, (decimal)Math.Pow(10, i));
}

View File

@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Linq;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Routing;
@ -153,7 +153,7 @@ namespace Microsoft.AspNet.Mvc
private string GenerateUrl(string protocol, string host, string path, string fragment)
{
// We should have a robust and centrallized version of this code. See HttpAbstractions#28
Contract.Assert(path != null);
Debug.Assert(path != null);
var url = path;
if (!string.IsNullOrEmpty(fragment))

View File

@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Microsoft.AspNet.Mvc.Core;
@ -81,7 +81,7 @@ namespace Microsoft.AspNet.Mvc
Type = typeInfo.AsType(),
};
Contract.Assert(!string.IsNullOrEmpty(candidate.FullName));
Debug.Assert(!string.IsNullOrEmpty(candidate.FullName));
var separatorIndex = candidate.FullName.LastIndexOf(".");
if (separatorIndex >= 0)
{

View File

@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.ModelBinding.Internal;
@ -90,9 +90,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
Type openBinderType,
Type modelType)
{
Contract.Assert(supportedInterfaceType != null);
Contract.Assert(openBinderType != null);
Contract.Assert(modelType != null);
Debug.Assert(supportedInterfaceType != null);
Debug.Assert(openBinderType != null);
Debug.Assert(modelType != null);
var modelTypeArguments = GetGenericBinderTypeArgs(supportedInterfaceType, modelType);

View File

@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Diagnostics;
namespace Microsoft.AspNet.Mvc.ModelBinding.Internal
{
@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Internal
/// </summary>
public static T[] ToArrayWithoutNulls<T>(this ICollection<T> collection) where T : class
{
Contract.Assert(collection != null);
Debug.Assert(collection != null);
var result = new T[collection.Count];
var count = 0;

View File

@ -4,7 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using Microsoft.AspNet.Mvc.ModelBinding.Internal;
@ -210,7 +210,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
private static Type GetElementType(Type type)
{
Contract.Assert(typeof(IEnumerable).IsAssignableFrom(type));
Debug.Assert(typeof(IEnumerable).IsAssignableFrom(type));
if (type.IsArray)
{
return type.GetElementType();

View File

@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Globalization;
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
@ -85,7 +85,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{
if (_values == null)
{
Contract.Assert(_valuesFactory != null);
Debug.Assert(_valuesFactory != null);
_values = await _valuesFactory();
}

View File

@ -23,7 +23,6 @@
"dependencies": {
"System.Collections.Concurrent": "4.0.10-beta-*",
"System.ComponentModel.TypeConverter": "4.0.0-beta-*",
"System.Diagnostics.Contracts": "4.0.0-beta-*",
"System.Reflection.TypeExtensions": "4.0.0-beta-*",
"System.Runtime.Serialization.Primitives": "4.0.0-beta-*",
"System.Runtime.Serialization.Xml": "4.0.10-beta-*",

View File

@ -19,7 +19,6 @@
"aspnetcore50": {
"dependencies": {
"System.Collections.Concurrent": "4.0.10-beta-*",
"System.Diagnostics.Contracts": "4.0.0-beta-*",
"Microsoft.Framework.Runtime.Interfaces": { "version": "1.0.0-*", "type": "build" }
}
}

View File

@ -4,7 +4,7 @@
#if ASPNETCORE50
using System.Collections.ObjectModel;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Linq;
namespace System.Collections.Generic
@ -19,7 +19,7 @@ namespace System.Collections.Generic
/// </summary>
public static T[] AppendAndReallocate<T>(this T[] array, T value)
{
Contract.Assert(array != null);
Debug.Assert(array != null);
int originalLength = array.Length;
T[] newArray = new T[originalLength + 1];
@ -34,7 +34,7 @@ namespace System.Collections.Generic
/// </summary>
public static T[] AsArray<T>(this IEnumerable<T> values)
{
Contract.Assert(values != null);
Debug.Assert(values != null);
T[] array = values as T[];
if (array == null)
@ -50,7 +50,7 @@ namespace System.Collections.Generic
/// </summary>
public static Collection<T> AsCollection<T>(this IEnumerable<T> enumerable)
{
Contract.Assert(enumerable != null);
Debug.Assert(enumerable != null);
Collection<T> collection = enumerable as Collection<T>;
if (collection != null)
@ -71,7 +71,7 @@ namespace System.Collections.Generic
/// </summary>
public static IList<T> AsIList<T>(this IEnumerable<T> enumerable)
{
Contract.Assert(enumerable != null);
Debug.Assert(enumerable != null);
IList<T> list = enumerable as IList<T>;
if (list != null)
@ -87,7 +87,7 @@ namespace System.Collections.Generic
/// </summary>
public static List<T> AsList<T>(this IEnumerable<T> enumerable)
{
Contract.Assert(enumerable != null);
Debug.Assert(enumerable != null);
List<T> list = enumerable as List<T>;
if (list != null)
@ -107,8 +107,8 @@ namespace System.Collections.Generic
/// </summary>
public static void RemoveFrom<T>(this List<T> list, int start)
{
Contract.Assert(list != null);
Contract.Assert(start >= 0 && start <= list.Count);
Debug.Assert(list != null);
Debug.Assert(start >= 0 && start <= list.Count);
list.RemoveRange(start, list.Count - start);
}
@ -118,8 +118,8 @@ namespace System.Collections.Generic
/// </summary>
public static T SingleDefaultOrError<T, TArg1>(this IList<T> list, Action<TArg1> errorAction, TArg1 errorArg1)
{
Contract.Assert(list != null);
Contract.Assert(errorAction != null);
Debug.Assert(list != null);
Debug.Assert(errorAction != null);
switch (list.Count)
{
@ -142,8 +142,8 @@ namespace System.Collections.Generic
/// </summary>
public static TMatch SingleOfTypeDefaultOrError<TInput, TMatch, TArg1>(this IList<TInput> list, Action<TArg1> errorAction, TArg1 errorArg1) where TMatch : class
{
Contract.Assert(list != null);
Contract.Assert(errorAction != null);
Debug.Assert(list != null);
Debug.Assert(errorAction != null);
TMatch result = null;
for (int i = 0; i < list.Count; i++)
@ -170,7 +170,7 @@ namespace System.Collections.Generic
/// </summary>
public static T[] ToArrayWithoutNulls<T>(this ICollection<T> collection) where T : class
{
Contract.Assert(collection != null);
Debug.Assert(collection != null);
T[] result = new T[collection.Count];
int count = 0;
@ -199,8 +199,8 @@ namespace System.Collections.Generic
/// </summary>
public static Dictionary<TKey, TValue> ToDictionaryFast<TKey, TValue>(this TValue[] array, Func<TValue, TKey> keySelector, IEqualityComparer<TKey> comparer)
{
Contract.Assert(array != null);
Contract.Assert(keySelector != null);
Debug.Assert(array != null);
Debug.Assert(keySelector != null);
Dictionary<TKey, TValue> dictionary = new Dictionary<TKey, TValue>(array.Length, comparer);
for (int i = 0; i < array.Length; i++)
@ -216,8 +216,8 @@ namespace System.Collections.Generic
/// </summary>
public static Dictionary<TKey, TValue> ToDictionaryFast<TKey, TValue>(this IList<TValue> list, Func<TValue, TKey> keySelector, IEqualityComparer<TKey> comparer)
{
Contract.Assert(list != null);
Contract.Assert(keySelector != null);
Debug.Assert(list != null);
Debug.Assert(keySelector != null);
TValue[] array = list as TValue[];
if (array != null)
@ -232,8 +232,8 @@ namespace System.Collections.Generic
/// </summary>
public static Dictionary<TKey, TValue> ToDictionaryFast<TKey, TValue>(this IEnumerable<TValue> enumerable, Func<TValue, TKey> keySelector, IEqualityComparer<TKey> comparer)
{
Contract.Assert(enumerable != null);
Contract.Assert(keySelector != null);
Debug.Assert(enumerable != null);
Debug.Assert(keySelector != null);
TValue[] array = enumerable as TValue[];
if (array != null)
@ -258,8 +258,8 @@ namespace System.Collections.Generic
/// </summary>
private static Dictionary<TKey, TValue> ToDictionaryFastNoCheck<TKey, TValue>(IList<TValue> list, Func<TValue, TKey> keySelector, IEqualityComparer<TKey> comparer)
{
Contract.Assert(list != null);
Contract.Assert(keySelector != null);
Debug.Assert(list != null);
Debug.Assert(keySelector != null);
int listCount = list.Count;
Dictionary<TKey, TValue> dictionary = new Dictionary<TKey, TValue>(listCount, comparer);

View File

@ -5,7 +5,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
@ -451,7 +451,7 @@ namespace System.Net.Http.Formatting
private static MediaTypeFormatter[] GetWritingFormatters(IEnumerable<MediaTypeFormatter> formatters)
{
Contract.Assert(formatters != null);
Debug.Assert(formatters != null);
MediaTypeFormatterCollection formatterCollection = formatters as MediaTypeFormatterCollection;
return formatters.AsArray();
}

View File

@ -6,7 +6,7 @@
using Microsoft.AspNet.Mvc;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Linq;
using System.Net.Http.Headers;
@ -49,7 +49,7 @@ namespace System.Net.Http.Formatting
public static bool IsSubsetOf(this MediaTypeHeaderValue mediaType1, MediaTypeHeaderValue mediaType2, out MediaTypeHeaderValueRange mediaType2Range)
{
// Performance-sensitive
Contract.Assert(mediaType1 != null);
Debug.Assert(mediaType1 != null);
if (mediaType2 == null)
{

View File

@ -4,7 +4,7 @@
#if ASPNETCORE50
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Net.Http.Headers;
namespace System.Net.Http.Formatting
@ -38,8 +38,8 @@ namespace System.Net.Http.Formatting
/// <returns></returns>
public int Compare(MediaTypeWithQualityHeaderValue mediaType1, MediaTypeWithQualityHeaderValue mediaType2)
{
Contract.Assert(mediaType1 != null, "The 'mediaType1' parameter should not be null.");
Contract.Assert(mediaType2 != null, "The 'mediaType2' parameter should not be null.");
Debug.Assert(mediaType1 != null, "The 'mediaType1' parameter should not be null.");
Debug.Assert(mediaType2 != null, "The 'mediaType2' parameter should not be null.");
if (Object.ReferenceEquals(mediaType1, mediaType2))
{
@ -90,8 +90,8 @@ namespace System.Net.Http.Formatting
private static int CompareBasedOnQualityFactor(MediaTypeWithQualityHeaderValue mediaType1, MediaTypeWithQualityHeaderValue mediaType2)
{
Contract.Assert(mediaType1 != null);
Contract.Assert(mediaType2 != null);
Debug.Assert(mediaType1 != null);
Debug.Assert(mediaType2 != null);
double mediaType1Quality = mediaType1.Quality ?? FormattingUtilities.Match;
double mediaType2Quality = mediaType2.Quality ?? FormattingUtilities.Match;

View File

@ -3,7 +3,7 @@
#if ASPNETCORE50
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Net.Http.Headers;
namespace System.Net.Http.Formatting
@ -21,10 +21,10 @@ namespace System.Net.Http.Formatting
public ParsedMediaTypeHeaderValue(MediaTypeHeaderValue mediaTypeHeaderValue)
{
Contract.Assert(mediaTypeHeaderValue != null);
Debug.Assert(mediaTypeHeaderValue != null);
string mediaType = _mediaType = mediaTypeHeaderValue.MediaType;
_delimiterIndex = mediaType.IndexOf(MediaTypeSubtypeDelimiter);
Contract.Assert(_delimiterIndex > 0, "The constructor of the MediaTypeHeaderValue would have failed if there wasn't a type and subtype.");
Debug.Assert(_delimiterIndex > 0, "The constructor of the MediaTypeHeaderValue would have failed if there wasn't a type and subtype.");
_isAllMediaRange = false;
_isSubtypeMediaRange = false;

View File

@ -4,7 +4,7 @@
#if ASPNETCORE50
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Net.Http.Headers;
namespace System.Net.Http.Formatting
@ -43,8 +43,8 @@ namespace System.Net.Http.Formatting
public int Compare(StringWithQualityHeaderValue stringWithQuality1,
StringWithQualityHeaderValue stringWithQuality2)
{
Contract.Assert(stringWithQuality1 != null);
Contract.Assert(stringWithQuality2 != null);
Debug.Assert(stringWithQuality1 != null);
Debug.Assert(stringWithQuality2 != null);
double quality1 = stringWithQuality1.Quality ?? FormattingUtilities.Match;
double quality2 = stringWithQuality2.Quality ?? FormattingUtilities.Match;

View File

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Net.Http;
using Microsoft.AspNet.Http;
@ -60,7 +60,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
if (!message.Headers.TryAddWithoutValidation(header.Key, header.Value))
{
var added = message.Content.Headers.TryAddWithoutValidation(header.Key, header.Value);
Contract.Assert(added);
Debug.Assert(added);
}
}