From c27b07ef3f8b07dfe1d1de38a8d7bf2d6a9298f4 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 9 Jun 2017 20:57:33 -0700 Subject: [PATCH] Use C# 7 features --- .../ActionConstraints/ActionConstraintItem.cs | 2 +- .../ActionConstraintProviderContext.cs | 4 +- .../ApiDescriptionProviderContext.cs | 4 +- .../Filters/FilterDescriptor.cs | 4 +- .../ModelBinding/BindingInfo.cs | 8 +- .../ModelBinding/EnumGroupAndName.cs | 10 +- .../ModelBinding/ModelError.cs | 4 +- .../ModelBinding/ModelMetadata.cs | 14 +- .../ModelBinding/ModelStateDictionary.cs | 5 +- .../ClientValidatorProviderContext.cs | 8 +- .../Validation/ModelValidationResult.cs | 4 +- .../ModelValidatorProviderContext.cs | 8 +- .../Validation/ValidationStateDictionary.cs | 61 ++--- .../ModelBinding/ValueProviderResult.cs | 12 +- .../ApiDescriptionGroup.cs | 4 +- .../ApiDescriptionGroupCollection.cs | 4 +- .../DefaultApiDescriptionProvider.cs | 8 +- .../AcceptVerbsAttribute.cs | 24 +- .../AcceptedResult.cs | 14 +- .../ActionNameAttribute.cs | 2 +- .../ApplicationModels/ApplicationModel.cs | 4 +- .../ApplicationModels/AttributeRouteModel.cs | 12 +- .../ApplicationModels/ParameterModel.cs | 2 +- .../Authorization/AuthorizeFilter.cs | 2 +- .../BindAttribute.cs | 8 +- .../ControllerBase.cs | 48 +--- .../Controllers/DefaultControllerFactory.cs | 8 +- .../CreatedResult.cs | 5 +- .../ApplicationModelConventionExtensions.cs | 6 +- .../FileContentResult.cs | 5 +- .../FileStreamResult.cs | 5 +- .../Formatters/FormatFilter.cs | 3 +- .../Formatters/MediaType.cs | 36 ++- .../FromBodyAttribute.cs | 2 +- .../FromFormAttribute.cs | 2 +- .../FromHeaderAttribute.cs | 2 +- .../FromQueryAttribute.cs | 2 +- .../FromRouteAttribute.cs | 2 +- .../ActionDescriptorCollection.cs | 4 +- .../Internal/AcceptHeaderParser.cs | 3 +- .../Internal/ActionConstraintCache.cs | 3 +- .../Internal/ActionSelector.cs | 8 +- .../AuthorizationApplicationModelProvider.cs | 2 +- .../Internal/ClientValidatorCache.cs | 3 +- .../ControllerActionDescriptorBuilder.cs | 4 +- .../ControllerActionDescriptorProvider.cs | 9 +- .../Internal/CopyOnWriteList.cs | 34 +-- .../DefaultActionConstraintProvider.cs | 5 +- .../DefaultApplicationModelProvider.cs | 11 +- .../DefaultBindingMetadataProvider.cs | 8 +- .../DefaultCollectionValidationStrategy.cs | 16 +- .../DefaultComplexObjectValidationStrategy.cs | 16 +- .../Internal/DefaultFilterProvider.cs | 5 +- ...plicitIndexCollectionValidationStrategy.cs | 16 +- .../Internal/FilterDescriptorOrderComparer.cs | 7 +- .../Internal/HttpMethodActionConstraint.cs | 13 +- .../Internal/HttpTokenParsingRules.cs | 17 +- .../Internal/MvcAttributeRouteHandler.cs | 8 +- .../Internal/MvcCoreLoggerExtensions.cs | 8 +- .../Internal/MvcRouteHandler.cs | 10 +- .../Internal/NonDisposableStream.cs | 31 +-- .../Internal/ReferenceEqualityComparer.cs | 10 +- .../ShortFormDictionaryValidationStrategy.cs | 16 +- .../LocalRedirectResult.cs | 5 +- .../Binders/CollectionModelBinder.cs | 4 +- .../Binders/ComplexTypeModelBinder.cs | 2 +- .../Binders/FormCollectionModelBinder.cs | 50 +--- .../ModelBinding/BindingBehaviorAttribute.cs | 2 +- .../DefaultPropertyFilterProvider.cs | 16 +- .../ModelBinding/FormValueProvider.cs | 10 +- .../Internal/ModelBindingHelper.cs | 12 +- .../ModelBinding/Metadata/BindingMetadata.cs | 5 +- .../Metadata/DefaultModelMetadata.cs | 216 +++--------------- .../Metadata/DefaultModelMetadataProvider.cs | 4 +- .../ModelBinding/QueryStringValueProvider.cs | 10 +- .../Validation/ValidationVisitor.cs | 3 +- .../MvcOptions.cs | 2 +- .../PhysicalFileResult.cs | 5 +- .../RedirectResult.cs | 5 +- .../ResponseCacheAttribute.cs | 30 +-- .../RouteAttribute.cs | 10 +- .../Routing/HttpMethodAttribute.cs | 21 +- .../Routing/KnownRouteValueConstraint.cs | 4 +- .../StatusCodeResult.cs | 2 +- .../CorsAuthorizationFilter.cs | 17 +- .../Internal/CorsApplicationModelProvider.cs | 9 +- .../CorsAuthorizationFilterFactory.cs | 12 +- .../DisableCorsAuthorizationFilter.cs | 12 +- .../DataAnnotationsMetadataProvider.cs | 2 +- .../Internal/JsonResultExecutor.cs | 6 +- .../JsonInputFormatter.cs | 9 +- .../JsonPatchOperationsArrayProvider.cs | 5 +- .../DelegatingEnumerator.cs | 8 +- .../SerializableErrorWrapperProvider.cs | 8 +- ...XmlDataContractSerializerInputFormatter.cs | 17 +- ...mlDataContractSerializerOutputFormatter.cs | 7 +- .../XmlSerializerInputFormatter.cs | 13 +- .../XmlSerializerOutputFormatter.cs | 5 +- .../HelperResult.cs | 5 +- .../Internal/RazorViewCompiler.cs | 2 +- .../LanguageViewLocationExpander.cs | 5 +- .../RazorPage.cs | 5 +- .../RazorPageOfT.cs | 8 +- .../RazorView.cs | 5 +- .../RazorViewEngine.cs | 3 +- .../RazorViewEngineOptions.cs | 6 +- .../TagHelpers/TagHelperComponentTagHelper.cs | 5 +- .../TagHelpers/UrlResolutionTagHelper.cs | 8 +- .../Filters/PageHandlerExecutedContext.cs | 16 +- .../Filters/PageHandlerExecutingContext.cs | 9 +- .../Filters/PageHandlerSelectedContext.cs | 9 +- .../PageBase.cs | 8 +- .../PageContext.cs | 15 +- .../AnchorTagHelper.cs | 8 +- .../CacheTagHelper.cs | 4 +- .../CacheTagHelperBase.cs | 8 +- .../ImageTagHelper.cs | 8 +- .../InputTagHelper.cs | 8 +- .../Internal/FileProviderGlobbingDirectory.cs | 16 +- .../LabelTagHelper.cs | 8 +- .../LinkTagHelper.cs | 8 +- .../OptionTagHelper.cs | 8 +- .../ScriptTagHelper.cs | 8 +- .../SelectTagHelper.cs | 8 +- .../TextAreaTagHelper.cs | 8 +- .../ValidationMessageTagHelper.cs | 8 +- .../ValidationSummaryTagHelper.cs | 13 +- .../Internal/HtmlAttributePropertyHelper.cs | 5 +- .../MvcViewFeaturesLoggerExtensions.cs | 10 +- .../Internal/SaveTempDataFilter.cs | 3 +- .../TempDataProperty.cs | 4 +- .../Internal/TempDataSerializer.cs | 9 +- .../Internal/ValidationHelpers.cs | 3 +- .../Internal/ViewBuffer.cs | 18 +- .../Internal/ViewComponentResultExecutor.cs | 6 +- .../Internal/ViewResultExecutor.cs | 6 +- .../MvcViewOptions.cs | 2 +- .../RemoteAttribute.cs | 2 +- .../Rendering/MultiSelectList.cs | 12 +- .../Rendering/SelectList.cs | 2 +- .../Rendering/ViewContext.cs | 2 +- .../ViewComponent.cs | 64 +----- .../ViewEngines/ViewEngineResult.cs | 5 +- .../ViewFeatures/AttributeDictionary.cs | 92 ++------ .../ViewFeatures/HtmlHelper.cs | 47 +--- .../ViewFeatures/HtmlHelperOptions.cs | 5 +- .../ViewFeatures/ModelExpression.cs | 18 +- .../ViewFeatures/TempDataDictionary.cs | 9 +- .../ViewFeatures/ViewDataDictionary.cs | 2 +- .../ViewFeatures/ViewDataInfo.cs | 4 +- 150 files changed, 375 insertions(+), 1358 deletions(-) diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/ActionConstraints/ActionConstraintItem.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/ActionConstraints/ActionConstraintItem.cs index 319cacc55a..7022a8f283 100644 --- a/src/Microsoft.AspNetCore.Mvc.Abstractions/ActionConstraints/ActionConstraintItem.cs +++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/ActionConstraints/ActionConstraintItem.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Mvc.ActionConstraints /// /// The instance. /// - public IActionConstraintMetadata Metadata { get; private set; } + public IActionConstraintMetadata Metadata { get; } /// /// Gets or sets a value indicating whether or not can be reused across requests. diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/ActionConstraints/ActionConstraintProviderContext.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/ActionConstraints/ActionConstraintProviderContext.cs index 5618cfe2b5..d740257203 100644 --- a/src/Microsoft.AspNetCore.Mvc.Abstractions/ActionConstraints/ActionConstraintProviderContext.cs +++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/ActionConstraints/ActionConstraintProviderContext.cs @@ -52,11 +52,11 @@ namespace Microsoft.AspNetCore.Mvc.ActionConstraints /// /// The for which constraints are being created. /// - public ActionDescriptor Action { get; private set; } + public ActionDescriptor Action { get; } /// /// The list of objects. /// - public IList Results { get; private set; } + public IList Results { get; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/ApiExplorer/ApiDescriptionProviderContext.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/ApiExplorer/ApiDescriptionProviderContext.cs index dfe6d3f347..aa9d199089 100644 --- a/src/Microsoft.AspNetCore.Mvc.Abstractions/ApiExplorer/ApiDescriptionProviderContext.cs +++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/ApiExplorer/ApiDescriptionProviderContext.cs @@ -31,11 +31,11 @@ namespace Microsoft.AspNetCore.Mvc.ApiExplorer /// /// The list of actions. /// - public IReadOnlyList Actions { get; private set; } + public IReadOnlyList Actions { get; } /// /// The list of resulting . /// - public IList Results { get; private set; } + public IList Results { get; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/Filters/FilterDescriptor.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/Filters/FilterDescriptor.cs index 04b887ec06..bd0cb771bd 100644 --- a/src/Microsoft.AspNetCore.Mvc.Abstractions/Filters/FilterDescriptor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/Filters/FilterDescriptor.cs @@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Mvc.Filters /// /// The instance. /// - public IFilterMetadata Filter { get; private set; } + public IFilterMetadata Filter { get; } /// /// The filter order. @@ -64,6 +64,6 @@ namespace Microsoft.AspNetCore.Mvc.Filters /// /// The filter scope. /// - public int Scope { get; private set; } + public int Scope { get; } } } diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/BindingInfo.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/BindingInfo.cs index 4f4d313177..941240cb64 100644 --- a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/BindingInfo.cs +++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/BindingInfo.cs @@ -125,13 +125,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding _providers = providers; } - public Func PropertyFilter - { - get - { - return CreatePropertyFilter(); - } - } + public Func PropertyFilter => CreatePropertyFilter(); private Func CreatePropertyFilter() { diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/EnumGroupAndName.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/EnumGroupAndName.cs index fd44fc3c11..0ad0117e5d 100644 --- a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/EnumGroupAndName.cs +++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/EnumGroupAndName.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding /// public struct EnumGroupAndName { - private Func _name; + private readonly Func _name; /// /// Initializes a new instance of the structure. This constructor should @@ -65,12 +65,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding /// /// Gets the name. /// - public string Name - { - get - { - return _name(); - } - } + public string Name => _name(); } } diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelError.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelError.cs index 9511d0872a..b2125e206d 100644 --- a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelError.cs +++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelError.cs @@ -32,8 +32,8 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding ErrorMessage = errorMessage ?? string.Empty; } - public Exception Exception { get; private set; } + public Exception Exception { get; } - public string ErrorMessage { get; private set; } + public string ErrorMessage { get; } } } diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelMetadata.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelMetadata.cs index 8f57ca1e51..b56b8d5cdc 100644 --- a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelMetadata.cs +++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelMetadata.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding /// /// Gets the container type of this metadata if it represents a property, otherwise null. /// - public Type ContainerType { get { return Identity.ContainerType; } } + public Type ContainerType => Identity.ContainerType; /// /// Gets the metadata of the container type that the current instance is part of. @@ -56,23 +56,17 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding /// /// Gets a value indicating the kind of metadata element represented by the current instance. /// - public ModelMetadataKind MetadataKind { get { return Identity.MetadataKind; } } + public ModelMetadataKind MetadataKind => Identity.MetadataKind; /// /// Gets the model type represented by the current instance. /// - public Type ModelType { get { return Identity.ModelType; } } + public Type ModelType => Identity.ModelType; /// /// Gets the property name represented by the current instance. /// - public string PropertyName - { - get - { - return Identity.Name; - } - } + public string PropertyName => Identity.Name; /// /// Gets the key for the current instance. diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelStateDictionary.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelStateDictionary.cs index 49f432bb1b..9f7f6cce98 100644 --- a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelStateDictionary.cs +++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelStateDictionary.cs @@ -112,10 +112,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding /// Returns true if a has been recorded; /// otherwise false. /// - public bool HasReachedMaxErrors - { - get { return ErrorCount >= MaxAllowedErrors; } - } + public bool HasReachedMaxErrors => ErrorCount >= MaxAllowedErrors; /// /// Gets the number of errors added to this instance of via diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/Validation/ClientValidatorProviderContext.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/Validation/ClientValidatorProviderContext.cs index 68ced77b45..84b02119b3 100644 --- a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/Validation/ClientValidatorProviderContext.cs +++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/Validation/ClientValidatorProviderContext.cs @@ -33,13 +33,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation /// /// This property provides convenience access to . /// - public IReadOnlyList ValidatorMetadata - { - get - { - return ModelMetadata.ValidatorMetadata; - } - } + public IReadOnlyList ValidatorMetadata => ModelMetadata.ValidatorMetadata; /// /// Gets the list of instances. diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/Validation/ModelValidationResult.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/Validation/ModelValidationResult.cs index a8214c9a05..0d00621ed0 100644 --- a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/Validation/ModelValidationResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/Validation/ModelValidationResult.cs @@ -11,8 +11,8 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation Message = message ?? string.Empty; } - public string MemberName { get; private set; } + public string MemberName { get; } - public string Message { get; private set; } + public string Message { get; } } } diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/Validation/ModelValidatorProviderContext.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/Validation/ModelValidatorProviderContext.cs index b5c96d5074..8076c82da4 100644 --- a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/Validation/ModelValidatorProviderContext.cs +++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/Validation/ModelValidatorProviderContext.cs @@ -32,13 +32,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation /// /// This property provides convenience access to . /// - public IReadOnlyList ValidatorMetadata - { - get - { - return ModelMetadata.ValidatorMetadata; - } - } + public IReadOnlyList ValidatorMetadata => ModelMetadata.ValidatorMetadata; /// /// Gets the list of instances. instances diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/Validation/ValidationStateDictionary.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/Validation/ValidationStateDictionary.cs index 7f4f6686f4..11179b014d 100644 --- a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/Validation/ValidationStateDictionary.cs +++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/Validation/ValidationStateDictionary.cs @@ -11,12 +11,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation /// /// Used for tracking validation state to customize validation behavior for a model object. /// - public class ValidationStateDictionary : - IDictionary, + public class ValidationStateDictionary : + IDictionary, IReadOnlyDictionary { private readonly Dictionary _inner; - + /// /// Creates a new . /// @@ -30,8 +30,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation { get { - ValidationStateEntry entry; - TryGetValue(key, out entry); + TryGetValue(key, out var entry); return entry; } @@ -42,58 +41,24 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation } /// - public int Count - { - get - { - return _inner.Count; - } - } + public int Count => _inner.Count; /// - public bool IsReadOnly - { - get - { - return ((IDictionary)_inner).IsReadOnly; - } - } + public bool IsReadOnly => ((IDictionary)_inner).IsReadOnly; /// - public ICollection Keys - { - get - { - return ((IDictionary)_inner).Keys; - } - } + public ICollection Keys => ((IDictionary)_inner).Keys; /// - public ICollection Values - { - get - { - return ((IDictionary)_inner).Values; - } - } + public ICollection Values => ((IDictionary)_inner).Values; /// - IEnumerable IReadOnlyDictionary.Keys - { - get - { - return ((IReadOnlyDictionary)_inner).Keys; - } - } + IEnumerable IReadOnlyDictionary.Keys => + ((IReadOnlyDictionary)_inner).Keys; /// - IEnumerable IReadOnlyDictionary.Values - { - get - { - return ((IReadOnlyDictionary)_inner).Values; - } - } + IEnumerable IReadOnlyDictionary.Values => + ((IReadOnlyDictionary)_inner).Values; /// public void Add(KeyValuePair item) @@ -160,7 +125,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation { return ((IDictionary)_inner).GetEnumerator(); } - + private class ReferenceEqualityComparer : IEqualityComparer { private static readonly bool IsMono = Type.GetType("Mono.Runtime") != null; diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ValueProviderResult.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ValueProviderResult.cs index 69b1b27af6..c9bf19ad4c 100644 --- a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ValueProviderResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ValueProviderResult.cs @@ -57,12 +57,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding /// /// Gets or sets the associated with the values. /// - public CultureInfo Culture { get; private set; } + public CultureInfo Culture { get; } /// /// Gets or sets the values. /// - public StringValues Values { get; private set; } + public StringValues Values { get; } /// /// Gets the first value based on the order values were provided in the request. Use @@ -84,13 +84,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding /// /// Gets the number of submitted values. /// - public int Length - { - get - { - return Values.Count; - } - } + public int Length => Values.Count; /// public override bool Equals(object obj) diff --git a/src/Microsoft.AspNetCore.Mvc.ApiExplorer/ApiDescriptionGroup.cs b/src/Microsoft.AspNetCore.Mvc.ApiExplorer/ApiDescriptionGroup.cs index eed4634d12..3a8e35e578 100644 --- a/src/Microsoft.AspNetCore.Mvc.ApiExplorer/ApiDescriptionGroup.cs +++ b/src/Microsoft.AspNetCore.Mvc.ApiExplorer/ApiDescriptionGroup.cs @@ -24,11 +24,11 @@ namespace Microsoft.AspNetCore.Mvc.ApiExplorer /// /// The group name. /// - public string GroupName { get; private set; } + public string GroupName { get; } /// /// A collection of items for this group. /// - public IReadOnlyList Items { get; private set; } + public IReadOnlyList Items { get; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc.ApiExplorer/ApiDescriptionGroupCollection.cs b/src/Microsoft.AspNetCore.Mvc.ApiExplorer/ApiDescriptionGroupCollection.cs index 1e6c3a01c2..b071f1c2c9 100644 --- a/src/Microsoft.AspNetCore.Mvc.ApiExplorer/ApiDescriptionGroupCollection.cs +++ b/src/Microsoft.AspNetCore.Mvc.ApiExplorer/ApiDescriptionGroupCollection.cs @@ -30,11 +30,11 @@ namespace Microsoft.AspNetCore.Mvc.ApiExplorer /// /// Returns the list of . /// - public IReadOnlyList Items { get; private set; } + public IReadOnlyList Items { get; } /// /// Returns the unique version of the current items. /// - public int Version { get; private set; } + public int Version { get; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc.ApiExplorer/DefaultApiDescriptionProvider.cs b/src/Microsoft.AspNetCore.Mvc.ApiExplorer/DefaultApiDescriptionProvider.cs index 989f07b2b5..8c6e1e5f73 100644 --- a/src/Microsoft.AspNetCore.Mvc.ApiExplorer/DefaultApiDescriptionProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.ApiExplorer/DefaultApiDescriptionProvider.cs @@ -48,10 +48,7 @@ namespace Microsoft.AspNetCore.Mvc.ApiExplorer } /// - public int Order - { - get { return -1000; } - } + public int Order => -1000; /// public void OnProvidersExecuting(ApiDescriptionProviderContext context) @@ -261,8 +258,7 @@ namespace Microsoft.AspNetCore.Mvc.ApiExplorer private RouteTemplate ParseTemplate(ControllerActionDescriptor action) { - if (action.AttributeRouteInfo != null && - action.AttributeRouteInfo.Template != null) + if (action.AttributeRouteInfo?.Template != null) { return TemplateParser.Parse(action.AttributeRouteInfo.Template); } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/AcceptVerbsAttribute.cs b/src/Microsoft.AspNetCore.Mvc.Core/AcceptVerbsAttribute.cs index c6dcf3b52d..3c889c2320 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/AcceptVerbsAttribute.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/AcceptVerbsAttribute.cs @@ -14,7 +14,6 @@ namespace Microsoft.AspNetCore.Mvc [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)] public sealed class AcceptVerbsAttribute : Attribute, IActionHttpMethodProvider, IRouteTemplateProvider { - private readonly IEnumerable _httpMethods; private int? _order; /// @@ -36,19 +35,13 @@ namespace Microsoft.AspNetCore.Mvc /// The HTTP methods the action supports. public AcceptVerbsAttribute(params string[] methods) { - _httpMethods = methods.Select(method => method.ToUpperInvariant()); + HttpMethods = methods.Select(method => method.ToUpperInvariant()); } /// /// Gets the HTTP methods the action supports. /// - public IEnumerable HttpMethods - { - get - { - return _httpMethods; - } - } + public IEnumerable HttpMethods { get; } /// /// The route template. May be null. @@ -56,10 +49,7 @@ namespace Microsoft.AspNetCore.Mvc public string Route { get; set; } /// - string IRouteTemplateProvider.Template - { - get { return Route; } - } + string IRouteTemplateProvider.Template => Route; /// /// Gets the route order. The order determines the order of route execution. Routes with a lower @@ -74,13 +64,7 @@ namespace Microsoft.AspNetCore.Mvc } /// - int? IRouteTemplateProvider.Order - { - get - { - return _order; - } - } + int? IRouteTemplateProvider.Order => _order; /// public string Name { get; set; } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/AcceptedResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/AcceptedResult.cs index ce6f7cb72f..c56730f0c5 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/AcceptedResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/AcceptedResult.cs @@ -12,8 +12,6 @@ namespace Microsoft.AspNetCore.Mvc /// public class AcceptedResult : ObjectResult { - private string _location; - /// /// Initializes a new instance of the class with the values /// provided. @@ -67,17 +65,7 @@ namespace Microsoft.AspNetCore.Mvc /// /// Gets or sets the location at which the status of the requested content can be monitored. /// - public string Location - { - get - { - return _location; - } - set - { - _location = value; - } - } + public string Location { get; set; } /// public override void OnFormatting(ActionContext context) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ActionNameAttribute.cs b/src/Microsoft.AspNetCore.Mvc.Core/ActionNameAttribute.cs index 5d8dfa9a76..78a374b517 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ActionNameAttribute.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ActionNameAttribute.cs @@ -23,6 +23,6 @@ namespace Microsoft.AspNetCore.Mvc /// /// Gets the name of the action. /// - public string Name { get; private set; } + public string Name { get; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ApplicationModel.cs b/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ApplicationModel.cs index 3c6d4c7dab..59a1b5fe50 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ApplicationModel.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ApplicationModel.cs @@ -31,9 +31,9 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels /// public ApiExplorerModel ApiExplorer { get; set; } - public IList Controllers { get; private set; } + public IList Controllers { get; } - public IList Filters { get; private set; } + public IList Filters { get; } /// /// Gets a set of properties associated with all actions. diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/AttributeRouteModel.cs b/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/AttributeRouteModel.cs index 6d3c9daaf8..07e6a20c48 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/AttributeRouteModel.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/AttributeRouteModel.cs @@ -64,14 +64,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels /// public bool SuppressPathMatching { get; set; } - public bool IsAbsoluteTemplate - { - get - { - return Template != null && - IsOverridePattern(Template); - } - } + public bool IsAbsoluteTemplate => Template != null && IsOverridePattern(Template); /// /// Combines two instances and returns @@ -368,8 +361,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels .Replace("[[", "[") .Replace("]]", "]"); - string value; - if (!values.TryGetValue(token, out value)) + if (!values.TryGetValue(token, out var value)) { // Value not found var message = Resources.FormatAttributeRoute_TokenReplacement_ReplacementValueNotFound( diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ParameterModel.cs b/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ParameterModel.cs index d304f5be39..bc1ed07a39 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ParameterModel.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ParameterModel.cs @@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels string ICommonModel.Name => ParameterName; - public ParameterInfo ParameterInfo { get; private set; } + public ParameterInfo ParameterInfo { get; } public string ParameterName { get; set; } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Authorization/AuthorizeFilter.cs b/src/Microsoft.AspNetCore.Mvc.Core/Authorization/AuthorizeFilter.cs index 5e55030df7..3d338381d5 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Authorization/AuthorizeFilter.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Authorization/AuthorizeFilter.cs @@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Mvc.Authorization /// Ifnull, the policy will be constructed using /// . /// - public AuthorizationPolicy Policy { get; private set; } + public AuthorizationPolicy Policy { get; } bool IFilterFactory.IsReusable => true; diff --git a/src/Microsoft.AspNetCore.Mvc.Core/BindAttribute.cs b/src/Microsoft.AspNetCore.Mvc.Core/BindAttribute.cs index ec9741803a..c5ee71cdad 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/BindAttribute.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/BindAttribute.cs @@ -47,13 +47,7 @@ namespace Microsoft.AspNetCore.Mvc /// /// Represents the model name used during model binding. /// - string IModelNameProvider.Name - { - get - { - return Prefix; - } - } + string IModelNameProvider.Name => Prefix; /// public Func PropertyFilter diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ControllerBase.cs b/src/Microsoft.AspNetCore.Mvc.Core/ControllerBase.cs index 448c84d257..ef911e5db8 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ControllerBase.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ControllerBase.cs @@ -35,57 +35,27 @@ namespace Microsoft.AspNetCore.Mvc /// /// Gets the for the executing action. /// - public HttpContext HttpContext - { - get - { - return ControllerContext.HttpContext; - } - } + public HttpContext HttpContext => ControllerContext.HttpContext; /// /// Gets the for the executing action. /// - public HttpRequest Request - { - get - { - return HttpContext?.Request; - } - } + public HttpRequest Request => HttpContext?.Request; /// /// Gets the for the executing action. /// - public HttpResponse Response - { - get - { - return HttpContext?.Response; - } - } + public HttpResponse Response => HttpContext?.Response; /// /// Gets the for the executing action. /// - public RouteData RouteData - { - get - { - return ControllerContext.RouteData; - } - } + public RouteData RouteData => ControllerContext.RouteData; /// /// Gets the that contains the state of the model and of model-binding validation. /// - public ModelStateDictionary ModelState - { - get - { - return ControllerContext?.ModelState; - } - } + public ModelStateDictionary ModelState => ControllerContext?.ModelState; /// /// Gets or sets the . @@ -222,13 +192,7 @@ namespace Microsoft.AspNetCore.Mvc /// /// Gets the for user associated with the executing action. /// - public ClaimsPrincipal User - { - get - { - return HttpContext?.User; - } - } + public ClaimsPrincipal User => HttpContext?.User; /// /// Creates a object by specifying a . diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Controllers/DefaultControllerFactory.cs b/src/Microsoft.AspNetCore.Mvc.Core/Controllers/DefaultControllerFactory.cs index e8ee84042e..3a2627d1ec 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Controllers/DefaultControllerFactory.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Controllers/DefaultControllerFactory.cs @@ -48,13 +48,7 @@ namespace Microsoft.AspNetCore.Mvc.Controllers /// /// The used to create a controller. /// - protected IControllerActivator ControllerActivator - { - get - { - return _controllerActivator; - } - } + protected IControllerActivator ControllerActivator => _controllerActivator; /// public virtual object CreateController(ControllerContext context) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/CreatedResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/CreatedResult.cs index bcee856a96..5e1d23a628 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/CreatedResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/CreatedResult.cs @@ -63,10 +63,7 @@ namespace Microsoft.AspNetCore.Mvc /// public string Location { - get - { - return _location; - } + get => _location; set { if (value == null) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/ApplicationModelConventionExtensions.cs b/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/ApplicationModelConventionExtensions.cs index f8d97a4ccd..ef3c606973 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/ApplicationModelConventionExtensions.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/ApplicationModelConventionExtensions.cs @@ -86,7 +86,7 @@ namespace Microsoft.Extensions.DependencyInjection private class ParameterApplicationModelConvention : IApplicationModelConvention { - private IParameterModelConvention _parameterModelConvention; + private readonly IParameterModelConvention _parameterModelConvention; public ParameterApplicationModelConvention(IParameterModelConvention parameterModelConvention) { @@ -121,7 +121,7 @@ namespace Microsoft.Extensions.DependencyInjection private class ActionApplicationModelConvention : IApplicationModelConvention { - private IActionModelConvention _actionModelConvention; + private readonly IActionModelConvention _actionModelConvention; public ActionApplicationModelConvention(IActionModelConvention actionModelConvention) { @@ -153,7 +153,7 @@ namespace Microsoft.Extensions.DependencyInjection private class ControllerApplicationModelConvention : IApplicationModelConvention { - private IControllerModelConvention _controllerModelConvention; + private readonly IControllerModelConvention _controllerModelConvention; public ControllerApplicationModelConvention(IControllerModelConvention controllerConvention) { diff --git a/src/Microsoft.AspNetCore.Mvc.Core/FileContentResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/FileContentResult.cs index 30c5a5d213..476eace53e 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/FileContentResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/FileContentResult.cs @@ -56,10 +56,7 @@ namespace Microsoft.AspNetCore.Mvc /// public byte[] FileContents { - get - { - return _fileContents; - } + get => _fileContents; set { if (value == null) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/FileStreamResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/FileStreamResult.cs index 84c44d2348..bd0367393a 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/FileStreamResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/FileStreamResult.cs @@ -53,10 +53,7 @@ namespace Microsoft.AspNetCore.Mvc /// public Stream FileStream { - get - { - return _fileStream; - } + get => _fileStream; set { if (value == null) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Formatters/FormatFilter.cs b/src/Microsoft.AspNetCore.Mvc.Core/Formatters/FormatFilter.cs index c47bb2683e..995a7ae60c 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Formatters/FormatFilter.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Formatters/FormatFilter.cs @@ -30,8 +30,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// public virtual string GetFormat(ActionContext context) { - object obj; - if (context.RouteData.Values.TryGetValue("format", out obj)) + if (context.RouteData.Values.TryGetValue("format", out var obj)) { // null and string.Empty are equivalent for route values. var routeValue = obj?.ToString(); diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Formatters/MediaType.cs b/src/Microsoft.AspNetCore.Mvc.Core/Formatters/MediaType.cs index a0843650d3..e72fccac65 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Formatters/MediaType.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Formatters/MediaType.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters { private static readonly StringSegment QualityParameter = new StringSegment("q"); - private MediaTypeParameterParser _parameterParser; + private readonly MediaTypeParameterParser _parameterParser; /// /// Initializes a instance. @@ -70,8 +70,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters _parameterParser = default(MediaTypeParameterParser); - StringSegment type; - var typeLength = GetTypeLength(mediaType, offset, out type); + var typeLength = GetTypeLength(mediaType, offset, out var type); if (typeLength == 0) { Type = new StringSegment(); @@ -85,8 +84,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters Type = type; } - StringSegment subType; - var subTypeLength = GetSubtypeLength(mediaType, offset + typeLength, out subType); + var subTypeLength = GetSubtypeLength(mediaType, offset + typeLength, out var subType); if (subTypeLength == 0) { SubType = new StringSegment(); @@ -210,7 +208,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// For the media type "application/vnd.example+json", this property gives the value /// "vnd.example+json". /// - public StringSegment SubType { get; private set; } + public StringSegment SubType { get; } /// /// Gets the subtype of the , excluding any structured syntax suffix. @@ -219,7 +217,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// For the media type "application/vnd.example+json", this property gives the value /// "vnd.example". /// - public StringSegment SubTypeWithoutSuffix { get; private set; } + public StringSegment SubTypeWithoutSuffix { get; } /// /// Gets the structured syntax suffix of the if it has one. @@ -228,7 +226,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// For the media type "application/vnd.example+json", this property gives the value /// "json". /// - public StringSegment SubTypeSuffix { get; private set; } + public StringSegment SubTypeSuffix { get; } /// /// Gets whether this matches all subtypes. @@ -318,8 +316,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters { var parametersParser = _parameterParser; - MediaTypeParameter parameter; - while (parametersParser.ParseNextParameter(out parameter)) + while (parametersParser.ParseNextParameter(out var parameter)) { if (parameter.HasName(parameterName)) { @@ -411,8 +408,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters var parser = parsedMediaType._parameterParser; var quality = 1.0d; - MediaTypeParameter parameter; - while (parser.ParseNextParameter(out parameter)) + while (parser.ParseNextParameter(out var parameter)) { if (parameter.HasName(QualityParameter)) { @@ -512,8 +508,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters private bool ContainsAllParameters(MediaTypeParameterParser setParameters) { var parameterFound = true; - MediaTypeParameter setParameter; - while (setParameters.ParseNextParameter(out setParameter) && parameterFound) + while (setParameters.ParseNextParameter(out var setParameter) && parameterFound) { if (setParameter.HasName("q")) { @@ -533,8 +528,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters // We can do this because it's a struct var subSetParameters = _parameterParser; parameterFound = false; - MediaTypeParameter subSetParameter; - while (subSetParameters.ParseNextParameter(out subSetParameter) && !parameterFound) + while (subSetParameters.ParseNextParameter(out var subSetParameter) && !parameterFound) { parameterFound = subSetParameter.Equals(setParameter); } @@ -545,8 +539,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters private struct MediaTypeParameterParser { - private string _mediaTypeBuffer; - private int? _length; + private readonly string _mediaTypeBuffer; + private readonly int? _length; public MediaTypeParameterParser(string mediaTypeBuffer, int offset, int? length) { @@ -589,8 +583,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters return 0; } - StringSegment name; - var nameLength = GetNameLength(input, startIndex, out name); + var nameLength = GetNameLength(input, startIndex, out var name); var current = startIndex + nameLength; @@ -611,8 +604,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters } } - StringSegment value; - var valueLength = GetValueLength(input, current, out value); + var valueLength = GetValueLength(input, current, out var value); parsedValue = new MediaTypeParameter(name, value); current += valueLength; diff --git a/src/Microsoft.AspNetCore.Mvc.Core/FromBodyAttribute.cs b/src/Microsoft.AspNetCore.Mvc.Core/FromBodyAttribute.cs index c49240523a..157d1cdd3d 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/FromBodyAttribute.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/FromBodyAttribute.cs @@ -13,6 +13,6 @@ namespace Microsoft.AspNetCore.Mvc public class FromBodyAttribute : Attribute, IBindingSourceMetadata { /// - public BindingSource BindingSource { get { return BindingSource.Body; } } + public BindingSource BindingSource => BindingSource.Body; } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/FromFormAttribute.cs b/src/Microsoft.AspNetCore.Mvc.Core/FromFormAttribute.cs index 8a8fb98921..a42774f17f 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/FromFormAttribute.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/FromFormAttribute.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Mvc public class FromFormAttribute : Attribute, IBindingSourceMetadata, IModelNameProvider { /// - public BindingSource BindingSource { get { return BindingSource.Form; } } + public BindingSource BindingSource => BindingSource.Form; /// public string Name { get; set; } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/FromHeaderAttribute.cs b/src/Microsoft.AspNetCore.Mvc.Core/FromHeaderAttribute.cs index ee32494183..46809454f1 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/FromHeaderAttribute.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/FromHeaderAttribute.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Mvc public class FromHeaderAttribute : Attribute, IBindingSourceMetadata, IModelNameProvider { /// - public BindingSource BindingSource { get { return BindingSource.Header; } } + public BindingSource BindingSource => BindingSource.Header; /// public string Name { get; set; } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/FromQueryAttribute.cs b/src/Microsoft.AspNetCore.Mvc.Core/FromQueryAttribute.cs index db76447a3c..df82f67bc3 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/FromQueryAttribute.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/FromQueryAttribute.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Mvc public class FromQueryAttribute : Attribute, IBindingSourceMetadata, IModelNameProvider { /// - public BindingSource BindingSource { get { return BindingSource.Query; } } + public BindingSource BindingSource => BindingSource.Query; /// public string Name { get; set; } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/FromRouteAttribute.cs b/src/Microsoft.AspNetCore.Mvc.Core/FromRouteAttribute.cs index eb30d715f9..94952e502f 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/FromRouteAttribute.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/FromRouteAttribute.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Mvc public class FromRouteAttribute : Attribute, IBindingSourceMetadata, IModelNameProvider { /// - public BindingSource BindingSource { get { return BindingSource.Path; } } + public BindingSource BindingSource => BindingSource.Path; /// public string Name { get; set; } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ActionDescriptorCollection.cs b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ActionDescriptorCollection.cs index 05fc198925..dc00290a5d 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ActionDescriptorCollection.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ActionDescriptorCollection.cs @@ -31,11 +31,11 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure /// /// Returns the cached . /// - public IReadOnlyList Items { get; private set; } + public IReadOnlyList Items { get; } /// /// Returns the unique version of the currently cached items. /// - public int Version { get; private set; } + public int Version { get; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/AcceptHeaderParser.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/AcceptHeaderParser.cs index 996e6a0134..289e151226 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/AcceptHeaderParser.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/AcceptHeaderParser.cs @@ -37,8 +37,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Internal { var startCharIndex = charIndex; - MediaTypeSegmentWithQuality output; - if (TryParseValue(value, ref charIndex, out output)) + if (TryParseValue(value, ref charIndex, out var output)) { // The entry may not contain an actual value, like Accept: application/json, , */* if (output.MediaType.HasValue) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionConstraintCache.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionConstraintCache.cs index dea1118040..3ba049a494 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionConstraintCache.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionConstraintCache.cs @@ -48,8 +48,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal { var cache = CurrentCache; - CacheEntry entry; - if (cache.Entries.TryGetValue(action, out entry)) + if (cache.Entries.TryGetValue(action, out var entry)) { return GetActionConstraintsFromEntry(entry, httpContext, action); } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionSelector.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionSelector.cs index 3d389b8ed6..f9c9fa750b 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionSelector.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionSelector.cs @@ -376,13 +376,13 @@ namespace Microsoft.AspNetCore.Mvc.Internal } } - public int Version { get; set; } + public int Version { get; } - public string[] RouteKeys { get; set; } + public string[] RouteKeys { get; } - public Dictionary> OrdinalEntries { get; set; } + public Dictionary> OrdinalEntries { get; } - public Dictionary> OrdinalIgnoreCaseEntries { get; set; } + public Dictionary> OrdinalIgnoreCaseEntries { get; } } private class StringArrayComparer : IEqualityComparer diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/AuthorizationApplicationModelProvider.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/AuthorizationApplicationModelProvider.cs index 31115f1320..6117a959a2 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/AuthorizationApplicationModelProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/AuthorizationApplicationModelProvider.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal _policyProvider = policyProvider; } - public int Order { get { return -1000 + 10; } } + public int Order => -1000 + 10; public void OnProvidersExecuted(ApplicationModelProviderContext context) { diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ClientValidatorCache.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ClientValidatorCache.cs index 83472b5a15..37adde40c2 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ClientValidatorCache.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ClientValidatorCache.cs @@ -16,8 +16,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal public IReadOnlyList GetValidators(ModelMetadata metadata, IClientModelValidatorProvider validatorProvider) { - CacheEntry entry; - if (_cacheEntries.TryGetValue(metadata, out entry)) + if (_cacheEntries.TryGetValue(metadata, out var entry)) { return GetValidatorsFromEntry(entry, metadata, validatorProvider); } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionDescriptorBuilder.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionDescriptorBuilder.cs index 3021f78431..572f3aa441 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionDescriptorBuilder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionDescriptorBuilder.cs @@ -474,9 +474,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal string routeName, ControllerActionDescriptor actionDescriptor) { - IList namedActionGroup; - - if (actionsByRouteName.TryGetValue(routeName, out namedActionGroup)) + if (actionsByRouteName.TryGetValue(routeName, out var namedActionGroup)) { namedActionGroup.Add(actionDescriptor); } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionDescriptorProvider.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionDescriptorProvider.cs index 476e2a14e6..c5fc31e178 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionDescriptorProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionDescriptorProvider.cs @@ -44,10 +44,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal _conventions = optionsAccessor.Value.Conventions; } - public int Order - { - get { return -1000; } - } + public int Order => -1000; /// public void OnProvidersExecuting(ActionDescriptorProviderContext context) @@ -98,14 +95,14 @@ namespace Microsoft.AspNetCore.Mvc.Internal } } - internal protected IEnumerable GetDescriptors() + protected internal IEnumerable GetDescriptors() { var applicationModel = BuildModel(); ApplicationModelConventions.ApplyConventions(applicationModel, _conventions); return ControllerActionDescriptorBuilder.Build(applicationModel); } - internal protected ApplicationModel BuildModel() + protected internal ApplicationModel BuildModel() { var controllerTypes = GetControllerTypes(); var context = new ApplicationModelProviderContext(controllerTypes); diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/CopyOnWriteList.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/CopyOnWriteList.cs index fd7d171168..a051b69cff 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/CopyOnWriteList.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/CopyOnWriteList.cs @@ -16,13 +16,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal _source = source; } - protected IReadOnlyList Readable - { - get - { - return _copy ?? _source; - } - } + protected IReadOnlyList Readable => _copy ?? _source; protected List Writable { @@ -39,31 +33,13 @@ namespace Microsoft.AspNetCore.Mvc.Internal public T this[int index] { - get - { - return Readable[index]; - } - set - { - Writable[index] = value; - } + get => Readable[index]; + set => Writable[index] = value; } - public int Count - { - get - { - return Readable.Count; - } - } + public int Count => Readable.Count; - public bool IsReadOnly - { - get - { - return false; - } - } + public bool IsReadOnly => false; public void Add(T item) { diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultActionConstraintProvider.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultActionConstraintProvider.cs index adade75d66..f79a2fa835 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultActionConstraintProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultActionConstraintProvider.cs @@ -17,10 +17,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal public class DefaultActionConstraintProvider : IActionConstraintProvider { /// - public int Order - { - get { return -1000; } - } + public int Order => -1000; /// public void OnProvidersExecuting(ActionConstraintProviderContext context) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultApplicationModelProvider.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultApplicationModelProvider.cs index 14f68d1a0b..3f98f4b51c 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultApplicationModelProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultApplicationModelProvider.cs @@ -26,13 +26,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal } /// - public int Order - { - get - { - return -1000; - } - } + public int Order => -1000; /// public virtual void OnProvidersExecuting(ApplicationModelProviderContext context) @@ -485,8 +479,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var createSelectorForSilentRouteProviders = false; foreach (var attribute in attributes) { - var routeTemplateProvider = attribute as IRouteTemplateProvider; - if (routeTemplateProvider != null) + if (attribute is IRouteTemplateProvider routeTemplateProvider) { if (IsSilentRouteAttribute(routeTemplateProvider)) { diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultBindingMetadataProvider.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultBindingMetadataProvider.cs index 8ed75a30ef..7d034e1200 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultBindingMetadataProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultBindingMetadataProvider.cs @@ -99,13 +99,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal _providers = providers; } - public Func PropertyFilter - { - get - { - return CreatePropertyFilter(); - } - } + public Func PropertyFilter => CreatePropertyFilter(); private Func CreatePropertyFilter() { diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultCollectionValidationStrategy.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultCollectionValidationStrategy.cs index 3823c8ac20..322f55d55b 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultCollectionValidationStrategy.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultCollectionValidationStrategy.cs @@ -108,21 +108,9 @@ namespace Microsoft.AspNetCore.Mvc.Internal _index = -1; } - public ValidationEntry Current - { - get - { - return _entry; - } - } + public ValidationEntry Current => _entry; - object IEnumerator.Current - { - get - { - return Current; - } - } + object IEnumerator.Current => Current; public bool MoveNext() { diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultComplexObjectValidationStrategy.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultComplexObjectValidationStrategy.cs index 135b13d2cf..a2a1e0323a 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultComplexObjectValidationStrategy.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultComplexObjectValidationStrategy.cs @@ -56,21 +56,9 @@ namespace Microsoft.AspNetCore.Mvc.Internal _index = -1; } - public ValidationEntry Current - { - get - { - return _entry; - } - } + public ValidationEntry Current => _entry; - object IEnumerator.Current - { - get - { - return Current; - } - } + object IEnumerator.Current => Current; public bool MoveNext() { diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultFilterProvider.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultFilterProvider.cs index 51bee5618c..3e7f685494 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultFilterProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultFilterProvider.cs @@ -10,10 +10,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal { public class DefaultFilterProvider : IFilterProvider { - public int Order - { - get { return -1000; } - } + public int Order => -1000; /// public void OnProvidersExecuting(FilterProviderContext context) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ExplicitIndexCollectionValidationStrategy.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ExplicitIndexCollectionValidationStrategy.cs index f4f940f8ae..8308dee10e 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ExplicitIndexCollectionValidationStrategy.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ExplicitIndexCollectionValidationStrategy.cs @@ -82,21 +82,9 @@ namespace Microsoft.AspNetCore.Mvc.Internal _enumerator = enumerator; } - public ValidationEntry Current - { - get - { - return _entry; - } - } + public ValidationEntry Current => _entry; - object IEnumerator.Current - { - get - { - return Current; - } - } + object IEnumerator.Current => Current; public bool MoveNext() { diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterDescriptorOrderComparer.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterDescriptorOrderComparer.cs index 766cb0d964..daadc073d4 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterDescriptorOrderComparer.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterDescriptorOrderComparer.cs @@ -9,12 +9,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal { public class FilterDescriptorOrderComparer : IComparer { - private static readonly FilterDescriptorOrderComparer _comparer = new FilterDescriptorOrderComparer(); - - public static FilterDescriptorOrderComparer Comparer - { - get { return _comparer; } - } + public static FilterDescriptorOrderComparer Comparer { get; } = new FilterDescriptorOrderComparer(); public int Compare(FilterDescriptor x, FilterDescriptor y) { diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/HttpMethodActionConstraint.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/HttpMethodActionConstraint.cs index 4e1a94250c..f936d8a2bf 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/HttpMethodActionConstraint.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/HttpMethodActionConstraint.cs @@ -42,18 +42,9 @@ namespace Microsoft.AspNetCore.Mvc.Internal _httpMethods = new ReadOnlyCollection(methods); } - public IEnumerable HttpMethods - { - get - { - return _httpMethods; - } - } + public IEnumerable HttpMethods => _httpMethods; - public int Order - { - get { return HttpMethodConstraintOrder; } - } + public int Order => HttpMethodConstraintOrder; public bool Accept(ActionConstraintContext context) { diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/HttpTokenParsingRules.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/HttpTokenParsingRules.cs index 0f8098d0db..b562ffba1e 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/HttpTokenParsingRules.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/HttpTokenParsingRules.cs @@ -99,10 +99,9 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Internal var current = startIndex; - char c; while (current < input.Length) { - c = input[current]; + var c = input[current]; if ((c == SP) || (c == Tab)) { @@ -202,9 +201,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Internal { // Only check whether we have a quoted char, if we have at least 3 characters left to read (i.e. // quoted char + closing char). Otherwise the closing char may be considered part of the quoted char. - var quotedPairLength = 0; if ((current + 2 < input.Length) && - (GetQuotedPairLength(input, current, out quotedPairLength) == HttpParseResult.Parsed)) + (GetQuotedPairLength(input, current, out var quotedPairLength) == HttpParseResult.Parsed)) { // We ignore invalid quoted-pairs. Invalid quoted-pairs may mean that it looked like a quoted pair, // but we actually have a quoted-string: e.g. "\ü" ('\' followed by a char >127 - quoted-pair only @@ -225,9 +223,14 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Internal return HttpParseResult.InvalidFormat; } - var nestedLength = 0; - var nestedResult = GetExpressionLength(input, current, openChar, closeChar, - supportsNesting, ref nestedCount, out nestedLength); + var nestedResult = GetExpressionLength( + input, + current, + openChar, + closeChar, + supportsNesting, + ref nestedCount, + out var nestedLength); switch (nestedResult) { diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcAttributeRouteHandler.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcAttributeRouteHandler.cs index 23f8f2c01a..93f7277522 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcAttributeRouteHandler.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcAttributeRouteHandler.cs @@ -14,10 +14,10 @@ namespace Microsoft.AspNetCore.Mvc.Internal { public class MvcAttributeRouteHandler : IRouter { - private IActionContextAccessor _actionContextAccessor; - private IActionInvokerFactory _actionInvokerFactory; - private IActionSelector _actionSelector; - private ILogger _logger; + private readonly IActionContextAccessor _actionContextAccessor; + private readonly IActionInvokerFactory _actionInvokerFactory; + private readonly IActionSelector _actionSelector; + private readonly ILogger _logger; private DiagnosticSource _diagnosticSource; public MvcAttributeRouteHandler( diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreLoggerExtensions.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreLoggerExtensions.cs index 66a3685520..b63b5ef8d7 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreLoggerExtensions.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreLoggerExtensions.cs @@ -552,13 +552,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal } } - public int Count - { - get - { - return 2; - } - } + public int Count => 2; public IEnumerator> GetEnumerator() { diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcRouteHandler.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcRouteHandler.cs index 2c03dfdc94..21903703fa 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcRouteHandler.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcRouteHandler.cs @@ -13,11 +13,11 @@ namespace Microsoft.AspNetCore.Mvc.Internal { public class MvcRouteHandler : IRouter { - private IActionContextAccessor _actionContextAccessor; - private IActionInvokerFactory _actionInvokerFactory; - private IActionSelector _actionSelector; - private ILogger _logger; - private DiagnosticSource _diagnosticSource; + private readonly IActionContextAccessor _actionContextAccessor; + private readonly IActionInvokerFactory _actionInvokerFactory; + private readonly IActionSelector _actionSelector; + private readonly ILogger _logger; + private readonly DiagnosticSource _diagnosticSource; public MvcRouteHandler( IActionInvokerFactory actionInvokerFactory, diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/NonDisposableStream.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/NonDisposableStream.cs index 2e4eecc229..9cc9a46ea4 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/NonDisposableStream.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/NonDisposableStream.cs @@ -34,35 +34,19 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// /// The inner stream this object delegates to. /// - protected Stream InnerStream - { - get { return _innerStream; } - } + protected Stream InnerStream => _innerStream; /// - public override bool CanRead - { - get { return _innerStream.CanRead; } - } + public override bool CanRead => _innerStream.CanRead; /// - public override bool CanSeek - { - get { return _innerStream.CanSeek; } - } + public override bool CanSeek => _innerStream.CanSeek; /// - public override bool CanWrite - { - get { return _innerStream.CanWrite; } - } + public override bool CanWrite => _innerStream.CanWrite; /// - public override long Length - { - get { return _innerStream.Length; } - } - + public override long Length => _innerStream.Length; /// public override long Position { @@ -78,10 +62,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal } /// - public override bool CanTimeout - { - get { return _innerStream.CanTimeout; } - } + public override bool CanTimeout => _innerStream.CanTimeout; /// public override int WriteTimeout diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ReferenceEqualityComparer.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ReferenceEqualityComparer.cs index f6af6e7e76..e2288a01c8 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ReferenceEqualityComparer.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ReferenceEqualityComparer.cs @@ -9,17 +9,9 @@ namespace Microsoft.AspNetCore.Mvc.Internal { internal class ReferenceEqualityComparer : IEqualityComparer { - private static readonly ReferenceEqualityComparer _instance = new ReferenceEqualityComparer(); - private static readonly bool IsMono = Type.GetType("Mono.Runtime") != null; - public static ReferenceEqualityComparer Instance - { - get - { - return _instance; - } - } + public static ReferenceEqualityComparer Instance { get; } = new ReferenceEqualityComparer(); public new bool Equals(object x, object y) { diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ShortFormDictionaryValidationStrategy.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ShortFormDictionaryValidationStrategy.cs index 3dad102c4b..3c7f74fd95 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ShortFormDictionaryValidationStrategy.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ShortFormDictionaryValidationStrategy.cs @@ -83,21 +83,9 @@ namespace Microsoft.AspNetCore.Mvc.Internal _keyMappingEnumerator = keyMappings.GetEnumerator(); } - public ValidationEntry Current - { - get - { - return _entry; - } - } + public ValidationEntry Current => _entry; - object IEnumerator.Current - { - get - { - return Current; - } - } + object IEnumerator.Current => Current; public bool MoveNext() { diff --git a/src/Microsoft.AspNetCore.Mvc.Core/LocalRedirectResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/LocalRedirectResult.cs index a06b3e8f99..165d932c3c 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/LocalRedirectResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/LocalRedirectResult.cs @@ -71,10 +71,7 @@ namespace Microsoft.AspNetCore.Mvc /// public string Url { - get - { - return _localUrl; - } + get => _localUrl; set { if (string.IsNullOrEmpty(value)) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CollectionModelBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CollectionModelBinder.cs index b390bcf331..c9699ec62b 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CollectionModelBinder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CollectionModelBinder.cs @@ -181,8 +181,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders bindingContext.ValueProvider }; - object boundValue; - using (bindingContext.EnterNestedScope( elementMetadata, fieldName: bindingContext.FieldName, @@ -193,7 +191,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders if (bindingContext.Result.IsModelSet) { - boundValue = bindingContext.Result.Model; + var boundValue = bindingContext.Result.Model; boundCollection.Add(ModelBindingHelper.CastOrDefault(boundValue)); } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ComplexTypeModelBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ComplexTypeModelBinder.cs index 52fa184a64..b59cd6e9bf 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ComplexTypeModelBinder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ComplexTypeModelBinder.cs @@ -410,7 +410,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders ModelBindingContext bindingContext) { var targetInvocationException = exception as TargetInvocationException; - if (targetInvocationException != null && targetInvocationException.InnerException != null) + if (targetInvocationException?.InnerException != null) { exception = targetInvocationException.InnerException; } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs index 0496fbddef..2688f11d08 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs @@ -41,37 +41,13 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders private class EmptyFormCollection : IFormCollection { - public StringValues this[string key] - { - get - { - return StringValues.Empty; - } - } + public StringValues this[string key] => StringValues.Empty; - public int Count - { - get - { - return 0; - } - } + public int Count => 0; - public IFormFileCollection Files - { - get - { - return new EmptyFormFileCollection(); - } - } + public IFormFileCollection Files => new EmptyFormFileCollection(); - public ICollection Keys - { - get - { - return new List(); - } - } + public ICollection Keys => new List(); public bool ContainsKey(string key) { @@ -97,23 +73,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders private class EmptyFormFileCollection : List, IFormFileCollection { - public IFormFile this[string name] - { - get - { - return null; - } - } + public IFormFile this[string name] => null; - public IFormFile GetFile(string name) - { - return null; - } + public IFormFile GetFile(string name) => null; - IReadOnlyList IFormFileCollection.GetFiles(string name) - { - return null; - } + IReadOnlyList IFormFileCollection.GetFiles(string name) => null; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/BindingBehaviorAttribute.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/BindingBehaviorAttribute.cs index 302d9fe8c8..84492d5806 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/BindingBehaviorAttribute.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/BindingBehaviorAttribute.cs @@ -23,6 +23,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding /// /// Gets the to apply. /// - public BindingBehavior Behavior { get; private set; } + public BindingBehavior Behavior { get; } } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/DefaultPropertyFilterProvider.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/DefaultPropertyFilterProvider.cs index 4ed1cf5986..3d1bc81a71 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/DefaultPropertyFilterProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/DefaultPropertyFilterProvider.cs @@ -22,25 +22,13 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding /// /// The prefix which is used while generating the property filter. /// - public virtual string Prefix - { - get - { - return string.Empty; - } - } + public virtual string Prefix => string.Empty; /// /// Expressions which can be used to generate property filter which can filter model /// properties. /// - public virtual IEnumerable>> PropertyIncludeExpressions - { - get - { - return null; - } - } + public virtual IEnumerable>> PropertyIncludeExpressions => null; /// public virtual Func PropertyFilter diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/FormValueProvider.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/FormValueProvider.cs index 97e6837b4c..0e347e99d7 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/FormValueProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/FormValueProvider.cs @@ -15,8 +15,8 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding public class FormValueProvider : BindingSourceValueProvider, IEnumerableValueProvider { private readonly CultureInfo _culture; + private readonly IFormCollection _values; private PrefixContainer _prefixContainer; - private IFormCollection _values; /// /// Creates a value provider for . @@ -44,13 +44,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding _culture = culture; } - public CultureInfo Culture - { - get - { - return _culture; - } - } + public CultureInfo Culture => _culture; protected PrefixContainer PrefixContainer { diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Internal/ModelBindingHelper.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Internal/ModelBindingHelper.cs index e74dfd768d..90d8dd79f1 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Internal/ModelBindingHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Internal/ModelBindingHelper.cs @@ -331,8 +331,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Internal } var memberExpression = (MemberExpression)expression; - var memberInfo = memberExpression.Member as PropertyInfo; - if (memberInfo != null) + if (memberExpression.Member is PropertyInfo memberInfo) { if (memberExpression.Expression.NodeType != ExpressionType.Parameter) { @@ -531,8 +530,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Internal return false; } - var collection = model as ICollection; - if (collection != null && !collection.IsReadOnly) + if (model is ICollection collection && !collection.IsReadOnly) { // Can use the existing collection. return true; @@ -615,8 +613,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Internal } // Does collection exist and can it be reused? - var collection = model as ICollection; - if (collection != null && !collection.IsReadOnly) + if (model is ICollection collection && !collection.IsReadOnly) { collection.Clear(); @@ -739,8 +736,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Internal destinationType = UnwrapNullableType(destinationType); // if this is a user-input value but the user didn't type anything, return no value - var valueAsString = value as string; - if (valueAsString != null && string.IsNullOrWhiteSpace(valueAsString)) + if (value is string valueAsString && string.IsNullOrWhiteSpace(valueAsString)) { return null; } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/BindingMetadata.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/BindingMetadata.cs index 2cf3e8ae5f..3714298b69 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/BindingMetadata.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/BindingMetadata.cs @@ -58,10 +58,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata /// public DefaultModelBindingMessageProvider ModelBindingMessageProvider { - get - { - return _messageProvider; - } + get => _messageProvider; set { if (value == null) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadata.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadata.cs index d1d2052fd3..91069d3d3e 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadata.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadata.cs @@ -88,22 +88,10 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata /// /// Gets the set of attributes for the current instance. /// - public ModelAttributes Attributes - { - get - { - return _details.ModelAttributes; - } - } + public ModelAttributes Attributes => _details.ModelAttributes; /// - public override ModelMetadata ContainerMetadata - { - get - { - return _details.ContainerMetadata; - } - } + public override ModelMetadata ContainerMetadata => _details.ContainerMetadata; /// /// Gets the for the current instance. @@ -188,49 +176,19 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata } /// - public override BindingSource BindingSource - { - get - { - return BindingMetadata.BindingSource; - } - } + public override BindingSource BindingSource => BindingMetadata.BindingSource; /// - public override string BinderModelName - { - get - { - return BindingMetadata.BinderModelName; - } - } + public override string BinderModelName => BindingMetadata.BinderModelName; /// - public override Type BinderType - { - get - { - return BindingMetadata.BinderType; - } - } + public override Type BinderType => BindingMetadata.BinderType; /// - public override bool ConvertEmptyStringToNull - { - get - { - return DisplayMetadata.ConvertEmptyStringToNull; - } - } + public override bool ConvertEmptyStringToNull => DisplayMetadata.ConvertEmptyStringToNull; /// - public override string DataTypeName - { - get - { - return DisplayMetadata.DataTypeName; - } - } + public override string DataTypeName => DisplayMetadata.DataTypeName; /// public override string Description @@ -247,13 +205,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata } /// - public override string DisplayFormatString - { - get - { - return DisplayMetadata.DisplayFormatString; - } - } + public override string DisplayFormatString => DisplayMetadata.DisplayFormatString; /// public override string DisplayName @@ -270,13 +222,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata } /// - public override string EditFormatString - { - get - { - return DisplayMetadata.EditFormatString; - } - } + public override string EditFormatString => DisplayMetadata.EditFormatString; /// public override ModelMetadata ElementMetadata @@ -294,48 +240,19 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata /// public override IEnumerable> EnumGroupedDisplayNamesAndValues - { - get - { - return DisplayMetadata.EnumGroupedDisplayNamesAndValues; - } - } + => DisplayMetadata.EnumGroupedDisplayNamesAndValues; /// - public override IReadOnlyDictionary EnumNamesAndValues - { - get - { - return DisplayMetadata.EnumNamesAndValues; - } - } + public override IReadOnlyDictionary EnumNamesAndValues => DisplayMetadata.EnumNamesAndValues; /// - public override bool HasNonDefaultEditFormat - { - get - { - return DisplayMetadata.HasNonDefaultEditFormat; - } - } + public override bool HasNonDefaultEditFormat => DisplayMetadata.HasNonDefaultEditFormat; /// - public override bool HideSurroundingHtml - { - get - { - return DisplayMetadata.HideSurroundingHtml; - } - } + public override bool HideSurroundingHtml => DisplayMetadata.HideSurroundingHtml; /// - public override bool HtmlEncode - { - get - { - return DisplayMetadata.HtmlEncode; - } - } + public override bool HtmlEncode => DisplayMetadata.HtmlEncode; /// public override bool IsBindingAllowed @@ -375,22 +292,10 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata } /// - public override bool IsEnum - { - get - { - return DisplayMetadata.IsEnum; - } - } + public override bool IsEnum => DisplayMetadata.IsEnum; /// - public override bool IsFlagsEnum - { - get - { - return DisplayMetadata.IsFlagsEnum; - } - } + public override bool IsFlagsEnum => DisplayMetadata.IsFlagsEnum; /// public override bool IsReadOnly @@ -440,31 +345,14 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata } /// - public override ModelBindingMessageProvider ModelBindingMessageProvider - { - get - { - return BindingMetadata.ModelBindingMessageProvider; - } - } + public override ModelBindingMessageProvider ModelBindingMessageProvider => + BindingMetadata.ModelBindingMessageProvider; /// - public override string NullDisplayText - { - get - { - return DisplayMetadata.NullDisplayText; - } - } + public override string NullDisplayText => DisplayMetadata.NullDisplayText; /// - public override int Order - { - get - { - return DisplayMetadata.Order; - } - } + public override int Order => DisplayMetadata.Order; /// public override string Placeholder @@ -497,58 +385,22 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata } /// - public override IPropertyFilterProvider PropertyFilterProvider - { - get - { - return BindingMetadata.PropertyFilterProvider; - } - } + public override IPropertyFilterProvider PropertyFilterProvider => BindingMetadata.PropertyFilterProvider; /// - public override bool ShowForDisplay - { - get - { - return DisplayMetadata.ShowForDisplay; - } - } + public override bool ShowForDisplay => DisplayMetadata.ShowForDisplay; /// - public override bool ShowForEdit - { - get - { - return DisplayMetadata.ShowForEdit; - } - } + public override bool ShowForEdit => DisplayMetadata.ShowForEdit; /// - public override string SimpleDisplayProperty - { - get - { - return DisplayMetadata.SimpleDisplayProperty; - } - } + public override string SimpleDisplayProperty => DisplayMetadata.SimpleDisplayProperty; /// - public override string TemplateHint - { - get - { - return DisplayMetadata.TemplateHint; - } - } + public override string TemplateHint => DisplayMetadata.TemplateHint; /// - public override IPropertyValidationFilter PropertyValidationFilter - { - get - { - return ValidationMetadata.PropertyValidationFilter; - } - } + public override IPropertyValidationFilter PropertyValidationFilter => ValidationMetadata.PropertyValidationFilter; /// public override bool ValidateChildren @@ -590,22 +442,10 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata } /// - public override Func PropertyGetter - { - get - { - return _details.PropertyGetter; - } - } + public override Func PropertyGetter => _details.PropertyGetter; /// - public override Action PropertySetter - { - get - { - return _details.PropertySetter; - } - } + public override Action PropertySetter => _details.PropertySetter; /// public override ModelMetadata GetMetadataForType(Type modelType) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadataProvider.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadataProvider.cs index 05d7c47984..a3e829c105 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadataProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadataProvider.cs @@ -251,9 +251,9 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata Details = details; } - public ModelMetadata Metadata { get; private set; } + public ModelMetadata Metadata { get; } - public DefaultMetadataDetails Details { get; private set; } + public DefaultMetadataDetails Details { get; } } private class ModelMetadataIdentityComparer : IEqualityComparer diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/QueryStringValueProvider.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/QueryStringValueProvider.cs index 3fc397bbc7..a905d72752 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/QueryStringValueProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/QueryStringValueProvider.cs @@ -15,8 +15,8 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding public class QueryStringValueProvider : BindingSourceValueProvider, IEnumerableValueProvider { private readonly CultureInfo _culture; + private readonly IQueryCollection _values; private PrefixContainer _prefixContainer; - private IQueryCollection _values; /// /// Creates a value provider for . @@ -44,13 +44,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding _culture = culture; } - public CultureInfo Culture - { - get - { - return _culture; - } - } + public CultureInfo Culture => _culture; protected PrefixContainer PrefixContainer { diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ValidationVisitor.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ValidationVisitor.cs index 356a51800c..76b43e8a7c 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ValidationVisitor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ValidationVisitor.cs @@ -21,6 +21,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation private readonly ActionContext _actionContext; private readonly ModelStateDictionary _modelState; private readonly ValidationStateDictionary _validationState; + private readonly ValidationStack _currentPath; private object _container; private string _key; @@ -28,8 +29,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation private ModelMetadata _metadata; private IValidationStrategy _strategy; - private ValidationStack _currentPath; - /// /// Creates a new . /// diff --git a/src/Microsoft.AspNetCore.Mvc.Core/MvcOptions.cs b/src/Microsoft.AspNetCore.Mvc.Core/MvcOptions.cs index 55dc6c526c..d8de256a7a 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/MvcOptions.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/MvcOptions.cs @@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Mvc /// public int MaxModelValidationErrors { - get { return _maxModelStateErrors; } + get => _maxModelStateErrors; set { if (value < 0) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/PhysicalFileResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/PhysicalFileResult.cs index 0503758e9b..a0be57ab17 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/PhysicalFileResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/PhysicalFileResult.cs @@ -54,10 +54,7 @@ namespace Microsoft.AspNetCore.Mvc /// public string FileName { - get - { - return _fileName; - } + get => _fileName; set { if (value == null) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/RedirectResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/RedirectResult.cs index 0341fa801e..ed4616a4c2 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/RedirectResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/RedirectResult.cs @@ -81,10 +81,7 @@ namespace Microsoft.AspNetCore.Mvc /// public string Url { - get - { - return _url; - } + get => _url; set { if (string.IsNullOrEmpty(value)) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ResponseCacheAttribute.cs b/src/Microsoft.AspNetCore.Mvc.Core/ResponseCacheAttribute.cs index 553be45b09..df6a06b9ae 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ResponseCacheAttribute.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ResponseCacheAttribute.cs @@ -29,14 +29,8 @@ namespace Microsoft.AspNetCore.Mvc /// public int Duration { - get - { - return _duration ?? 0; - } - set - { - _duration = value; - } + get => _duration ?? 0; + set => _duration = value; } /// @@ -44,14 +38,8 @@ namespace Microsoft.AspNetCore.Mvc /// public ResponseCacheLocation Location { - get - { - return _location ?? ResponseCacheLocation.Any; - } - set - { - _location = value; - } + get => _location ?? ResponseCacheLocation.Any; + set => _location = value; } /// @@ -62,14 +50,8 @@ namespace Microsoft.AspNetCore.Mvc /// public bool NoStore { - get - { - return _noStore ?? false; - } - set - { - _noStore = value; - } + get => _noStore ?? false; + set => _noStore = value; } /// diff --git a/src/Microsoft.AspNetCore.Mvc.Core/RouteAttribute.cs b/src/Microsoft.AspNetCore.Mvc.Core/RouteAttribute.cs index 5a7875d9d3..db42bd2bc1 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/RouteAttribute.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/RouteAttribute.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Mvc } /// - public string Template { get; private set; } + public string Template { get; } /// /// Gets the route order. The order determines the order of route execution. Routes with a lower order @@ -44,13 +44,7 @@ namespace Microsoft.AspNetCore.Mvc } /// - int? IRouteTemplateProvider.Order - { - get - { - return _order; - } - } + int? IRouteTemplateProvider.Order => _order; /// public string Name { get; set; } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Routing/HttpMethodAttribute.cs b/src/Microsoft.AspNetCore.Mvc.Core/Routing/HttpMethodAttribute.cs index 7a7d1c203a..44095ee4ae 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Routing/HttpMethodAttribute.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Routing/HttpMethodAttribute.cs @@ -12,7 +12,6 @@ namespace Microsoft.AspNetCore.Mvc.Routing [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)] public abstract class HttpMethodAttribute : Attribute, IActionHttpMethodProvider, IRouteTemplateProvider { - private readonly IEnumerable _httpMethods; private int? _order; /// @@ -42,21 +41,15 @@ namespace Microsoft.AspNetCore.Mvc.Routing throw new ArgumentNullException(nameof(httpMethods)); } - _httpMethods = httpMethods; + HttpMethods = httpMethods; Template = template; } /// - public IEnumerable HttpMethods - { - get - { - return _httpMethods; - } - } + public IEnumerable HttpMethods { get; } /// - public string Template { get; private set; } + public string Template { get; } /// /// Gets the route order. The order determines the order of route execution. Routes with a lower @@ -71,13 +64,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing } /// - int? IRouteTemplateProvider.Order - { - get - { - return _order; - } - } + int? IRouteTemplateProvider.Order => _order; /// public string Name { get; set; } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Routing/KnownRouteValueConstraint.cs b/src/Microsoft.AspNetCore.Mvc.Core/Routing/KnownRouteValueConstraint.cs index 30a57e87cd..a80b3b510c 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Routing/KnownRouteValueConstraint.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Routing/KnownRouteValueConstraint.cs @@ -116,9 +116,9 @@ namespace Microsoft.AspNetCore.Mvc.Routing Items = items; } - public int Version { get; private set; } + public int Version { get; } - public string[] Items { get; private set; } + public string[] Items { get; } } } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/StatusCodeResult.cs b/src/Microsoft.AspNetCore.Mvc.Core/StatusCodeResult.cs index 614d604a55..8db690c94e 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/StatusCodeResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/StatusCodeResult.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Mvc /// /// Gets the HTTP status code. /// - public int StatusCode { get; private set; } + public int StatusCode { get; } /// public override void ExecuteResult(ActionContext context) diff --git a/src/Microsoft.AspNetCore.Mvc.Cors/CorsAuthorizationFilter.cs b/src/Microsoft.AspNetCore.Mvc.Cors/CorsAuthorizationFilter.cs index aa0bd66cec..184d9560be 100644 --- a/src/Microsoft.AspNetCore.Mvc.Cors/CorsAuthorizationFilter.cs +++ b/src/Microsoft.AspNetCore.Mvc.Cors/CorsAuthorizationFilter.cs @@ -18,8 +18,8 @@ namespace Microsoft.AspNetCore.Mvc.Cors /// public class CorsAuthorizationFilter : ICorsAuthorizationFilter { - private ICorsService _corsService; - private ICorsPolicyProvider _corsPolicyProvider; + private readonly ICorsService _corsService; + private readonly ICorsPolicyProvider _corsPolicyProvider; /// /// Creates a new instance of . @@ -38,16 +38,9 @@ namespace Microsoft.AspNetCore.Mvc.Cors public string PolicyName { get; set; } /// - public int Order - { - get - { - // Since clients' preflight requests would not have data to authenticate requests, this - // filter must run before any other authorization filters. - return int.MinValue + 100; - } - } - + // Since clients' preflight requests would not have data to authenticate requests, this + // filter must run before any other authorization filters. + public int Order => int.MinValue + 100; /// public async Task OnAuthorizationAsync(Filters.AuthorizationFilterContext context) diff --git a/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsApplicationModelProvider.cs b/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsApplicationModelProvider.cs index 5899dc21f7..6e21a082b4 100644 --- a/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsApplicationModelProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsApplicationModelProvider.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal { public class CorsApplicationModelProvider : IApplicationModelProvider { - public int Order { get { return -1000 + 10; } } + public int Order => -1000 + 10; public void OnProvidersExecuted(ApplicationModelProviderContext context) { @@ -28,18 +28,15 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal throw new ArgumentNullException(nameof(context)); } - IEnableCorsAttribute enableCors; - IDisableCorsAttribute disableCors; - foreach (var controllerModel in context.Result.Controllers) { - enableCors = controllerModel.Attributes.OfType().FirstOrDefault(); + var enableCors = controllerModel.Attributes.OfType().FirstOrDefault(); if (enableCors != null) { controllerModel.Filters.Add(new CorsAuthorizationFilterFactory(enableCors.PolicyName)); } - disableCors = controllerModel.Attributes.OfType().FirstOrDefault(); + var disableCors = controllerModel.Attributes.OfType().FirstOrDefault(); if (disableCors != null) { controllerModel.Filters.Add(new DisableCorsAuthorizationFilter()); diff --git a/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsAuthorizationFilterFactory.cs b/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsAuthorizationFilterFactory.cs index b2557fe667..9cb7146f5c 100644 --- a/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsAuthorizationFilterFactory.cs +++ b/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsAuthorizationFilterFactory.cs @@ -24,15 +24,9 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal } /// - public int Order - { - get - { - // Since clients' preflight requests would not have data to authenticate requests, this - // filter must run before any other authorization filters. - return int.MinValue + 100; - } - } + // Since clients' preflight requests would not have data to authenticate requests, this + // filter must run before any other authorization filters. + public int Order => int.MinValue + 100; /// public bool IsReusable => true; diff --git a/src/Microsoft.AspNetCore.Mvc.Cors/Internal/DisableCorsAuthorizationFilter.cs b/src/Microsoft.AspNetCore.Mvc.Cors/Internal/DisableCorsAuthorizationFilter.cs index 47b6c363a6..8ecd6cbfb6 100644 --- a/src/Microsoft.AspNetCore.Mvc.Cors/Internal/DisableCorsAuthorizationFilter.cs +++ b/src/Microsoft.AspNetCore.Mvc.Cors/Internal/DisableCorsAuthorizationFilter.cs @@ -16,15 +16,9 @@ namespace Microsoft.AspNetCore.Mvc.Cors.Internal public class DisableCorsAuthorizationFilter : ICorsAuthorizationFilter { /// - public int Order - { - get - { - // Since clients' preflight requests would not have data to authenticate requests, this - // filter must run before any other authorization filters. - return int.MinValue + 100; - } - } + // Since clients' preflight requests would not have data to authenticate requests, this + // filter must run before any other authorization filters. + public int Order => int.MinValue + 100; /// public Task OnAuthorizationAsync(AuthorizationFilterContext context) diff --git a/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataAnnotationsMetadataProvider.cs b/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataAnnotationsMetadataProvider.cs index 16cd00814f..a743844827 100644 --- a/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataAnnotationsMetadataProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataAnnotationsMetadataProvider.cs @@ -130,7 +130,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal // DisplayName // DisplayAttribute has precendence over DisplayNameAttribute. - if (displayAttribute != null && displayAttribute.GetName() != null) + if (displayAttribute?.GetName() != null) { if (localizer != null && !string.IsNullOrEmpty(displayAttribute.Name) && diff --git a/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/JsonResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/JsonResultExecutor.cs index 20427595b4..130ccc465e 100644 --- a/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/JsonResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/JsonResultExecutor.cs @@ -99,14 +99,12 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal var response = context.HttpContext.Response; - string resolvedContentType; - Encoding resolvedContentTypeEncoding; ResponseContentTypeHelper.ResolveContentTypeAndEncoding( result.ContentType, response.ContentType, DefaultContentType, - out resolvedContentType, - out resolvedContentTypeEncoding); + out var resolvedContentType, + out var resolvedContentTypeEncoding); response.ContentType = resolvedContentType; diff --git a/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonInputFormatter.cs b/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonInputFormatter.cs index 3eccb9f5e3..803eec6b17 100644 --- a/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonInputFormatter.cs +++ b/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonInputFormatter.cs @@ -149,7 +149,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters jsonReader.CloseInput = false; var successful = true; - EventHandler errorHandler = (sender, eventArgs) => + + void ErrorHandler(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs eventArgs) { successful = false; @@ -180,11 +181,11 @@ namespace Microsoft.AspNetCore.Mvc.Formatters // Failure to do so can cause the exception to be rethrown at every recursive level and // overflow the stack for x64 CLR processes eventArgs.ErrorContext.Handled = true; - }; + } var type = context.ModelType; var jsonSerializer = CreateJsonSerializer(); - jsonSerializer.Error += errorHandler; + jsonSerializer.Error += ErrorHandler; object model; try { @@ -193,7 +194,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters finally { // Clean up the error handler since CreateJsonSerializer() pools instances. - jsonSerializer.Error -= errorHandler; + jsonSerializer.Error -= ErrorHandler; ReleaseJsonSerializer(jsonSerializer); } diff --git a/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonPatchOperationsArrayProvider.cs b/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonPatchOperationsArrayProvider.cs index 49e0ff4003..840df5fdf8 100644 --- a/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonPatchOperationsArrayProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonPatchOperationsArrayProvider.cs @@ -31,10 +31,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json /// /// The order -999 ensures that this provider is executed right after the Microsoft.AspNetCore.Mvc.ApiExplorer.DefaultApiDescriptionProvider. /// - public int Order - { - get { return -999; } - } + public int Order => -999; /// public void OnProvidersExecuting(ApiDescriptionProviderContext context) diff --git a/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/DelegatingEnumerator.cs b/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/DelegatingEnumerator.cs index c5dd1860e5..f59b5cdfa7 100644 --- a/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/DelegatingEnumerator.cs +++ b/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/DelegatingEnumerator.cs @@ -53,13 +53,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml } /// - object IEnumerator.Current - { - get - { - return Current; - } - } + object IEnumerator.Current => Current; /// public void Dispose() diff --git a/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/SerializableErrorWrapperProvider.cs b/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/SerializableErrorWrapperProvider.cs index ad5666dea5..bd83514e6a 100644 --- a/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/SerializableErrorWrapperProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/SerializableErrorWrapperProvider.cs @@ -11,13 +11,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml public class SerializableErrorWrapperProvider : IWrapperProvider { /// - public Type WrappingType - { - get - { - return typeof(SerializableErrorWrapper); - } - } + public Type WrappingType => typeof(SerializableErrorWrapper); /// public object Wrap(object original) diff --git a/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerInputFormatter.cs b/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerInputFormatter.cs index cfcfe8f579..b57aa46dad 100644 --- a/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerInputFormatter.cs +++ b/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerInputFormatter.cs @@ -25,10 +25,10 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// public class XmlDataContractSerializerInputFormatter : TextInputFormatter { - private DataContractSerializerSettings _serializerSettings; - private ConcurrentDictionary _serializerCache = new ConcurrentDictionary(); + private readonly ConcurrentDictionary _serializerCache = new ConcurrentDictionary(); private readonly XmlDictionaryReaderQuotas _readerQuotas = FormattingUtilities.GetDefaultXmlReaderQuotas(); private readonly bool _suppressInputFormatterBuffering; + private DataContractSerializerSettings _serializerSettings; /// /// Initializes a new instance of DataContractSerializerInputFormatter @@ -78,10 +78,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// The quotas include - DefaultMaxDepth, DefaultMaxStringContentLength, DefaultMaxArrayLength, /// DefaultMaxBytesPerRead, DefaultMaxNameTableCharCount /// - public XmlDictionaryReaderQuotas XmlDictionaryReaderQuotas - { - get { return _readerQuotas; } - } + public XmlDictionaryReaderQuotas XmlDictionaryReaderQuotas => _readerQuotas; /// /// Gets or sets the used to configure the @@ -89,7 +86,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// public DataContractSerializerSettings SerializerSettings { - get { return _serializerSettings; } + get => _serializerSettings; set { if (value == null) @@ -137,8 +134,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters // Unwrap only if the original type was wrapped. if (type != context.ModelType) { - var unwrappable = deserializedObject as IUnwrappable; - if (unwrappable != null) + if (deserializedObject is IUnwrappable unwrappable) { deserializedObject = unwrappable.Unwrap(declaredType: context.ModelType); } @@ -234,8 +230,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters throw new ArgumentNullException(nameof(type)); } - object serializer; - if (!_serializerCache.TryGetValue(type, out serializer)) + if (!_serializerCache.TryGetValue(type, out var serializer)) { serializer = CreateSerializer(type); if (serializer != null) diff --git a/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerOutputFormatter.cs b/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerOutputFormatter.cs index fddc8e5afa..57b4071cfe 100644 --- a/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerOutputFormatter.cs +++ b/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerOutputFormatter.cs @@ -20,8 +20,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// public class XmlDataContractSerializerOutputFormatter : TextOutputFormatter { + private readonly ConcurrentDictionary _serializerCache = new ConcurrentDictionary(); private DataContractSerializerSettings _serializerSettings; - private ConcurrentDictionary _serializerCache = new ConcurrentDictionary(); /// /// Initializes a new instance of @@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// public DataContractSerializerSettings SerializerSettings { - get { return _serializerSettings; } + get => _serializerSettings; set { if (value == null) @@ -225,8 +225,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// The instance. protected virtual DataContractSerializer GetCachedSerializer(Type type) { - object serializer; - if (!_serializerCache.TryGetValue(type, out serializer)) + if (!_serializerCache.TryGetValue(type, out var serializer)) { serializer = CreateSerializer(type); if (serializer != null) diff --git a/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerInputFormatter.cs b/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerInputFormatter.cs index b946682c4a..4ce0807982 100644 --- a/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerInputFormatter.cs +++ b/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerInputFormatter.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// public class XmlSerializerInputFormatter : TextInputFormatter { - private ConcurrentDictionary _serializerCache = new ConcurrentDictionary(); + private readonly ConcurrentDictionary _serializerCache = new ConcurrentDictionary(); private readonly XmlDictionaryReaderQuotas _readerQuotas = FormattingUtilities.GetDefaultXmlReaderQuotas(); private readonly bool _suppressInputFormatterBuffering; @@ -75,10 +75,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// The quotas include - DefaultMaxDepth, DefaultMaxStringContentLength, DefaultMaxArrayLength, /// DefaultMaxBytesPerRead, DefaultMaxNameTableCharCount /// - public XmlDictionaryReaderQuotas XmlDictionaryReaderQuotas - { - get { return _readerQuotas; } - } + public XmlDictionaryReaderQuotas XmlDictionaryReaderQuotas => _readerQuotas; /// public override async Task ReadRequestBodyAsync( @@ -119,8 +116,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters // Unwrap only if the original type was wrapped. if (type != context.ModelType) { - var unwrappable = deserializedObject as IUnwrappable; - if (unwrappable != null) + if (deserializedObject is IUnwrappable unwrappable) { deserializedObject = unwrappable.Unwrap(declaredType: context.ModelType); } @@ -210,8 +206,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters throw new ArgumentNullException(nameof(type)); } - object serializer; - if (!_serializerCache.TryGetValue(type, out serializer)) + if (!_serializerCache.TryGetValue(type, out var serializer)) { serializer = CreateSerializer(type); if (serializer != null) diff --git a/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerOutputFormatter.cs b/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerOutputFormatter.cs index 16f1288074..7b04317e18 100644 --- a/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerOutputFormatter.cs +++ b/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerOutputFormatter.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// public class XmlSerializerOutputFormatter : TextOutputFormatter { - private ConcurrentDictionary _serializerCache = new ConcurrentDictionary(); + private readonly ConcurrentDictionary _serializerCache = new ConcurrentDictionary(); /// /// Initializes a new instance of @@ -203,8 +203,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// The instance. protected virtual XmlSerializer GetCachedSerializer(Type type) { - object serializer; - if (!_serializerCache.TryGetValue(type, out serializer)) + if (!_serializerCache.TryGetValue(type, out var serializer)) { serializer = CreateSerializer(type); if (serializer != null) diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/HelperResult.cs b/src/Microsoft.AspNetCore.Mvc.Razor/HelperResult.cs index 22e55bcc7f..d69f37d59e 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor/HelperResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor/HelperResult.cs @@ -36,10 +36,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor /// /// Gets the asynchronous delegate to invoke when is called. /// - public Func WriteAction - { - get { return _asyncAction; } - } + public Func WriteAction => _asyncAction; /// /// Method invoked to produce content from the . diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/Internal/RazorViewCompiler.cs b/src/Microsoft.AspNetCore.Mvc.Razor/Internal/RazorViewCompiler.cs index 0f28387e2d..575c7f6bc8 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor/Internal/RazorViewCompiler.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor/Internal/RazorViewCompiler.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal private readonly Action _compilationCallback; private readonly ILogger _logger; private readonly CSharpCompiler _csharpCompiler; - private IMemoryCache _cache; + private readonly IMemoryCache _cache; public RazorViewCompiler( IFileProvider fileProvider, diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/LanguageViewLocationExpander.cs b/src/Microsoft.AspNetCore.Mvc.Razor/LanguageViewLocationExpander.cs index 6532d0d619..1ed92110bc 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor/LanguageViewLocationExpander.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor/LanguageViewLocationExpander.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor public class LanguageViewLocationExpander : IViewLocationExpander { private const string ValueKey = "language"; - private LanguageViewLocationExpanderFormat _format; + private readonly LanguageViewLocationExpanderFormat _format; /// /// Instantiates a new instance. @@ -68,8 +68,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor throw new ArgumentNullException(nameof(viewLocations)); } - string value; - context.Values.TryGetValue(ValueKey, out value); + context.Values.TryGetValue(ValueKey, out var value); if (!string.IsNullOrEmpty(value)) { diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/RazorPage.cs b/src/Microsoft.AspNetCore.Mvc.Razor/RazorPage.cs index 303eac1243..3d13f977f7 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor/RazorPage.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor/RazorPage.cs @@ -183,11 +183,10 @@ namespace Microsoft.AspNetCore.Mvc.Razor throw new InvalidOperationException(message); } - RenderAsyncDelegate renderDelegate; - if (PreviousSectionWriters.TryGetValue(sectionName, out renderDelegate)) + if (PreviousSectionWriters.TryGetValue(sectionName, out var renderDelegate)) { _renderedSections.Add(sectionName); - + await renderDelegate(); // Return a token value that allows the Write call that wraps the RenderSection \ RenderSectionAsync diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageOfT.cs b/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageOfT.cs index 2270c57ce0..923cf13525 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageOfT.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageOfT.cs @@ -15,13 +15,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor /// /// Gets the Model property of the property. /// - public TModel Model - { - get - { - return ViewData == null ? default(TModel) : ViewData.Model; - } - } + public TModel Model => ViewData == null ? default(TModel) : ViewData.Model; /// /// Gets or sets the dictionary for view data. diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/RazorView.cs b/src/Microsoft.AspNetCore.Mvc.Razor/RazorView.cs index bb57b26c95..19bee46190 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor/RazorView.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor/RazorView.cs @@ -74,10 +74,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor } /// - public string Path - { - get { return RazorPage.Path; } - } + public string Path => RazorPage.Path; /// /// Gets instance that the views executes on. diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngine.cs b/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngine.cs index 143a64fb46..243a899f46 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngine.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngine.cs @@ -302,13 +302,12 @@ namespace Microsoft.AspNetCore.Mvc.Razor return pagePath; } - string absolutePath; if (string.IsNullOrEmpty(executingFilePath)) { // Given a relative path i.e. not yet application-relative (starting with "~/" or "/"), interpret // path relative to currently-executing view, if any. // Not yet executing a view. Start in app root. - absolutePath = "/" + pagePath; + var absolutePath = "/" + pagePath; return ViewEnginePath.ResolvePath(absolutePath); } diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngineOptions.cs b/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngineOptions.cs index 5ea398ce5f..07c9a36b73 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngineOptions.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngineOptions.cs @@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor /// public Action CompilationCallback { - get { return _compilationCallback; } + get => _compilationCallback; set { if (value == null) @@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor /// public CSharpParseOptions ParseOptions { - get { return _parseOptions; } + get => _parseOptions; set { if (value == null) @@ -143,7 +143,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor /// public CSharpCompilationOptions CompilationOptions { - get { return _compilationOptions; } + get => _compilationOptions; set { if (value == null) diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/TagHelperComponentTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/TagHelperComponentTagHelper.cs index e12404574c..9946993dc3 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/TagHelperComponentTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/TagHelperComponentTagHelper.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers { private readonly ILogger _logger; - private IEnumerable _components; + private readonly IEnumerable _components; /// /// Creates a new and orders the @@ -31,7 +31,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers /// The are ordered after the /// creation of the to position the s /// added from controllers and views correctly. - public TagHelperComponentTagHelper(ITagHelperComponentManager manager, + public TagHelperComponentTagHelper( + ITagHelperComponentManager manager, ILoggerFactory loggerFactory) { if (manager == null) diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/UrlResolutionTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/UrlResolutionTagHelper.cs index 0bd0450735..21ae7d4ce3 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/UrlResolutionTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/UrlResolutionTagHelper.cs @@ -96,13 +96,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers } /// - public override int Order - { - get - { - return -1000 - 999; - } - } + public override int Order => -1000 - 999; protected IUrlHelperFactory UrlHelperFactory { get; } diff --git a/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageHandlerExecutedContext.cs b/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageHandlerExecutedContext.cs index 084b44a825..5597fdc92e 100644 --- a/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageHandlerExecutedContext.cs +++ b/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageHandlerExecutedContext.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Mvc.Filters /// The handler method to be invoked, may be null. /// The handler instance associated with the page. public PageHandlerExecutedContext( - PageContext pageContext, + PageContext pageContext, IList filters, HandlerMethodDescriptor handlerMethod, object handlerInstance) @@ -45,13 +45,8 @@ namespace Microsoft.AspNetCore.Mvc.Filters /// /// Gets the descriptor associated with the current page. /// - public new virtual CompiledPageActionDescriptor ActionDescriptor - { - get - { - return (CompiledPageActionDescriptor)base.ActionDescriptor; - } - } + public new virtual CompiledPageActionDescriptor ActionDescriptor => + (CompiledPageActionDescriptor)base.ActionDescriptor; /// /// Gets or sets an indication that an page filter short-circuited the action and the page filter pipeline. @@ -99,10 +94,7 @@ namespace Microsoft.AspNetCore.Mvc.Filters /// public virtual ExceptionDispatchInfo ExceptionDispatchInfo { - get - { - return _exceptionDispatchInfo; - } + get => _exceptionDispatchInfo; set { diff --git a/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageHandlerExecutingContext.cs b/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageHandlerExecutingContext.cs index 0f712502b9..25b9b90b70 100644 --- a/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageHandlerExecutingContext.cs +++ b/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageHandlerExecutingContext.cs @@ -49,13 +49,8 @@ namespace Microsoft.AspNetCore.Mvc.Filters /// /// Gets the descriptor associated with the current page. /// - public new virtual CompiledPageActionDescriptor ActionDescriptor - { - get - { - return (CompiledPageActionDescriptor)base.ActionDescriptor; - } - } + public new virtual CompiledPageActionDescriptor ActionDescriptor => + (CompiledPageActionDescriptor)base.ActionDescriptor; /// /// Gets or sets the to execute. Setting to a non-null diff --git a/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageHandlerSelectedContext.cs b/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageHandlerSelectedContext.cs index 49d43e3dfa..8489ab3fe5 100644 --- a/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageHandlerSelectedContext.cs +++ b/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageHandlerSelectedContext.cs @@ -38,13 +38,8 @@ namespace Microsoft.AspNetCore.Mvc.Filters /// /// Gets the descriptor associated with the current page. /// - public new virtual CompiledPageActionDescriptor ActionDescriptor - { - get - { - return (CompiledPageActionDescriptor)base.ActionDescriptor; - } - } + public new virtual CompiledPageActionDescriptor ActionDescriptor => + (CompiledPageActionDescriptor)base.ActionDescriptor; /// /// Gets or sets the descriptor for the handler method about to be invoked. diff --git a/src/Microsoft.AspNetCore.Mvc.RazorPages/PageBase.cs b/src/Microsoft.AspNetCore.Mvc.RazorPages/PageBase.cs index ca5fa86731..fee31ea83c 100644 --- a/src/Microsoft.AspNetCore.Mvc.RazorPages/PageBase.cs +++ b/src/Microsoft.AspNetCore.Mvc.RazorPages/PageBase.cs @@ -57,13 +57,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages /// /// Gets the for the executing action. /// - public RouteData RouteData - { - get - { - return PageContext.RouteData; - } - } + public RouteData RouteData => PageContext.RouteData; /// /// Gets the . diff --git a/src/Microsoft.AspNetCore.Mvc.RazorPages/PageContext.cs b/src/Microsoft.AspNetCore.Mvc.RazorPages/PageContext.cs index a1cdcef1a8..cfede5d167 100644 --- a/src/Microsoft.AspNetCore.Mvc.RazorPages/PageContext.cs +++ b/src/Microsoft.AspNetCore.Mvc.RazorPages/PageContext.cs @@ -43,10 +43,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages /// public virtual new CompiledPageActionDescriptor ActionDescriptor { - get - { - return _actionDescriptor; - } + get => _actionDescriptor; set { if (value == null) @@ -89,10 +86,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages /// public virtual ViewDataDictionary ViewData { - get - { - return _viewData; - } + get => _viewData; set { if (value == null) @@ -109,10 +103,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages /// public virtual IList> ViewStartFactories { - get - { - return _viewStartFactories; - } + get => _viewStartFactories; set { if (value == null) diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/AnchorTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/AnchorTagHelper.cs index 17be080c6b..175523d2fb 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/AnchorTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/AnchorTagHelper.cs @@ -50,13 +50,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers } /// - public override int Order - { - get - { - return -1000; - } - } + public override int Order => -1000; protected IHtmlGenerator Generator { get; } diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelper.cs index 8d5c7cc8fa..48798e76c1 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelper.cs @@ -69,8 +69,6 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers { var cacheKey = new CacheTagKey(this, context); - MemoryCacheEntryOptions options; - while (content == null) { Task result; @@ -82,7 +80,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers // Create an entry link scope and flow it so that any tokens related to the cache entries // created within this scope get copied to this scope. - options = GetMemoryCacheEntryOptions(); + var options = GetMemoryCacheEntryOptions(); options.AddExpirationToken(new CancellationChangeToken(tokenSource.Token)); var tcs = new TaskCompletionSource(); diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelperBase.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelperBase.cs index 847e5da0a3..f147c38e89 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelperBase.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelperBase.cs @@ -35,13 +35,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers } /// - public override int Order - { - get - { - return -1000; - } - } + public override int Order => -1000; /// /// Gets the which encodes the content to be cached. diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/ImageTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/ImageTagHelper.cs index 6f2a9e09a9..587dfc3567 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/ImageTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/ImageTagHelper.cs @@ -48,13 +48,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers } /// - public override int Order - { - get - { - return -1000; - } - } + public override int Order => -1000; /// /// Source of the image. diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/InputTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/InputTagHelper.cs index 820f966fb8..0b618900a8 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/InputTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/InputTagHelper.cs @@ -72,13 +72,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers } /// - public override int Order - { - get - { - return -1000; - } - } + public override int Order => -1000; protected IHtmlGenerator Generator { get; } diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/FileProviderGlobbingDirectory.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/FileProviderGlobbingDirectory.cs index c4d77dbeb8..c2d0bf6227 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/FileProviderGlobbingDirectory.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/FileProviderGlobbingDirectory.cs @@ -64,21 +64,9 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers.Internal } } - public override string Name - { - get - { - return _fileInfo?.Name; - } - } + public override string Name => _fileInfo?.Name; - public override DirectoryInfoBase ParentDirectory - { - get - { - return _parent; - } - } + public override DirectoryInfoBase ParentDirectory => _parent; public override IEnumerable EnumerateFileSystemInfos() { diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/LabelTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/LabelTagHelper.cs index d8aefe3229..b0668eed68 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/LabelTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/LabelTagHelper.cs @@ -27,13 +27,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers } /// - public override int Order - { - get - { - return -1000; - } - } + public override int Order => -1000; [HtmlAttributeNotBound] [ViewContext] diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/LinkTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/LinkTagHelper.cs index 9d74409e1c..84655b04be 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/LinkTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/LinkTagHelper.cs @@ -115,13 +115,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers } /// - public override int Order - { - get - { - return -1000; - } - } + public override int Order => -1000; /// /// Address of the linked resource. diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/OptionTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/OptionTagHelper.cs index 56c001d1e9..8f2678e968 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/OptionTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/OptionTagHelper.cs @@ -31,13 +31,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers } /// - public override int Order - { - get - { - return -1000; - } - } + public override int Order => -1000; protected IHtmlGenerator Generator { get; } diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/ScriptTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/ScriptTagHelper.cs index 32ece082c0..8faf17807f 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/ScriptTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/ScriptTagHelper.cs @@ -97,13 +97,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers } /// - public override int Order - { - get - { - return -1000; - } - } + public override int Order => -1000; /// /// Address of the external script to use. diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/SelectTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/SelectTagHelper.cs index cce6220330..c7657f17f1 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/SelectTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/SelectTagHelper.cs @@ -36,13 +36,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers } /// - public override int Order - { - get - { - return -1000; - } - } + public override int Order => -1000; protected IHtmlGenerator Generator { get; } diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/TextAreaTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/TextAreaTagHelper.cs index e8b6893b15..bf04f35d3a 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/TextAreaTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/TextAreaTagHelper.cs @@ -26,13 +26,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers } /// - public override int Order - { - get - { - return -1000; - } - } + public override int Order => -1000; protected IHtmlGenerator Generator { get; } diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/ValidationMessageTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/ValidationMessageTagHelper.cs index 5d6ec1ea6d..80820f6894 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/ValidationMessageTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/ValidationMessageTagHelper.cs @@ -28,13 +28,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers } /// - public override int Order - { - get - { - return -1000; - } - } + public override int Order => -1000; [HtmlAttributeNotBound] [ViewContext] diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/ValidationSummaryTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/ValidationSummaryTagHelper.cs index 3a68c793a1..ee090b28c6 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/ValidationSummaryTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/ValidationSummaryTagHelper.cs @@ -28,13 +28,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers } /// - public override int Order - { - get - { - return -1000; - } - } + public override int Order => -1000; [HtmlAttributeNotBound] [ViewContext] @@ -54,10 +48,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers [HtmlAttributeName(ValidationSummaryAttributeName)] public ValidationSummary ValidationSummary { - get - { - return _validationSummary; - } + get => _validationSummary; set { switch (value) diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/HtmlAttributePropertyHelper.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/HtmlAttributePropertyHelper.cs index 6fd48b6ea4..3b0db8ee6e 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/HtmlAttributePropertyHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/HtmlAttributePropertyHelper.cs @@ -30,10 +30,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal public override string Name { - get - { - return base.Name; - } + get => base.Name; protected set { diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/MvcViewFeaturesLoggerExtensions.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/MvcViewFeaturesLoggerExtensions.cs index df634e6a37..b29284b00a 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/MvcViewFeaturesLoggerExtensions.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/MvcViewFeaturesLoggerExtensions.cs @@ -217,17 +217,11 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal } } - public int Count - { - get - { - return 2; - } - } + public int Count => 2; public IEnumerator> GetEnumerator() { - for (int i = 0; i < Count; ++i) + for (var i = 0; i < Count; ++i) { yield return this[i]; } diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/SaveTempDataFilter.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/SaveTempDataFilter.cs index 4984a9b44d..eb4653484d 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/SaveTempDataFilter.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/SaveTempDataFilter.cs @@ -100,8 +100,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal for (var i = 0; i < filters.Count; i++) { - var callback = filters[i] as ISaveTempDataCallback; - if (callback != null) + if (filters[i] is ISaveTempDataCallback callback) { callback.OnTempDataSaving(tempData); } diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/SaveTempDataPropertyFilter/TempDataProperty.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/SaveTempDataPropertyFilter/TempDataProperty.cs index 160172c823..8a0349048e 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/SaveTempDataPropertyFilter/TempDataProperty.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/SaveTempDataPropertyFilter/TempDataProperty.cs @@ -8,9 +8,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal { public struct TempDataProperty { - private Func _getter; + private readonly Func _getter; - private Action _setter; + private readonly Action _setter; public TempDataProperty(PropertyInfo propertyInfo, Func getter, Action setter) { diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/TempDataSerializer.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/TempDataSerializer.cs index 29ad5bbd2f..7915dcac3d 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/TempDataSerializer.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/TempDataSerializer.cs @@ -67,8 +67,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal if (jArrayValue != null && jArrayValue.Count > 0) { var arrayType = jArrayValue[0].Type; - Type returnType; - if (_tokenTypeLookup.TryGetValue(arrayType, out returnType)) + if (_tokenTypeLookup.TryGetValue(arrayType, out var returnType)) { var arrayConverter = _arrayConverters.GetOrAdd(returnType, type => { @@ -95,8 +94,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal } var jTokenType = jObjectValue.Properties().First().Value.Type; - Type valueType; - if (_tokenTypeLookup.TryGetValue(jTokenType, out valueType)) + if (_tokenTypeLookup.TryGetValue(jTokenType, out var valueType)) { var dictionaryConverter = _dictionaryConverters.GetOrAdd(valueType, type => { @@ -114,9 +112,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal throw new InvalidOperationException(message); } } - else if (item.Value is long) + else if (item.Value is long longValue) { - var longValue = (long)item.Value; if (longValue >= int.MinValue && longValue <= int.MaxValue) { // BsonReader casts all ints to longs. We'll attempt to work around this by force converting diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ValidationHelpers.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ValidationHelpers.cs index c2df1617bb..54c40227dd 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ValidationHelpers.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ValidationHelpers.cs @@ -49,8 +49,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal { if (excludePropertyErrors) { - ModelStateEntry ms; - viewData.ModelState.TryGetValue(viewData.TemplateInfo.HtmlFieldPrefix, out ms); + viewData.ModelState.TryGetValue(viewData.TemplateInfo.HtmlFieldPrefix, out var ms); if (ms != null) { diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewBuffer.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewBuffer.cs index 601c8b5771..5143e515d4 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewBuffer.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewBuffer.cs @@ -186,15 +186,13 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal { var value = page.Buffer[j]; - var valueAsString = value.Value as string; - if (valueAsString != null) + if (value.Value is string valueAsString) { writer.Write(valueAsString); continue; } - var valueAsHtmlContent = value.Value as IHtmlContent; - if (valueAsHtmlContent != null) + if (value.Value is IHtmlContent valueAsHtmlContent) { valueAsHtmlContent.WriteTo(writer, encoder); continue; @@ -228,22 +226,19 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal { var value = page.Buffer[j]; - var valueAsString = value.Value as string; - if (valueAsString != null) + if (value.Value is string valueAsString) { await writer.WriteAsync(valueAsString); continue; } - var valueAsViewBuffer = value.Value as ViewBuffer; - if (valueAsViewBuffer != null) + if (value.Value is ViewBuffer valueAsViewBuffer) { await valueAsViewBuffer.WriteToAsync(writer, encoder); continue; } - var valueAsHtmlContent = value.Value as IHtmlContent; - if (valueAsHtmlContent != null) + if (value.Value is IHtmlContent valueAsHtmlContent) { valueAsHtmlContent.WriteTo(writer, encoder); await writer.FlushAsync(); @@ -296,8 +291,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal // Perf: We have an efficient implementation when the destination is another view buffer, // we can just insert our pages as-is. - var other = destination as ViewBuffer; - if (other != null) + if (destination is ViewBuffer other) { MoveTo(other); return; diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewComponentResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewComponentResultExecutor.cs index 8715d407b3..19a8ba4bd3 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewComponentResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewComponentResultExecutor.cs @@ -89,14 +89,12 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal tempData = _tempDataDictionaryFactory.GetTempData(context.HttpContext); } - string resolvedContentType; - Encoding resolvedContentTypeEncoding; ResponseContentTypeHelper.ResolveContentTypeAndEncoding( viewComponentResult.ContentType, response.ContentType, ViewExecutor.DefaultContentType, - out resolvedContentType, - out resolvedContentTypeEncoding); + out var resolvedContentType, + out var resolvedContentTypeEncoding); response.ContentType = resolvedContentType; diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewResultExecutor.cs index a2aee6b8cc..4b4badc60f 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewResultExecutor.cs @@ -183,16 +183,14 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal throw new ArgumentNullException(nameof(context)); } - object routeValue; - if (!context.RouteData.Values.TryGetValue(ActionNameKey, out routeValue)) + if (!context.RouteData.Values.TryGetValue(ActionNameKey, out var routeValue)) { return null; } var actionDescriptor = context.ActionDescriptor; string normalizedValue = null; - string value; - if (actionDescriptor.RouteValues.TryGetValue(ActionNameKey, out value) && + if (actionDescriptor.RouteValues.TryGetValue(ActionNameKey, out var value) && !string.IsNullOrEmpty(value)) { normalizedValue = value; diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/MvcViewOptions.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/MvcViewOptions.cs index 89d594493e..9805c88aeb 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/MvcViewOptions.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/MvcViewOptions.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Mvc /// public HtmlHelperOptions HtmlHelperOptions { - get { return _htmlHelperOptions; } + get => _htmlHelperOptions; set { if (value == null) diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/RemoteAttribute.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/RemoteAttribute.cs index 8818b6acab..119ba657a3 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/RemoteAttribute.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/RemoteAttribute.cs @@ -125,7 +125,7 @@ namespace Microsoft.AspNetCore.Mvc /// public string AdditionalFields { - get { return _additionalFields; } + get => _additionalFields; set { _additionalFields = value ?? string.Empty; diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Rendering/MultiSelectList.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Rendering/MultiSelectList.cs index d09a9bc768..360b75b87e 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Rendering/MultiSelectList.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Rendering/MultiSelectList.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Mvc.Rendering /// public class MultiSelectList : IEnumerable { - private IList _groups; + private readonly IList _groups; private IList _selectListItems; public MultiSelectList(IEnumerable items) @@ -100,15 +100,15 @@ namespace Microsoft.AspNetCore.Mvc.Rendering /// /// Gets or sets the data group field. /// - public string DataGroupField { get; private set; } + public string DataGroupField { get; } - public string DataTextField { get; private set; } + public string DataTextField { get; } - public string DataValueField { get; private set; } + public string DataValueField { get; } - public IEnumerable Items { get; private set; } + public IEnumerable Items { get; } - public IEnumerable SelectedValues { get; private set; } + public IEnumerable SelectedValues { get; } public virtual IEnumerator GetEnumerator() { diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Rendering/SelectList.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Rendering/SelectList.cs index 98e9f1178e..7d30bffeb7 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Rendering/SelectList.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Rendering/SelectList.cs @@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Mvc.Rendering SelectedValue = selectedValue; } - public object SelectedValue { get; private set; } + public object SelectedValue { get; } private static IEnumerable ToEnumerable(object selectedValue) { diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Rendering/ViewContext.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Rendering/ViewContext.cs index 957260bf94..88b8b0d74d 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Rendering/ViewContext.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Rendering/ViewContext.cs @@ -144,7 +144,7 @@ namespace Microsoft.AspNetCore.Mvc.Rendering /// public virtual FormContext FormContext { - get { return _formContext; } + get => _formContext; set { diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewComponent.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewComponent.cs index 83d71c6d7d..f0ae37312b 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewComponent.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewComponent.cs @@ -31,35 +31,17 @@ namespace Microsoft.AspNetCore.Mvc /// /// Gets the . /// - public HttpContext HttpContext - { - get - { - return ViewContext?.HttpContext; - } - } + public HttpContext HttpContext => ViewContext?.HttpContext; /// /// Gets the . /// - public HttpRequest Request - { - get - { - return ViewContext?.HttpContext?.Request; - } - } + public HttpRequest Request => ViewContext?.HttpContext?.Request; /// /// Gets the for the current user. /// - public IPrincipal User - { - get - { - return ViewContext?.HttpContext?.User; - } - } + public IPrincipal User => ViewContext?.HttpContext?.User; /// /// Gets the for the current user. @@ -69,13 +51,7 @@ namespace Microsoft.AspNetCore.Mvc /// /// Gets the for the current request. /// - public RouteData RouteData - { - get - { - return ViewContext?.RouteData; - } - } + public RouteData RouteData => ViewContext?.RouteData; /// /// Gets the view bag. @@ -96,13 +72,7 @@ namespace Microsoft.AspNetCore.Mvc /// /// Gets the . /// - public ModelStateDictionary ModelState - { - get - { - return ViewData?.ModelState; - } - } + public ModelStateDictionary ModelState => ViewData?.ModelState; /// /// Gets or sets the . @@ -159,35 +129,17 @@ namespace Microsoft.AspNetCore.Mvc /// /// Gets the . /// - public ViewContext ViewContext - { - get - { - return ViewComponentContext.ViewContext; - } - } + public ViewContext ViewContext => ViewComponentContext.ViewContext; /// /// Gets the . /// - public ViewDataDictionary ViewData - { - get - { - return ViewComponentContext.ViewData; - } - } + public ViewDataDictionary ViewData => ViewComponentContext.ViewData; /// /// Gets the . /// - public ITempDataDictionary TempData - { - get - { - return ViewComponentContext.TempData; - } - } + public ITempDataDictionary TempData => ViewComponentContext.TempData; /// /// Gets or sets the . diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewEngines/ViewEngineResult.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewEngines/ViewEngineResult.cs index 02d2ee4693..6fb58cc334 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewEngines/ViewEngineResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewEngines/ViewEngineResult.cs @@ -20,10 +20,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewEngines public string ViewName { get; private set; } - public bool Success - { - get { return View != null; } - } + public bool Success => View != null; public static ViewEngineResult NotFound( string viewName, diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/AttributeDictionary.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/AttributeDictionary.cs index 1951b1561c..0c55c80a4e 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/AttributeDictionary.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/AttributeDictionary.cs @@ -60,49 +60,19 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures public int Count => _items == null ? 0 : _items.Count; /// - public bool IsReadOnly - { - get - { - return false; - } - } + public bool IsReadOnly => false; /// - public ICollection Keys - { - get - { - return new KeyCollection(this); - } - } + public ICollection Keys => new KeyCollection(this); /// - public ICollection Values - { - get - { - return new ValueCollection(this); - } - } + public ICollection Values => new ValueCollection(this); /// - IEnumerable IReadOnlyDictionary.Keys - { - get - { - return new KeyCollection(this); - } - } + IEnumerable IReadOnlyDictionary.Keys => new KeyCollection(this); /// - IEnumerable IReadOnlyDictionary.Values - { - get - { - return new ValueCollection(this); - } - } + IEnumerable IReadOnlyDictionary.Values => new ValueCollection(this); private KeyValuePair Get(int index) { @@ -389,22 +359,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures } /// - public KeyValuePair Current - { - get - { - return _attributes.Get(_index); - } - } + public KeyValuePair Current => _attributes.Get(_index); /// - object IEnumerator.Current - { - get - { - return Current; - } - } + object IEnumerator.Current => Current; /// public void Dispose() @@ -486,7 +444,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures public Enumerator GetEnumerator() { - return new Enumerator(this._attributes); + return new Enumerator(_attributes); } public bool Remove(string item) @@ -517,21 +475,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures _index = -1; } - public string Current - { - get - { - return _attributes.Get(_index).Key; - } - } + public string Current => _attributes.Get(_index).Key; - object IEnumerator.Current - { - get - { - return Current; - } - } + object IEnumerator.Current => Current; public void Dispose() { @@ -606,7 +552,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures public Enumerator GetEnumerator() { - return new Enumerator(this._attributes); + return new Enumerator(_attributes); } public bool Remove(string item) @@ -637,21 +583,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures _index = -1; } - public string Current - { - get - { - return _attributes.Get(_index).Key; - } - } + public string Current => _attributes.Get(_index).Key; - object IEnumerator.Current - { - get - { - return Current; - } - } + object IEnumerator.Current => Current; public void Dispose() { diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs index 592b05fc89..0d36d43a3a 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs @@ -88,24 +88,12 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures /// public Html5DateRenderingMode Html5DateRenderingMode { - get - { - return ViewContext.Html5DateRenderingMode; - } - set - { - ViewContext.Html5DateRenderingMode = value; - } + get => ViewContext.Html5DateRenderingMode; + set => ViewContext.Html5DateRenderingMode = value; } /// - public string IdAttributeDotReplacement - { - get - { - return _htmlGenerator.IdAttributeDotReplacement; - } - } + public string IdAttributeDotReplacement => _htmlGenerator.IdAttributeDotReplacement; /// public ViewContext ViewContext @@ -119,38 +107,17 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures return _viewContext; } - private set - { - _viewContext = value; - } + private set => _viewContext = value; } /// - public dynamic ViewBag - { - get - { - return ViewContext.ViewBag; - } - } + public dynamic ViewBag => ViewContext.ViewBag; /// - public ViewDataDictionary ViewData - { - get - { - return ViewContext.ViewData; - } - } + public ViewDataDictionary ViewData => ViewContext.ViewData; /// - public ITempDataDictionary TempData - { - get - { - return ViewContext.TempData; - } - } + public ITempDataDictionary TempData => ViewContext.TempData; /// public UrlEncoder UrlEncoder { get; } diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelperOptions.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelperOptions.cs index 1b132a4491..952bc7b4d9 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelperOptions.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelperOptions.cs @@ -28,10 +28,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures /// public string IdAttributeDotReplacement { - get - { - return _idAttributeDotReplacement; - } + get => _idAttributeDotReplacement; set { if (value == null) diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ModelExpression.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ModelExpression.cs index 6981524ace..73089f5212 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ModelExpression.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ModelExpression.cs @@ -39,18 +39,12 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures /// /// String representation of the of interest. /// - public string Name { get; private set; } + public string Name { get; } /// /// Metadata about the of interest. /// - public ModelMetadata Metadata - { - get - { - return ModelExplorer.Metadata; - } - } + public ModelMetadata Metadata => ModelExplorer.Metadata; /// /// Gets the model object for the of interest. @@ -59,13 +53,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures /// Getting will evaluate a compiled version of the original /// . /// - public object Model - { - get - { - return ModelExplorer.Model; - } - } + public object Model => ModelExplorer.Model; /// /// Gets the model explorer for the of interest. diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/TempDataDictionary.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/TempDataDictionary.cs index 38ea9bae88..95abb49bb4 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/TempDataDictionary.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/TempDataDictionary.cs @@ -258,8 +258,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures private sealed class TempDataDictionaryEnumerator : IEnumerator> { - private IEnumerator> _enumerator; - private TempDataDictionary _tempData; + private readonly IEnumerator> _enumerator; + private readonly TempDataDictionary _tempData; public TempDataDictionaryEnumerator(TempDataDictionary tempData) { @@ -278,10 +278,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures } } - object IEnumerator.Current - { - get { return Current; } - } + object IEnumerator.Current => Current; public bool MoveNext() { diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewDataDictionary.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewDataDictionary.cs index 309b565395..c560b810db 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewDataDictionary.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewDataDictionary.cs @@ -367,7 +367,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures public object Eval(string expression) { var info = GetViewDataInfo(expression); - return (info != null) ? info.Value : null; + return info?.Value; } /// diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewDataInfo.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewDataInfo.cs index d2f5b928d3..9ae0d8eb5b 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewDataInfo.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewDataInfo.cs @@ -53,9 +53,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures _valueAccessor = valueAccessor; } - public object Container { get; private set; } + public object Container { get; } - public PropertyInfo PropertyInfo { get; private set; } + public PropertyInfo PropertyInfo { get; } public object Value {