diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelStateDictionary.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelStateDictionary.cs
index 911a643d03..56b4b1aa97 100644
--- a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelStateDictionary.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelStateDictionary.cs
@@ -169,7 +169,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
}
}
- // Flag that indiciates if TooManyModelErrorException has already been added to this dictionary.
+ // Flag that indicates if TooManyModelErrorException has already been added to this dictionary.
private bool HasRecordedMaxModelError { get; set; }
///
@@ -625,7 +625,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
}
///
- /// Removes all keys and values from ths instance of .
+ /// Removes all keys and values from this instance of .
///
public void Clear()
{
diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelStateEntry.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelStateEntry.cs
index a4f6391bbc..5ece146fbe 100644
--- a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelStateEntry.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelStateEntry.cs
@@ -11,6 +11,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public abstract class ModelStateEntry
{
private ModelErrorCollection _errors;
+
///
/// Gets the raw value from the request associated with this entry.
///
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/BindAttribute.cs b/src/Microsoft.AspNetCore.Mvc.Core/BindAttribute.cs
index 08e80d744e..9a69dc91d9 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/BindAttribute.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/BindAttribute.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using Microsoft.AspNetCore.Mvc.Internal;
#if NETSTANDARD1_6
using System.Reflection;
#endif
@@ -83,7 +84,7 @@ namespace Microsoft.AspNetCore.Mvc
{
if (string.IsNullOrEmpty(original))
{
- return new string[0];
+ return EmptyArray.Instance;
}
var split = original.Split(',').Select(piece => piece.Trim()).Where(piece => !string.IsNullOrEmpty(piece));
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ChallengeResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/ChallengeResult.cs
index d7d73eed6e..9881c332d6 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/ChallengeResult.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/ChallengeResult.cs
@@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Mvc
/// Initializes a new instance of .
///
public ChallengeResult()
- : this(new string[] { })
+ : this(EmptyArray.Instance)
{
}
@@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Mvc
/// used to perform the authentication
/// challenge.
public ChallengeResult(AuthenticationProperties properties)
- : this(new string[] { }, properties)
+ : this(EmptyArray.Instance, properties)
{
}
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ConsumesAttribute.cs b/src/Microsoft.AspNetCore.Mvc.Core/ConsumesAttribute.cs
index 54b4d1bda0..c3c240e63e 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/ConsumesAttribute.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/ConsumesAttribute.cs
@@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Mvc
// The value used is a non default value so that it avoids getting mixed with other action constraints
// with default order.
///
- int IActionConstraint.Order { get; } = ConsumesActionConstraintOrder;
+ int IActionConstraint.Order => ConsumesActionConstraintOrder;
///
/// Gets or sets the supported request content types. Used to select an action when there would otherwise be
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterAttribute.cs b/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterAttribute.cs
index f88fd1a4c0..019f1551f3 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterAttribute.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterAttribute.cs
@@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Mvc
public int Order { get; set; }
///
- public bool IsReusable { get; } = true;
+ public bool IsReusable => true;
///
public IFilterMetadata CreateInstance(IServiceProvider serviceProvider)
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ForbidResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/ForbidResult.cs
index e831976b18..9fbcf18137 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/ForbidResult.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/ForbidResult.cs
@@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Mvc
/// Initializes a new instance of .
///
public ForbidResult()
- : this(new string[] { })
+ : this(EmptyArray.Instance)
{
}
@@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Mvc
/// used to perform the authentication
/// challenge.
public ForbidResult(AuthenticationProperties properties)
- : this(new string[] { }, properties)
+ : this(EmptyArray.Instance, properties)
{
}
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Formatters/FormatterMappings.cs b/src/Microsoft.AspNetCore.Mvc.Core/Formatters/FormatterMappings.cs
index 3d66ecf5ca..b9075b0acc 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/Formatters/FormatterMappings.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/Formatters/FormatterMappings.cs
@@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.Core;
-using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNetCore.Mvc.Formatters
@@ -18,7 +17,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
new Dictionary(StringComparer.OrdinalIgnoreCase);
///
- /// Sets mapping for the format to specified media type.
+ /// Sets mapping for the format to specified media type.
/// If the format already exists, the media type will be overwritten with the new value.
///
/// The format value.
@@ -39,7 +38,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
}
///
- /// Sets mapping for the format to specified media type.
+ /// Sets mapping for the format to specified media type.
/// If the format already exists, the media type will be overwritten with the new value.
///
/// The format value.
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ClientValidatorCache.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ClientValidatorCache.cs
index 5dcec980bc..b77470c23b 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ClientValidatorCache.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ClientValidatorCache.cs
@@ -11,8 +11,6 @@ namespace Microsoft.AspNetCore.Mvc.Internal
{
public class ClientValidatorCache
{
- private readonly IReadOnlyList EmptyArray = new IClientModelValidator[0];
-
private readonly ConcurrentDictionary _cacheEntries = new ConcurrentDictionary();
public IReadOnlyList GetValidators(ModelMetadata metadata, IClientModelValidatorProvider validatorProvider)
@@ -106,7 +104,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
if (count == 0)
{
- return EmptyArray;
+ return EmptyArray.Instance;
}
var validators = new IClientModelValidator[count];
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionInvokerCache.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionInvokerCache.cs
index a232dd09ff..70595cd7a5 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionInvokerCache.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionInvokerCache.cs
@@ -3,7 +3,6 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
-using System.Diagnostics;
using System.Linq;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
@@ -13,8 +12,6 @@ namespace Microsoft.AspNetCore.Mvc.Internal
{
public class ControllerActionInvokerCache
{
- private readonly IFilterMetadata[] EmptyFilterArray = new IFilterMetadata[0];
-
private readonly IActionDescriptorCollectionProvider _collectionProvider;
private readonly IFilterProvider[] _filterProviders;
@@ -134,7 +131,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
if (count == 0)
{
- return EmptyFilterArray;
+ return EmptyArray.Instance;
}
else
{
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/EmptyArray.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/EmptyArray.cs
new file mode 100644
index 0000000000..f8e0972989
--- /dev/null
+++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/EmptyArray.cs
@@ -0,0 +1,19 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+#if !NET451
+using System;
+#endif
+
+namespace Microsoft.AspNetCore.Mvc.Internal
+{
+ public static class EmptyArray
+ {
+ public static TElement[] Instance { get; } =
+#if NET451
+ new TElement[0];
+#else
+ Array.Empty();
+#endif
+ }
+}
\ No newline at end of file
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileResultExecutorBase.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileResultExecutorBase.cs
index 887dba2a1f..dd046cf234 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileResultExecutorBase.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileResultExecutorBase.cs
@@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
private void SetContentType(ActionContext context, FileResult result)
{
var response = context.HttpContext.Response;
- response.ContentType = result.ContentType.ToString();
+ response.ContentType = result.ContentType;
}
protected static ILogger CreateLogger(ILoggerFactory factory)
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/PrefixContainer.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/PrefixContainer.cs
index e5c8bfe12a..e984f8830b 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/PrefixContainer.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/PrefixContainer.cs
@@ -14,7 +14,6 @@ namespace Microsoft.AspNetCore.Mvc.Internal
///
public class PrefixContainer
{
- private static readonly string[] EmptyArray = new string[0];
private static readonly char[] Delimiters = new char[] { '[', '.' };
private readonly ICollection _originalValues;
@@ -31,7 +30,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
if (_originalValues.Count == 0)
{
- _sortedValues = EmptyArray;
+ _sortedValues = EmptyArray.Instance;
}
else
{
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ValidatorCache.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ValidatorCache.cs
index f1ee38da92..c41d9d3293 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ValidatorCache.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ValidatorCache.cs
@@ -11,8 +11,6 @@ namespace Microsoft.AspNetCore.Mvc.Internal
{
public class ValidatorCache
{
- private readonly IReadOnlyList EmptyArray = new IModelValidator[0];
-
private readonly ConcurrentDictionary _cacheEntries = new ConcurrentDictionary();
public IReadOnlyList GetValidators(ModelMetadata metadata, IModelValidatorProvider validatorProvider)
@@ -105,7 +103,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
if (count == 0)
{
- return EmptyArray;
+ return EmptyArray.Instance;
}
var validators = new IModelValidator[count];
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ArrayModelBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ArrayModelBinder.cs
index 584cc32b0c..670013656e 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ArrayModelBinder.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ArrayModelBinder.cs
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
+using Microsoft.AspNetCore.Mvc.Internal;
namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
{
@@ -36,7 +37,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
{
Debug.Assert(targetType == typeof(TElement[]), "GenericModelBinder only creates this binder for arrays.");
- return new TElement[0];
+ return EmptyArray.Instance;
}
///
diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs
index ce123c9276..a4a68458a2 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs
@@ -7,7 +7,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
-using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using Microsoft.Extensions.Primitives;
namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
@@ -36,7 +35,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders
{
model = new EmptyFormCollection();
}
-
+
bindingContext.Result = ModelBindingResult.Success(model);
}
diff --git a/src/Microsoft.AspNetCore.Mvc.Localization/LocalizedHtmlString.cs b/src/Microsoft.AspNetCore.Mvc.Localization/LocalizedHtmlString.cs
index f9c19bfb22..4ecc996ded 100644
--- a/src/Microsoft.AspNetCore.Mvc.Localization/LocalizedHtmlString.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Localization/LocalizedHtmlString.cs
@@ -3,9 +3,9 @@
using System;
using System.IO;
-using System.Text;
using System.Text.Encodings.Web;
using Microsoft.AspNetCore.Html;
+using Microsoft.AspNetCore.Mvc.Internal;
namespace Microsoft.AspNetCore.Mvc.Localization
{
@@ -14,11 +14,6 @@ namespace Microsoft.AspNetCore.Mvc.Localization
///
public class LocalizedHtmlString : IHtmlContent
{
-#if NETSTANDARD1_4
- private static readonly object[] EmptyArguments = Array.Empty