From 18c80d156c77d66b7287bef30a1b0bb2d0014772 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 25 Sep 2015 12:36:05 -0700 Subject: [PATCH] Replace NotNullAttribute with thrown exceptions --- samples/MvcSample.Web/project.json | 10 +- samples/TagHelperSample.Web/project.json | 4 +- .../AnchorTagHelper.cs | 17 +- .../Controller.cs | 256 ++++++++++-- .../MvcViewFeaturesMvcBuilderExtensions.cs | 17 +- ...MvcViewFeaturesMvcCoreBuilderExtensions.cs | 38 +- .../IViewComponentResult.cs | 5 +- .../Internal/ICanHasViewContext.cs | 3 +- .../Internal/NullView.cs | 11 +- .../Internal/ValidationHelpers.cs | 9 +- .../MvcViewOptions.cs | 21 +- .../PartialViewResult.cs | 8 +- .../RemoteAttribute.cs | 15 +- .../Rendering/HtmlHelperDisplayExtensions.cs | 148 ++++++- .../HtmlHelperDisplayNameExtensions.cs | 23 +- .../Rendering/HtmlHelperEditorExtensions.cs | 177 ++++++-- .../Rendering/HtmlHelperFormExtensions.cs | 108 ++++- .../Rendering/HtmlHelperInputExtensions.cs | 385 +++++++++++++----- .../Rendering/HtmlHelperLabelExtensions.cs | 86 +++- .../Rendering/HtmlHelperLinkExtensions.cs | 157 +++++-- .../Rendering/HtmlHelperNameExtensions.cs | 17 +- .../Rendering/HtmlHelperPartialExtensions.cs | 142 ++++++- .../Rendering/HtmlHelperSelectExtensions.cs | 129 ++++-- .../HtmlHelperValidationExtensions.cs | 156 +++++-- .../Rendering/HtmlHelperValueExtensions.cs | 37 +- .../Rendering/HtmlString.cs | 13 +- .../Rendering/IHtmlHelper.cs | 13 +- .../Rendering/IHtmlHelperOfT.cs | 39 +- .../Rendering/IJsonHelper.cs | 5 +- .../Rendering/MultiSelectList.cs | 32 +- .../Rendering/MvcForm.cs | 8 +- .../Rendering/SelectList.cs | 34 +- .../Rendering/TagBuilder.cs | 14 +- .../ViewComponentHelperExtensions.cs | 32 +- .../Rendering/ViewContext.cs | 72 +++- .../SkipStatusCodePagesAttribute.cs | 14 +- .../ViewComponent.cs | 38 +- .../ViewComponentResult.cs | 1 - .../ContentViewComponentResult.cs | 30 +- .../DefaultViewComponentActivator.cs | 12 +- .../DefaultViewComponentDescriptorProvider.cs | 9 +- .../DefaultViewComponentHelper.cs | 113 ++++- .../DefaultViewComponentInvoker.cs | 64 ++- .../DefaultViewComponentInvokerFactory.cs | 9 +- .../DefaultViewComponentSelector.cs | 8 +- .../ViewComponents/IViewComponentInvoker.cs | 5 +- .../IViewComponentInvokerFactory.cs | 4 +- .../ViewComponents/IViewComponentSelector.cs | 4 +- .../ViewComponents/JsonViewComponentResult.cs | 23 +- .../ViewComponents/ViewComponentContext.cs | 32 +- .../ViewComponentConventions.cs | 22 +- .../ViewComponentDescriptorCollection.cs | 9 +- .../ViewComponentMethodSelector.cs | 15 +- .../ViewComponents/ViewViewComponentResult.cs | 15 +- .../ViewEngines/CompositeViewEngine.cs | 30 +- .../ViewEngines/IView.cs | 3 +- .../ViewEngines/ViewEngineResult.cs | 27 +- .../ViewFeatures/CachedExpressionCompiler.cs | 43 +- .../ViewFeatures/DefaultEditorTemplates.cs | 16 +- .../ViewFeatures/DefaultHtmlGenerator.cs | 212 ++++++++-- .../ViewFeatures/DynamicViewData.cs | 23 +- .../ViewFeatures/ExpressionHelper.cs | 22 +- .../ExpressionMetadataProvider.cs | 30 +- .../ViewFeatures/FormContext.cs | 15 +- .../ViewFeatures/HtmlHelper.cs | 119 +++++- .../ViewFeatures/HtmlHelperOfT.cs | 191 +++++++-- .../ViewFeatures/IHtmlGenerator.cs | 41 +- .../ViewFeatures/ITempDataProvider.cs | 5 +- .../ViewFeatures/JsonHelper.cs | 18 +- .../ViewFeatures/ModelExpression.cs | 14 +- .../SessionStateTempDataProvider.cs | 14 +- .../StringCollectionTextWriter.cs | 15 +- .../ViewFeatures/StringHtmlContent.cs | 16 +- .../ViewFeatures/TempDataDictionary.cs | 13 +- .../ViewFeatures/TemplateBuilder.cs | 30 +- .../ViewFeatures/TemplateRenderer.cs | 22 +- .../ViewFeatures/TryGetValueProvider.cs | 7 +- ...nobtrusiveValidationAttributesGenerator.cs | 9 +- ...dateAntiforgeryTokenAuthorizationFilter.cs | 16 +- .../ViewFeatures/ViewDataDictionary.cs | 125 ++++-- .../ViewFeatures/ViewDataDictionaryOfT.cs | 32 +- .../ViewFeatures/ViewDataEvaluator.cs | 9 +- .../ViewFeatures/ViewExecutor.cs | 39 +- .../ViewResult.cs | 13 +- .../project.json | 13 +- .../RazorPageTest.cs | 10 +- .../RazorViewEngineTest.cs | 36 +- .../RazorViewTest.cs | 22 +- .../ControllerTest.cs | 2 + .../PartialViewResultTest.cs | 104 +++-- .../Rendering/DefaultTemplatesUtilities.cs | 4 +- .../Rendering/HtmlHelperSelectTest.cs | 5 +- .../Rendering/ViewContextTests.cs | 20 +- .../ViewComponentResultTest.cs | 25 +- .../ContentViewComponentResultTest.cs | 3 +- .../DefaultViewComponentSelectorTest.cs | 3 +- .../JsonViewComponentResultTest.cs | 2 +- .../ViewViewComponentResultTest.cs | 33 +- .../DefaultEditorTemplatesTest.cs | 29 +- .../ViewFeatures/DefaultHtmlGeneratorTest.cs | 5 +- .../ViewFeatures/SaveTempDataFilterTest.cs | 11 +- .../ViewFeatures/TempDataDictionaryTest.cs | 9 +- .../ViewFeatures/ViewExecutorTest.cs | 2 +- .../ViewResultTest.cs | 37 +- .../HomeController.cs | 6 +- .../Controllers/RoundtripController.cs | 3 +- 106 files changed, 3312 insertions(+), 909 deletions(-) diff --git a/samples/MvcSample.Web/project.json b/samples/MvcSample.Web/project.json index 83409b709e..53ac6ff07f 100644 --- a/samples/MvcSample.Web/project.json +++ b/samples/MvcSample.Web/project.json @@ -18,15 +18,7 @@ "Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.AspNet.Session": "1.0.0-*", "Microsoft.AspNet.StaticFiles": "1.0.0-*", - "Microsoft.Framework.Configuration.Json": "1.0.0-*", - "Microsoft.Framework.PropertyHelper.Sources": { - "version": "1.0.0-*", - "type": "build" - }, - "Microsoft.Framework.NotNullAttribute.Sources": { - "type": "build", - "version": "1.0.0-*" - } + "Microsoft.Framework.Configuration.Json": "1.0.0-*" }, "frameworks": { "dnx451": { }, diff --git a/samples/TagHelperSample.Web/project.json b/samples/TagHelperSample.Web/project.json index 8f856d1b6c..76b2437964 100644 --- a/samples/TagHelperSample.Web/project.json +++ b/samples/TagHelperSample.Web/project.json @@ -15,9 +15,7 @@ "Microsoft.AspNet.Server.IIS": "1.0.0-*", "Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.AspNet.StaticFiles": "1.0.0-*", - "Microsoft.AspNet.Tooling.Razor": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" }, - "Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" } + "Microsoft.AspNet.Tooling.Razor": "1.0.0-*" }, "frameworks": { "dnx451": { }, diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/AnchorTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/AnchorTagHelper.cs index cbbfb4eca3..1d75b25bd9 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/AnchorTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/AnchorTagHelper.cs @@ -147,14 +147,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers TagBuilder tagBuilder; if (Route == null) { - tagBuilder = Generator.GenerateActionLink(linkText: string.Empty, - actionName: Action, - controllerName: Controller, - protocol: Protocol, - hostname: Host, - fragment: Fragment, - routeValues: routeValues, - htmlAttributes: null); + tagBuilder = Generator.GenerateActionLink( + linkText: string.Empty, + actionName: Action, + controllerName: Controller, + protocol: Protocol, + hostname: Host, + fragment: Fragment, + routeValues: routeValues, + htmlAttributes: null); } else if (Action != null || Controller != null) { diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs index f2b9497f85..dc0510438f 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs @@ -104,8 +104,8 @@ namespace Microsoft.AspNet.Mvc /// /// /// activates this property while activating controllers. - /// If user code directly instantiates a controller, the getter returns an empty - /// . + /// If user code directly instantiates a controller, the getter returns an empty + /// . /// [ActionContext] public ActionContext ActionContext @@ -147,10 +147,13 @@ namespace Microsoft.AspNet.Mvc return _metadataProvider; } - - [param: NotNull] set { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + _metadataProvider = value; } } @@ -169,10 +172,13 @@ namespace Microsoft.AspNet.Mvc return _url; } - - [param: NotNull] set { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + _url = value; } } @@ -191,10 +197,13 @@ namespace Microsoft.AspNet.Mvc return _objectValidator; } - - [param: NotNull] set { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + _objectValidator = value; } } @@ -259,10 +268,13 @@ namespace Microsoft.AspNet.Mvc return _tempData; } - - [param: NotNull] set { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + _tempData = value; } } @@ -525,8 +537,13 @@ namespace Microsoft.AspNet.Mvc /// Callers should cache an instance of to avoid /// recreating cached data with each call. [NonAction] - public virtual JsonResult Json(object data, [NotNull] JsonSerializerSettings serializerSettings) + public virtual JsonResult Json(object data, JsonSerializerSettings serializerSettings) { + if (serializerSettings == null) + { + throw new ArgumentNullException(nameof(serializerSettings)); + } + var disposableValue = data as IDisposable; if (disposableValue != null) { @@ -981,8 +998,13 @@ namespace Microsoft.AspNet.Mvc /// /// The created for the response. [NonAction] - public virtual BadRequestObjectResult HttpBadRequest([NotNull] ModelStateDictionary modelState) + public virtual BadRequestObjectResult HttpBadRequest(ModelStateDictionary modelState) { + if (modelState == null) + { + throw new ArgumentNullException(nameof(modelState)); + } + return new BadRequestObjectResult(modelState); } @@ -993,8 +1015,13 @@ namespace Microsoft.AspNet.Mvc /// The content value to format in the entity body. /// The created for the response. [NonAction] - public virtual CreatedResult Created([NotNull] string uri, object value) + public virtual CreatedResult Created(string uri, object value) { + if (uri == null) + { + throw new ArgumentNullException(nameof(uri)); + } + var disposableValue = value as IDisposable; if (disposableValue != null) { @@ -1011,14 +1038,19 @@ namespace Microsoft.AspNet.Mvc /// The content value to format in the entity body. /// The created for the response. [NonAction] - public virtual CreatedResult Created([NotNull] Uri uri, object value) + public virtual CreatedResult Created(Uri uri, object value) { + if (uri == null) + { + throw new ArgumentNullException(nameof(uri)); + } + var disposableValue = value as IDisposable; if (disposableValue != null) { Response.RegisterForDispose(disposableValue); } - + return new CreatedResult(uri, value); } @@ -1119,8 +1151,12 @@ namespace Microsoft.AspNet.Mvc /// /// The action executing context. [NonAction] - public virtual void OnActionExecuting([NotNull] ActionExecutingContext context) + public virtual void OnActionExecuting(ActionExecutingContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } } /// @@ -1128,8 +1164,12 @@ namespace Microsoft.AspNet.Mvc /// /// The action executed context. [NonAction] - public virtual void OnActionExecuted([NotNull] ActionExecutedContext context) + public virtual void OnActionExecuted(ActionExecutedContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } } /// @@ -1141,9 +1181,19 @@ namespace Microsoft.AspNet.Mvc /// A instance. [NonAction] public virtual async Task OnActionExecutionAsync( - [NotNull] ActionExecutingContext context, - [NotNull] ActionExecutionDelegate next) + ActionExecutingContext context, + ActionExecutionDelegate next) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (next == null) + { + throw new ArgumentNullException(nameof(next)); + } + OnActionExecuting(context); if (context.Result == null) { @@ -1160,9 +1210,14 @@ namespace Microsoft.AspNet.Mvc /// A that on completion returns true if the update is successful. [NonAction] public virtual Task TryUpdateModelAsync( - [NotNull] TModel model) + TModel model) where TModel : class { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + return TryUpdateModelAsync(model, prefix: string.Empty); } @@ -1177,10 +1232,20 @@ namespace Microsoft.AspNet.Mvc /// A that on completion returns true if the update is successful. [NonAction] public virtual Task TryUpdateModelAsync( - [NotNull] TModel model, - [NotNull] string prefix) + TModel model, + string prefix) where TModel : class { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (prefix == null) + { + throw new ArgumentNullException(nameof(prefix)); + } + if (BindingContext == null) { var message = Resources.FormatPropertyOfTypeCannotBeNull( @@ -1204,11 +1269,26 @@ namespace Microsoft.AspNet.Mvc /// A that on completion returns true if the update is successful. [NonAction] public virtual Task TryUpdateModelAsync( - [NotNull] TModel model, - [NotNull] string prefix, - [NotNull] IValueProvider valueProvider) + TModel model, + string prefix, + IValueProvider valueProvider) where TModel : class { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (prefix == null) + { + throw new ArgumentNullException(nameof(prefix)); + } + + if (valueProvider == null) + { + throw new ArgumentNullException(nameof(valueProvider)); + } + if (BindingContext == null) { var message = Resources.FormatPropertyOfTypeCannotBeNull( @@ -1243,11 +1323,21 @@ namespace Microsoft.AspNet.Mvc /// A that on completion returns true if the update is successful. [NonAction] public Task TryUpdateModelAsync( - [NotNull] TModel model, + TModel model, string prefix, - [NotNull] params Expression>[] includeExpressions) + params Expression>[] includeExpressions) where TModel : class { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (includeExpressions == null) + { + throw new ArgumentNullException(nameof(includeExpressions)); + } + if (BindingContext == null) { var message = Resources.FormatPropertyOfTypeCannotBeNull( @@ -1282,11 +1372,21 @@ namespace Microsoft.AspNet.Mvc /// A that on completion returns true if the update is successful. [NonAction] public Task TryUpdateModelAsync( - [NotNull] TModel model, + TModel model, string prefix, - [NotNull] Func predicate) + Func predicate) where TModel : class { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (predicate == null) + { + throw new ArgumentNullException(nameof(predicate)); + } + if (BindingContext == null) { var message = Resources.FormatPropertyOfTypeCannotBeNull( @@ -1323,12 +1423,27 @@ namespace Microsoft.AspNet.Mvc /// A that on completion returns true if the update is successful. [NonAction] public Task TryUpdateModelAsync( - [NotNull] TModel model, + TModel model, string prefix, - [NotNull] IValueProvider valueProvider, - [NotNull] params Expression>[] includeExpressions) + IValueProvider valueProvider, + params Expression>[] includeExpressions) where TModel : class { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (valueProvider == null) + { + throw new ArgumentNullException(nameof(valueProvider)); + } + + if (includeExpressions == null) + { + throw new ArgumentNullException(nameof(includeExpressions)); + } + if (BindingContext == null) { var message = Resources.FormatPropertyOfTypeCannotBeNull( @@ -1364,12 +1479,27 @@ namespace Microsoft.AspNet.Mvc /// A that on completion returns true if the update is successful. [NonAction] public Task TryUpdateModelAsync( - [NotNull] TModel model, + TModel model, string prefix, - [NotNull] IValueProvider valueProvider, - [NotNull] Func predicate) + IValueProvider valueProvider, + Func predicate) where TModel : class { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (valueProvider == null) + { + throw new ArgumentNullException(nameof(valueProvider)); + } + + if (predicate == null) + { + throw new ArgumentNullException(nameof(predicate)); + } + if (BindingContext == null) { var message = Resources.FormatPropertyOfTypeCannotBeNull( @@ -1403,10 +1533,20 @@ namespace Microsoft.AspNet.Mvc /// A that on completion returns true if the update is successful. [NonAction] public virtual Task TryUpdateModelAsync( - [NotNull] object model, - [NotNull] Type modelType, + object model, + Type modelType, string prefix) { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (modelType == null) + { + throw new ArgumentNullException(nameof(modelType)); + } + if (BindingContext == null) { var message = Resources.FormatPropertyOfTypeCannotBeNull( @@ -1442,12 +1582,32 @@ namespace Microsoft.AspNet.Mvc /// A that on completion returns true if the update is successful. [NonAction] public Task TryUpdateModelAsync( - [NotNull] object model, - [NotNull] Type modelType, + object model, + Type modelType, string prefix, - [NotNull] IValueProvider valueProvider, - [NotNull] Func predicate) + IValueProvider valueProvider, + Func predicate) { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (modelType == null) + { + throw new ArgumentNullException(nameof(modelType)); + } + + if (valueProvider == null) + { + throw new ArgumentNullException(nameof(valueProvider)); + } + + if (predicate == null) + { + throw new ArgumentNullException(nameof(predicate)); + } + if (BindingContext == null) { var message = Resources.FormatPropertyOfTypeCannotBeNull( @@ -1478,8 +1638,13 @@ namespace Microsoft.AspNet.Mvc /// true if the is valid; false otherwise. [NonAction] public virtual bool TryValidateModel( - [NotNull] object model) + object model) { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + return TryValidateModel(model, prefix: null); } @@ -1492,9 +1657,14 @@ namespace Microsoft.AspNet.Mvc /// true if the is valid;false otherwise. [NonAction] public virtual bool TryValidateModel( - [NotNull] object model, + object model, string prefix) { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (BindingContext == null) { var message = Resources.FormatPropertyOfTypeCannotBeNull( diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/DependencyInjection/MvcViewFeaturesMvcBuilderExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/DependencyInjection/MvcViewFeaturesMvcBuilderExtensions.cs index b355a16318..919d98182d 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/DependencyInjection/MvcViewFeaturesMvcBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/DependencyInjection/MvcViewFeaturesMvcBuilderExtensions.cs @@ -1,9 +1,8 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNet.Mvc; -using Microsoft.Framework.Internal; namespace Microsoft.Framework.DependencyInjection { @@ -18,9 +17,19 @@ namespace Microsoft.Framework.DependencyInjection /// The . /// The which need to be configured. public static IMvcBuilder AddViewOptions( - [NotNull] this IMvcBuilder builder, - [NotNull] Action setupAction) + this IMvcBuilder builder, + Action setupAction) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (setupAction == null) + { + throw new ArgumentNullException(nameof(setupAction)); + } + builder.Services.Configure(setupAction); return builder; } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/DependencyInjection/MvcViewFeaturesMvcCoreBuilderExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/DependencyInjection/MvcViewFeaturesMvcCoreBuilderExtensions.cs index 11296ad8b1..1b1a63ee12 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/DependencyInjection/MvcViewFeaturesMvcCoreBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/DependencyInjection/MvcViewFeaturesMvcCoreBuilderExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -11,24 +11,38 @@ using Microsoft.AspNet.Mvc.ViewEngines; using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.AspNet.Mvc.ViewFeatures.Internal; using Microsoft.Framework.DependencyInjection.Extensions; -using Microsoft.Framework.Internal; using Microsoft.Framework.OptionsModel; namespace Microsoft.Framework.DependencyInjection { public static class MvcViewFeaturesMvcCoreBuilderExtensions { - public static IMvcCoreBuilder AddViews([NotNull] this IMvcCoreBuilder builder) + public static IMvcCoreBuilder AddViews(this IMvcCoreBuilder builder) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + builder.AddDataAnnotations(); AddViewServices(builder.Services); return builder; } public static IMvcCoreBuilder AddViews( - [NotNull] this IMvcCoreBuilder builder, - [NotNull] Action setupAction) + this IMvcCoreBuilder builder, + Action setupAction) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (setupAction == null) + { + throw new ArgumentNullException(nameof(setupAction)); + } + builder.AddDataAnnotations(); AddViewServices(builder.Services); @@ -41,9 +55,19 @@ namespace Microsoft.Framework.DependencyInjection } public static IMvcCoreBuilder ConfigureViews( - [NotNull] this IMvcCoreBuilder builder, - [NotNull] Action setupAction) + this IMvcCoreBuilder builder, + Action setupAction) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (setupAction == null) + { + throw new ArgumentNullException(nameof(setupAction)); + } + builder.Services.Configure(setupAction); return builder; } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/IViewComponentResult.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/IViewComponentResult.cs index 375343248f..d0e7b63326 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/IViewComponentResult.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/IViewComponentResult.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Mvc.ViewComponents; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -16,7 +15,7 @@ namespace Microsoft.AspNet.Mvc /// Executes the result of a using the specified . /// /// The for the current component execution. - void Execute([NotNull] ViewComponentContext context); + void Execute(ViewComponentContext context); /// /// Asynchronously executes the result of a using the specified @@ -24,6 +23,6 @@ namespace Microsoft.AspNet.Mvc /// /// The for the current component execution. /// A that represents the asynchronous execution. - Task ExecuteAsync([NotNull] ViewComponentContext context); + Task ExecuteAsync(ViewComponentContext context); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Internal/ICanHasViewContext.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Internal/ICanHasViewContext.cs index 1194f77248..4efec666fa 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Internal/ICanHasViewContext.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Internal/ICanHasViewContext.cs @@ -2,12 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ViewFeatures.Internal { public interface ICanHasViewContext { - void Contextualize([NotNull] ViewContext viewContext); + void Contextualize(ViewContext viewContext); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Internal/NullView.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Internal/NullView.cs index c1e17dffd4..5cf7dcfba1 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Internal/NullView.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Internal/NullView.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.ViewEngines; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ViewFeatures.Internal { @@ -14,8 +14,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures.Internal public string Path => string.Empty; - public Task RenderAsync([NotNull] ViewContext context) + public Task RenderAsync(ViewContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + return Task.FromResult(0); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Internal/ValidationHelpers.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Internal/ValidationHelpers.cs index 56dcfd4f37..34110c823c 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Internal/ValidationHelpers.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Internal/ValidationHelpers.cs @@ -5,8 +5,6 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Mvc.ModelBinding; -using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ViewFeatures.Internal { @@ -62,8 +60,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures.Internal { private Dictionary _ordering = new Dictionary(StringComparer.OrdinalIgnoreCase); - public ErrorsOrderer([NotNull] ModelMetadata metadata) + public ErrorsOrderer(ModelMetadata metadata) { + if (metadata == null) + { + throw new ArgumentNullException(nameof(metadata)); + } + foreach (var data in metadata.Properties) { _ordering[data.PropertyName] = data.Order; diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/MvcViewOptions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/MvcViewOptions.cs index 46aad3d935..5373bfa60a 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/MvcViewOptions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/MvcViewOptions.cs @@ -1,12 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using Microsoft.AspNet.Mvc.ModelBinding.Validation; -using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.ViewEngines; using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -15,10 +14,24 @@ namespace Microsoft.AspNet.Mvc /// public class MvcViewOptions { + private HtmlHelperOptions _htmlHelperOptions = new HtmlHelperOptions(); + /// - /// Gets or sets programmatic configuration for the HTML helpers and . + /// Gets or sets programmatic configuration for the HTML helpers and . /// - public HtmlHelperOptions HtmlHelperOptions { get;[param: NotNull] set; } = new HtmlHelperOptions(); + public HtmlHelperOptions HtmlHelperOptions + { + get { return _htmlHelperOptions; } + set + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + _htmlHelperOptions = value; + } + } /// /// Gets a list s used by this application. diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/PartialViewResult.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/PartialViewResult.cs index fe69b0070b..d5ba5890a0 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/PartialViewResult.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/PartialViewResult.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; using Microsoft.Net.Http.Headers; using Microsoft.Framework.OptionsModel; @@ -54,8 +53,13 @@ namespace Microsoft.AspNet.Mvc public MediaTypeHeaderValue ContentType { get; set; } /// - public override async Task ExecuteResultAsync([NotNull] ActionContext context) + public override async Task ExecuteResultAsync(ActionContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var viewEngine = ViewEngine ?? context.HttpContext.RequestServices.GetRequiredService(); diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/RemoteAttribute.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/RemoteAttribute.cs index c60045d121..07659d7a1e 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/RemoteAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/RemoteAttribute.cs @@ -11,7 +11,6 @@ using Microsoft.AspNet.Mvc.Internal; using Microsoft.AspNet.Mvc.ModelBinding.Validation; using Microsoft.AspNet.Routing; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; using Microsoft.AspNet.Mvc.Routing; namespace Microsoft.AspNet.Mvc @@ -192,8 +191,13 @@ namespace Microsoft.AspNet.Mvc /// /// The used to generate the URL. /// The URL where the client should send a validation request. - protected virtual string GetUrl([NotNull] ClientModelValidationContext context) + protected virtual string GetUrl(ClientModelValidationContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var urlHelper = context.RequestServices.GetRequiredService(); var url = urlHelper.RouteUrl(new UrlRouteContext() { @@ -230,8 +234,13 @@ namespace Microsoft.AspNet.Mvc /// Thrown if unable to generate a target URL for a validation request. /// public virtual IEnumerable GetClientValidationRules( - [NotNull] ClientModelValidationContext context) + ClientModelValidationContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var metadata = context.ModelMetadata; var rule = new ModelClientValidationRemoteRule( FormatErrorMessage(metadata.GetDisplayName()), diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperDisplayExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperDisplayExtensions.cs index a0ed3c7a14..f2c58b2d4a 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperDisplayExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperDisplayExtensions.cs @@ -4,7 +4,6 @@ using System; using System.Linq.Expressions; using Microsoft.AspNet.Html.Abstractions; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Rendering { @@ -37,8 +36,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// case-sensitive file systems. /// /// - public static IHtmlContent Display([NotNull] this IHtmlHelper htmlHelper, string expression) + public static IHtmlContent Display(this IHtmlHelper htmlHelper, string expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Display(expression, templateName: null, htmlFieldName: null, additionalViewData: null); } @@ -73,10 +77,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent Display( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, object additionalViewData) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Display( expression, templateName: null, @@ -111,10 +120,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent Display( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, string templateName) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Display(expression, templateName, htmlFieldName: null, additionalViewData: null); } @@ -150,11 +164,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent Display( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, string templateName, object additionalViewData) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Display( expression, templateName, @@ -193,11 +212,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent Display( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, string templateName, string htmlFieldName) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Display(expression, templateName, htmlFieldName, additionalViewData: null); } @@ -221,9 +245,19 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent DisplayFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression) + this IHtmlHelper htmlHelper, + Expression> expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.DisplayFor( expression, templateName: null, @@ -257,10 +291,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent DisplayFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, object additionalViewData) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.DisplayFor( expression, templateName: null, @@ -290,10 +334,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent DisplayFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, string templateName) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.DisplayFor( expression, templateName, @@ -328,11 +382,21 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent DisplayFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, string templateName, object additionalViewData) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.DisplayFor( expression, templateName, @@ -366,11 +430,21 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent DisplayFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, string templateName, string htmlFieldName) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.DisplayFor( expression, templateName: templateName, @@ -394,8 +468,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// case-sensitive file systems. /// /// - public static IHtmlContent DisplayForModel([NotNull] this IHtmlHelper htmlHelper) + public static IHtmlContent DisplayForModel(this IHtmlHelper htmlHelper) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Display( expression: null, templateName: null, @@ -424,8 +503,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// case-sensitive file systems. /// /// - public static IHtmlContent DisplayForModel([NotNull] this IHtmlHelper htmlHelper, object additionalViewData) + public static IHtmlContent DisplayForModel(this IHtmlHelper htmlHelper, object additionalViewData) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Display( expression: null, templateName: null, @@ -450,8 +534,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// case-sensitive file systems. /// /// - public static IHtmlContent DisplayForModel([NotNull] this IHtmlHelper htmlHelper, string templateName) + public static IHtmlContent DisplayForModel(this IHtmlHelper htmlHelper, string templateName) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Display( expression: null, templateName: templateName, @@ -483,10 +572,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent DisplayForModel( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string templateName, object additionalViewData) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Display( expression: null, templateName: templateName, @@ -517,10 +611,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent DisplayForModel( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string templateName, string htmlFieldName) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Display( expression: null, templateName: templateName, @@ -556,11 +655,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent DisplayForModel( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string templateName, string htmlFieldName, object additionalViewData) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Display( expression: null, templateName: templateName, diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperDisplayNameExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperDisplayNameExtensions.cs index ae3d46cf19..5f08cddffc 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperDisplayNameExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperDisplayNameExtensions.cs @@ -4,8 +4,6 @@ using System; using System.Collections.Generic; using System.Linq.Expressions; -using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Rendering { @@ -19,8 +17,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// The instance this method extends. /// A containing the display name. - public static string DisplayNameForModel([NotNull] this IHtmlHelper htmlHelper) + public static string DisplayNameForModel(this IHtmlHelper htmlHelper) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.DisplayName(expression: null); } @@ -36,9 +39,19 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The type of the result. /// A containing the display name. public static string DisplayNameFor( - [NotNull] this IHtmlHelper> htmlHelper, - [NotNull] Expression> expression) + this IHtmlHelper> htmlHelper, + Expression> expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.DisplayNameForInnerType(expression); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperEditorExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperEditorExtensions.cs index c07c5d182e..18525d4bdd 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperEditorExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperEditorExtensions.cs @@ -4,8 +4,6 @@ using System; using System.Linq.Expressions; using Microsoft.AspNet.Html.Abstractions; -using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Rendering { @@ -38,8 +36,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// case-sensitive file systems. /// /// - public static IHtmlContent Editor([NotNull] this IHtmlHelper htmlHelper, string expression) + public static IHtmlContent Editor(this IHtmlHelper htmlHelper, string expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Editor(expression, templateName: null, htmlFieldName: null, additionalViewData: null); } @@ -55,8 +58,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// /// An anonymous or - /// that can contain additional view data that will be merged into the - /// instance created for the template. + /// that can contain additional view data that will be merged into the + /// instance created for the template. /// /// A new containing the <input> element(s). /// @@ -74,10 +77,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent Editor( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, object additionalViewData) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Editor( expression, templateName: null, @@ -111,8 +119,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// case-sensitive file systems. /// /// - public static IHtmlContent Editor([NotNull] this IHtmlHelper htmlHelper, string expression, string templateName) + public static IHtmlContent Editor(this IHtmlHelper htmlHelper, string expression, string templateName) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Editor(expression, templateName, htmlFieldName: null, additionalViewData: null); } @@ -129,8 +142,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The name of the template used to create the HTML markup. /// /// An anonymous or - /// that can contain additional view data that will be merged into the - /// instance created for the template. + /// that can contain additional view data that will be merged into the + /// instance created for the template. /// /// A new containing the <input> element(s). /// @@ -148,11 +161,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent Editor( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, string templateName, object additionalViewData) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Editor( expression, templateName, @@ -191,11 +209,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent Editor( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, string templateName, string htmlFieldName) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Editor(expression, templateName, htmlFieldName, additionalViewData: null); } @@ -219,9 +242,19 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent EditorFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression) + this IHtmlHelper htmlHelper, + Expression> expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.EditorFor(expression, templateName: null, htmlFieldName: null, additionalViewData: null); } @@ -234,8 +267,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// An expression to be evaluated against the current model. /// /// An anonymous or - /// that can contain additional view data that will be merged into the - /// instance created for the template. + /// that can contain additional view data that will be merged into the + /// instance created for the template. /// /// The type of the model. /// The type of the result. @@ -251,10 +284,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent EditorFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, object additionalViewData) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.EditorFor( expression, templateName: null, @@ -284,10 +327,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent EditorFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, string templateName) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.EditorFor(expression, templateName, htmlFieldName: null, additionalViewData: null); } @@ -301,8 +354,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The name of the template that is used to create the HTML markup. /// /// An anonymous or - /// that can contain additional view data that will be merged into the - /// instance created for the template. + /// that can contain additional view data that will be merged into the + /// instance created for the template. /// /// The type of the model. /// The type of the result. @@ -318,11 +371,21 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent EditorFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, string templateName, object additionalViewData) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.EditorFor( expression, templateName, @@ -356,11 +419,21 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent EditorFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, string templateName, string htmlFieldName) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.EditorFor(expression, templateName, htmlFieldName, additionalViewData: null); } @@ -380,8 +453,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// case-sensitive file systems. /// /// - public static IHtmlContent EditorForModel([NotNull] this IHtmlHelper htmlHelper) + public static IHtmlContent EditorForModel(this IHtmlHelper htmlHelper) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Editor( expression: null, templateName: null, @@ -396,8 +474,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The instance this method extends. /// /// An anonymous or - /// that can contain additional view data that will be merged into the - /// instance created for the template. + /// that can contain additional view data that will be merged into the + /// instance created for the template. /// /// A new containing the <input> element(s). /// @@ -410,8 +488,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// case-sensitive file systems. /// /// - public static IHtmlContent EditorForModel([NotNull] this IHtmlHelper htmlHelper, object additionalViewData) + public static IHtmlContent EditorForModel(this IHtmlHelper htmlHelper, object additionalViewData) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Editor( expression: null, templateName: null, @@ -436,8 +519,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// case-sensitive file systems. /// /// - public static IHtmlContent EditorForModel([NotNull] this IHtmlHelper htmlHelper, string templateName) + public static IHtmlContent EditorForModel(this IHtmlHelper htmlHelper, string templateName) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Editor( expression: null, templateName: templateName, @@ -454,8 +542,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The name of the template used to create the HTML markup. /// /// An anonymous or - /// that can contain additional view data that will be merged into the - /// instance created for the template. + /// that can contain additional view data that will be merged into the + /// instance created for the template. /// /// A new containing the <input> element(s). /// @@ -469,10 +557,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent EditorForModel( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string templateName, object additionalViewData) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Editor( expression: null, templateName: templateName, @@ -503,10 +596,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent EditorForModel( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string templateName, string htmlFieldName) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Editor( expression: null, templateName: templateName, @@ -527,8 +625,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// /// An anonymous or - /// that can contain additional view data that will be merged into the - /// instance created for the template. + /// that can contain additional view data that will be merged into the + /// instance created for the template. /// /// A new containing the <input> element(s). /// @@ -542,11 +640,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent EditorForModel( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string templateName, string htmlFieldName, object additionalViewData) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Editor( expression: null, templateName: templateName, diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperFormExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperFormExtensions.cs index 67e63d3823..1376282a38 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperFormExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperFormExtensions.cs @@ -1,8 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; +using System; namespace Microsoft.AspNet.Mvc.Rendering { @@ -22,8 +21,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// In this context, "renders" means the method writes its output using . /// - public static MvcForm BeginForm([NotNull] this IHtmlHelper htmlHelper) + public static MvcForm BeginForm(this IHtmlHelper htmlHelper) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + // Generates
. return htmlHelper.BeginForm(actionName: null, controllerName: null, routeValues: null, method: FormMethod.Post, htmlAttributes: null); @@ -41,8 +45,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// In this context, "renders" means the method writes its output using . /// - public static MvcForm BeginForm([NotNull] this IHtmlHelper htmlHelper, FormMethod method) + public static MvcForm BeginForm(this IHtmlHelper htmlHelper, FormMethod method) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.BeginForm(actionName: null, controllerName: null, routeValues: null, method: method, htmlAttributes: null); } @@ -65,10 +74,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginForm( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, FormMethod method, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.BeginForm(actionName: null, controllerName: null, routeValues: null, method: method, htmlAttributes: htmlAttributes); } @@ -91,8 +105,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// In this context, "renders" means the method writes its output using . /// - public static MvcForm BeginForm([NotNull] this IHtmlHelper htmlHelper, object routeValues) + public static MvcForm BeginForm(this IHtmlHelper htmlHelper, object routeValues) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.BeginForm(actionName: null, controllerName: null, routeValues: routeValues, method: FormMethod.Post, htmlAttributes: null); } @@ -111,10 +130,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginForm( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string actionName, string controllerName) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.BeginForm(actionName, controllerName, routeValues: null, method: FormMethod.Post, htmlAttributes: null); } @@ -140,11 +164,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginForm( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string actionName, string controllerName, object routeValues) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.BeginForm(actionName, controllerName, routeValues, FormMethod.Post, htmlAttributes: null); } @@ -164,11 +193,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginForm( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.BeginForm(actionName, controllerName, routeValues: null, method: method, htmlAttributes: null); } @@ -195,12 +229,17 @@ namespace Microsoft.AspNet.Mvc.Rendering /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginForm( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string actionName, string controllerName, object routeValues, FormMethod method) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.BeginForm(actionName, controllerName, routeValues, method, htmlAttributes: null); } @@ -225,12 +264,17 @@ namespace Microsoft.AspNet.Mvc.Rendering /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginForm( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.BeginForm(actionName, controllerName, routeValues: null, method: method, htmlAttributes: htmlAttributes); } @@ -253,8 +297,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// In this context, "renders" means the method writes its output using . /// - public static MvcForm BeginRouteForm([NotNull] this IHtmlHelper htmlHelper, object routeValues) + public static MvcForm BeginRouteForm(this IHtmlHelper htmlHelper, object routeValues) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.BeginRouteForm( routeName: null, routeValues: routeValues, @@ -274,8 +323,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// In this context, "renders" means the method writes its output using . /// - public static MvcForm BeginRouteForm([NotNull] this IHtmlHelper htmlHelper, string routeName) + public static MvcForm BeginRouteForm(this IHtmlHelper htmlHelper, string routeName) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.BeginRouteForm( routeName, routeValues: null, @@ -303,10 +357,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginRouteForm( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string routeName, object routeValues) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.BeginRouteForm(routeName, routeValues, FormMethod.Post, htmlAttributes: null); } @@ -324,10 +383,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginRouteForm( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string routeName, FormMethod method) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.BeginRouteForm(routeName, routeValues: null, method: method, htmlAttributes: null); } @@ -352,11 +416,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginRouteForm( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string routeName, object routeValues, FormMethod method) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.BeginRouteForm(routeName, routeValues, method, htmlAttributes: null); } @@ -379,11 +448,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginRouteForm( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string routeName, FormMethod method, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.BeginRouteForm( routeName, routeValues: null, diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperInputExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperInputExtensions.cs index 003461e40f..961c4bb125 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperInputExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperInputExtensions.cs @@ -4,8 +4,6 @@ using System; using System.Linq.Expressions; using Microsoft.AspNet.Html.Abstractions; -using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Rendering { @@ -23,8 +21,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> elements. /// /// - /// Combines and to set checkbox - /// element's "name" attribute. Sanitizes to set checkbox element's "id" + /// Combines and to set + /// checkbox element's "name" attribute. Sanitizes to set checkbox element's "id" /// attribute. /// /// Determines checkbox element's "checked" attribute based on the following precedence: @@ -34,8 +32,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// fully-qualified name) if entry exists and can be converted to a . /// /// - /// entry for (converted to a fully-qualified - /// name) if entry exists and can be converted to a . + /// entry for (converted to a + /// fully-qualified name) if entry exists and can be converted to a . /// /// /// Linq expression based on (converted to a fully-qualified name) run against @@ -50,8 +48,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// value "checked" if the values is true; does not include the attribute otherwise. /// /// - public static IHtmlContent CheckBox([NotNull] this IHtmlHelper htmlHelper, string expression) + public static IHtmlContent CheckBox(this IHtmlHelper htmlHelper, string expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.CheckBox(expression, isChecked: null, htmlAttributes: null); } @@ -65,8 +68,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> elements. /// /// - /// Combines and to set checkbox - /// element's "name" attribute. Sanitizes to set checkbox element's "id" + /// Combines and to set + /// checkbox element's "name" attribute. Sanitizes to set checkbox element's "id" /// attribute. /// /// Determines checkbox element's "checked" attribute based on the following precedence: @@ -77,8 +80,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// if non-null. /// - /// entry for (converted to a fully-qualified - /// name) if entry exists and can be converted to a . + /// entry for (converted to a + /// fully-qualified name) if entry exists and can be converted to a . /// /// /// Linq expression based on (converted to a fully-qualified name) run against @@ -94,10 +97,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent CheckBox( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, bool isChecked) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.CheckBox(expression, isChecked, htmlAttributes: null); } @@ -115,8 +123,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> elements. /// /// - /// Combines and to set checkbox - /// element's "name" attribute. Sanitizes to set checkbox element's "id" + /// Combines and to set + /// checkbox element's "name" attribute. Sanitizes to set checkbox element's "id" /// attribute. /// /// Determines checkbox element's "checked" attribute based on the following precedence: @@ -126,8 +134,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// fully-qualified name) if entry exists and can be converted to a . /// /// - /// entry for (converted to a fully-qualified - /// name) if entry exists and can be converted to a . + /// entry for (converted to a + /// fully-qualified name) if entry exists and can be converted to a . /// /// /// Linq expression based on (converted to a fully-qualified name) run against @@ -144,10 +152,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent CheckBox( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.CheckBox(expression, isChecked: null, htmlAttributes: htmlAttributes); } @@ -160,7 +173,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> elements. /// /// - /// Combines and the string representation of the + /// Combines and the string representation of the /// to set checkbox element's "name" attribute. Sanitizes the string /// representation of the to set checkbox element's "id" attribute. /// @@ -182,9 +195,19 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent CheckBoxFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression) + this IHtmlHelper htmlHelper, + Expression> expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.CheckBoxFor(expression, htmlAttributes: null); } @@ -196,7 +219,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> element. /// /// - /// Combines and to set + /// Combines and to set /// <input> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// @@ -207,8 +230,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// fully-qualified name) if entry exists and can be converted to a . /// /// - /// entry for (converted to a fully-qualified - /// name) if entry exists and can be converted to a . + /// entry for (converted to a + /// fully-qualified name) if entry exists and can be converted to a . /// /// /// Linq expression based on (converted to a fully-qualified name) run against @@ -219,8 +242,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// Otherwise, string.Empty. /// /// - public static IHtmlContent Hidden([NotNull] this IHtmlHelper htmlHelper, string expression) + public static IHtmlContent Hidden(this IHtmlHelper htmlHelper, string expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Hidden(expression, value: null, htmlAttributes: null); } @@ -233,7 +261,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> element. /// /// - /// Combines and to set + /// Combines and to set /// <input> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// @@ -245,8 +273,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// if non-null. /// - /// entry for (converted to a fully-qualified - /// name) if entry exists and can be converted to a . + /// entry for (converted to a + /// fully-qualified name) if entry exists and can be converted to a . /// /// /// Linq expression based on (converted to a fully-qualified name) run against @@ -258,10 +286,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent Hidden( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, object value) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Hidden(expression, value, htmlAttributes: null); } @@ -275,7 +308,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> element. /// /// - /// Combines and the string representation of the + /// Combines and the string representation of the /// to set <input> element's "name" attribute. Sanitizes the string /// representation of the to set element's "id" attribute. /// @@ -293,9 +326,19 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent HiddenFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression) + this IHtmlHelper htmlHelper, + Expression> expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.HiddenFor(expression, htmlAttributes: null); } @@ -306,12 +349,17 @@ namespace Microsoft.AspNet.Mvc.Rendering /// Expression name, relative to the current model. /// A new containing the <input> element. /// - /// Combines and to set + /// Combines and to set /// <input> element's "name" attribute. Sanitizes to set element's "id" /// attribute. Sets <input> element's "value" attribute to string.Empty. /// - public static IHtmlContent Password([NotNull] this IHtmlHelper htmlHelper, string expression) + public static IHtmlContent Password(this IHtmlHelper htmlHelper, string expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Password(expression, value: null, htmlAttributes: null); } @@ -324,7 +372,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> element. /// /// - /// Combines and to set + /// Combines and to set /// <input> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// @@ -335,10 +383,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent Password( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, object value) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Password(expression, value, htmlAttributes: null); } @@ -352,7 +405,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> element. /// /// - /// Combines and the string representation of the + /// Combines and the string representation of the /// to set <input> element's "name" attribute. Sanitizes the string /// representation of the to set element's "id" attribute. /// @@ -366,9 +419,19 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent PasswordFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression) + this IHtmlHelper htmlHelper, + Expression> expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.PasswordFor(expression, htmlAttributes: null); } @@ -381,7 +444,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> element. /// /// - /// Combines and to set + /// Combines and to set /// <input> element's "name" attribute. Sanitizes to set element's "id" /// attribute. Sets <input> element's "value" attribute to . /// @@ -392,8 +455,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// fully-qualified name) if entry exists and can be converted to a . /// /// - /// entry for (converted to a fully-qualified - /// name) if entry exists and can be converted to a . + /// entry for (converted to a + /// fully-qualified name) if entry exists and can be converted to a . /// /// /// Linq expression based on (converted to a fully-qualified name) run against @@ -411,10 +474,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent RadioButton( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, object value) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.RadioButton(expression, value, isChecked: null, htmlAttributes: null); } @@ -435,7 +503,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> element. /// /// - /// Combines and to set + /// Combines and to set /// <input> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// @@ -453,8 +521,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// Existing "checked" entry in if any. /// - /// entry for (converted to a fully-qualified - /// name) if entry exists and can be converted to a . + /// entry for (converted to a + /// fully-qualified name) if entry exists and can be converted to a . /// /// /// Linq expression based on (converted to a fully-qualified name) run against @@ -472,11 +540,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent RadioButton( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, object value, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.RadioButton(expression, value, isChecked: null, htmlAttributes: htmlAttributes); } @@ -496,7 +569,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> element. /// /// - /// Combines and to set + /// Combines and to set /// <input> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// @@ -513,8 +586,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// if non-null. /// - /// entry for (converted to a fully-qualified - /// name) if entry exists and can be converted to a . + /// entry for (converted to a + /// fully-qualified name) if entry exists and can be converted to a . /// /// /// Linq expression based on (converted to a fully-qualified name) run against @@ -532,11 +605,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent RadioButton( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, object value, bool isChecked) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.RadioButton(expression, value, isChecked, htmlAttributes: null); } @@ -551,7 +629,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> element. /// /// - /// Combines and the string representation of the + /// Combines and the string representation of the /// to set <select> element's "name" attribute. Sanitizes the string /// representation of the to set element's "id" attribute. Converts the /// to a to set element's "value" attribute. @@ -574,10 +652,25 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent RadioButtonFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, - [NotNull] object value) + this IHtmlHelper htmlHelper, + Expression> expression, + object value) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + return htmlHelper.RadioButtonFor(expression, value, htmlAttributes: null); } @@ -589,7 +682,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> element. /// /// - /// Combines and to set + /// Combines and to set /// <input> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// @@ -600,8 +693,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// fully-qualified name) if entry exists and can be converted to a . /// /// - /// entry for (converted to a fully-qualified - /// name) if entry exists and can be converted to a . + /// entry for (converted to a + /// fully-qualified name) if entry exists and can be converted to a . /// /// /// Linq expression based on (converted to a fully-qualified name) run against @@ -612,8 +705,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// Otherwise, string.Empty. /// /// - public static IHtmlContent TextBox([NotNull] this IHtmlHelper htmlHelper, string expression) + public static IHtmlContent TextBox(this IHtmlHelper htmlHelper, string expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.TextBox(expression, value: null, format: null, htmlAttributes: null); } @@ -626,7 +724,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> element. /// /// - /// Combines and to set + /// Combines and to set /// <input> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// @@ -640,8 +738,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// if non-null. /// /// - /// entry for (converted to a fully-qualified - /// name) if entry exists and can be converted to a . + /// entry for (converted to a + /// fully-qualified name) if entry exists and can be converted to a . /// /// /// Linq expression based on (converted to a fully-qualified name) run against @@ -653,10 +751,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent TextBox( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, object value) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.TextBox(expression, value, format: null, htmlAttributes: null); } @@ -672,7 +775,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> element. /// /// - /// Combines and to set + /// Combines and to set /// <input> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// @@ -688,8 +791,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// is null or empty. /// /// - /// entry for (converted to a fully-qualified - /// name) if entry exists and can be converted to a . Formats entry using + /// entry for (converted to a + /// fully-qualified name) if entry exists and can be converted to a . Formats entry using /// or converts entry to a directly if /// is null or empty. /// @@ -704,11 +807,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent TextBox( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, object value, string format) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.TextBox(expression, value, format, htmlAttributes: null); } @@ -726,7 +834,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> element. /// /// - /// Combines and to set + /// Combines and to set /// <input> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// @@ -740,8 +848,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// if non-null. /// /// - /// entry for (converted to a fully-qualified - /// name) if entry exists and can be converted to a . + /// entry for (converted to a + /// fully-qualified name) if entry exists and can be converted to a . /// /// /// Linq expression based on (converted to a fully-qualified name) run against @@ -754,11 +862,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent TextBox( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, object value, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.TextBox(expression, value, format: null, htmlAttributes: htmlAttributes); } @@ -772,7 +885,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> element. /// /// - /// Combines and the string representation of the + /// Combines and the string representation of the /// to set <input> element's "name" attribute. Sanitizes the string /// representation of the to set element's "id" attribute. /// @@ -789,9 +902,19 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent TextBoxFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression) + this IHtmlHelper htmlHelper, + Expression> expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.TextBoxFor(expression, format: null, htmlAttributes: null); } @@ -808,7 +931,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> element. /// /// - /// Combines and the string representation of the + /// Combines and the string representation of the /// to set <input> element's "name" attribute. Sanitizes the string /// representation of the to set element's "id" attribute. /// @@ -827,10 +950,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent TextBoxFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, string format) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.TextBoxFor(expression, format, htmlAttributes: null); } @@ -849,7 +982,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <input> element. /// /// - /// Combines and the string representation of the + /// Combines and the string representation of the /// to set <input> element's "name" attribute. Sanitizes the string /// representation of the to set element's "id" attribute. /// @@ -867,10 +1000,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent TextBoxFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.TextBoxFor(expression, format: null, htmlAttributes: htmlAttributes); } @@ -882,7 +1025,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <textarea> element. /// /// - /// Combines and to set + /// Combines and to set /// <textarea> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// @@ -893,8 +1036,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// fully-qualified name) if entry exists and can be converted to a . /// /// - /// entry for (converted to a fully-qualified - /// name) if entry exists and can be converted to a . + /// entry for (converted to a + /// fully-qualified name) if entry exists and can be converted to a . /// /// /// Linq expression based on (converted to a fully-qualified name) run against @@ -906,9 +1049,14 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent TextArea( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.TextArea(expression, value: null, rows: 0, columns: 0, htmlAttributes: null); } @@ -925,7 +1073,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <textarea> element. /// /// - /// Combines and to set + /// Combines and to set /// <textarea> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// @@ -936,8 +1084,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// fully-qualified name) if entry exists and can be converted to a . /// /// - /// entry for (converted to a fully-qualified - /// name) if entry exists and can be converted to a . + /// entry for (converted to a + /// fully-qualified name) if entry exists and can be converted to a . /// /// /// Linq expression based on (converted to a fully-qualified name) run against @@ -949,10 +1097,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent TextArea( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.TextArea(expression, value: null, rows: 0, columns: 0, htmlAttributes: htmlAttributes); } @@ -965,7 +1118,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <textarea> element. /// /// - /// Combines and to set + /// Combines and to set /// <textarea> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// @@ -977,8 +1130,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// if non-null. /// - /// entry for (converted to a fully-qualified - /// name) if entry exists and can be converted to a . + /// entry for (converted to a + /// fully-qualified name) if entry exists and can be converted to a . /// /// /// Linq expression based on (converted to a fully-qualified name) run against @@ -990,10 +1143,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent TextArea( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, string value) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.TextArea(expression, value, rows: 0, columns: 0, htmlAttributes: null); } @@ -1011,7 +1169,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <textarea> element. /// /// - /// Combines and to set + /// Combines and to set /// <textarea> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// @@ -1023,8 +1181,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// if non-null. /// - /// entry for (converted to a fully-qualified - /// name) if entry exists and can be converted to a . + /// entry for (converted to a + /// fully-qualified name) if entry exists and can be converted to a . /// /// /// Linq expression based on (converted to a fully-qualified name) run against @@ -1036,11 +1194,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent TextArea( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, string value, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.TextArea(expression, value, rows: 0, columns: 0, htmlAttributes: htmlAttributes); } @@ -1054,7 +1217,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <textarea> element. /// /// - /// Combines and the string representation of the + /// Combines and the string representation of the /// to set <textarea> element's "name" attribute. Sanitizes the string /// representation of the to set element's "id" attribute. /// @@ -1071,9 +1234,19 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent TextAreaFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression) + this IHtmlHelper htmlHelper, + Expression> expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.TextAreaFor(expression, rows: 0, columns: 0, htmlAttributes: null); } @@ -1092,7 +1265,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A new containing the <textarea> element. /// /// - /// Combines and the string representation of the + /// Combines and the string representation of the /// to set <textarea> element's "name" attribute. Sanitizes the string /// representation of the to set element's "id" attribute. /// @@ -1109,10 +1282,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent TextAreaFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.TextAreaFor(expression, rows: 0, columns: 0, htmlAttributes: htmlAttributes); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperLabelExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperLabelExtensions.cs index 73ea26d187..f65b0aefa6 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperLabelExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperLabelExtensions.cs @@ -4,8 +4,6 @@ using System; using System.Linq.Expressions; using Microsoft.AspNet.Html.Abstractions; -using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Rendering { @@ -20,8 +18,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The instance this method extends. /// Expression name, relative to the current model. /// A new containing the <label> element. - public static IHtmlContent Label([NotNull] this IHtmlHelper htmlHelper, string expression) + public static IHtmlContent Label(this IHtmlHelper htmlHelper, string expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Label(expression, labelText: null, htmlAttributes: null); } @@ -32,8 +35,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// Expression name, relative to the current model. /// The inner text of the element. /// A new containing the <label> element. - public static IHtmlContent Label([NotNull] this IHtmlHelper htmlHelper, string expression, string labelText) + public static IHtmlContent Label(this IHtmlHelper htmlHelper, string expression, string labelText) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Label(expression, labelText, htmlAttributes: null); } @@ -46,9 +54,19 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The type of the result. /// A new containing the <label> element. public static IHtmlContent LabelFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression) + this IHtmlHelper htmlHelper, + Expression> expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.LabelFor(expression, labelText: null, htmlAttributes: null); } @@ -62,10 +80,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The type of the result. /// A new containing the <label> element. public static IHtmlContent LabelFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, string labelText) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.LabelFor(expression, labelText, htmlAttributes: null); } @@ -83,10 +111,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The type of the result. /// A new containing the <label> element. public static IHtmlContent LabelFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.LabelFor(expression, labelText: null, htmlAttributes: htmlAttributes); } @@ -95,8 +133,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// The instance this method extends. /// A new containing the <label> element. - public static IHtmlContent LabelForModel([NotNull] this IHtmlHelper htmlHelper) + public static IHtmlContent LabelForModel(this IHtmlHelper htmlHelper) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Label(expression: null, labelText: null, htmlAttributes: null); } @@ -106,8 +149,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The instance this method extends. /// The inner text of the element. /// A new containing the <label> element. - public static IHtmlContent LabelForModel([NotNull] this IHtmlHelper htmlHelper, string labelText) + public static IHtmlContent LabelForModel(this IHtmlHelper htmlHelper, string labelText) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Label(expression: null, labelText: labelText, htmlAttributes: null); } @@ -121,8 +169,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// attributes. /// /// A new containing the <label> element. - public static IHtmlContent LabelForModel([NotNull] this IHtmlHelper htmlHelper, object htmlAttributes) + public static IHtmlContent LabelForModel(this IHtmlHelper htmlHelper, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Label(expression: null, labelText: null, htmlAttributes: htmlAttributes); } @@ -138,10 +191,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// A new containing the <label> element. public static IHtmlContent LabelForModel( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string labelText, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Label(expression: null, labelText: labelText, htmlAttributes: htmlAttributes); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperLinkExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperLinkExtensions.cs index 7e4187a407..134dd78fd2 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperLinkExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperLinkExtensions.cs @@ -1,9 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNet.Html.Abstractions; -using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Rendering { @@ -20,10 +19,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The name of the action. /// A new containing the anchor element. public static IHtmlContent ActionLink( - [NotNull] this IHtmlHelper helper, - [NotNull] string linkText, + this IHtmlHelper helper, + string linkText, string actionName) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + + if (linkText == null) + { + throw new ArgumentNullException(nameof(linkText)); + } + return helper.ActionLink( linkText, actionName, @@ -50,11 +59,21 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// A new containing the anchor element. public static IHtmlContent ActionLink( - [NotNull] this IHtmlHelper helper, - [NotNull] string linkText, + this IHtmlHelper helper, + string linkText, string actionName, object routeValues) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + + if (linkText == null) + { + throw new ArgumentNullException(nameof(linkText)); + } + return helper.ActionLink( linkText, actionName, @@ -86,12 +105,22 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// A new containing the anchor element. public static IHtmlContent ActionLink( - [NotNull] this IHtmlHelper helper, - [NotNull] string linkText, + this IHtmlHelper helper, + string linkText, string actionName, object routeValues, object htmlAttributes) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + + if (linkText == null) + { + throw new ArgumentNullException(nameof(linkText)); + } + return helper.ActionLink( linkText, actionName, @@ -112,11 +141,21 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The name of the controller. /// A new containing the anchor element. public static IHtmlContent ActionLink( - [NotNull] this IHtmlHelper helper, - [NotNull] string linkText, + this IHtmlHelper helper, + string linkText, string actionName, string controllerName) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + + if (linkText == null) + { + throw new ArgumentNullException(nameof(linkText)); + } + return helper.ActionLink( linkText, actionName, @@ -144,12 +183,22 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// A new containing the anchor element. public static IHtmlContent ActionLink( - [NotNull] this IHtmlHelper helper, - [NotNull] string linkText, + this IHtmlHelper helper, + string linkText, string actionName, string controllerName, object routeValues) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + + if (linkText == null) + { + throw new ArgumentNullException(nameof(linkText)); + } + return helper.ActionLink( linkText, actionName, @@ -182,13 +231,23 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// A new containing the anchor element. public static IHtmlContent ActionLink( - [NotNull] this IHtmlHelper helper, - [NotNull] string linkText, + this IHtmlHelper helper, + string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + + if (linkText == null) + { + throw new ArgumentNullException(nameof(linkText)); + } + return helper.ActionLink( linkText, actionName, @@ -214,10 +273,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// A new containing the anchor element. public static IHtmlContent RouteLink( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] string linkText, + this IHtmlHelper htmlHelper, + string linkText, object routeValues) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (linkText == null) + { + throw new ArgumentNullException(nameof(linkText)); + } + return htmlHelper.RouteLink( linkText, routeName: null, @@ -236,10 +305,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The name of the route. /// A new containing the anchor element. public static IHtmlContent RouteLink( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] string linkText, + this IHtmlHelper htmlHelper, + string linkText, string routeName) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (linkText == null) + { + throw new ArgumentNullException(nameof(linkText)); + } + return htmlHelper.RouteLink( linkText, routeName, @@ -265,11 +344,21 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// A new containing the anchor element. public static IHtmlContent RouteLink( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] string linkText, + this IHtmlHelper htmlHelper, + string linkText, string routeName, object routeValues) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (linkText == null) + { + throw new ArgumentNullException(nameof(linkText)); + } + return htmlHelper.RouteLink( linkText, routeName, @@ -299,11 +388,21 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// A new containing the anchor element. public static IHtmlContent RouteLink( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] string linkText, + this IHtmlHelper htmlHelper, + string linkText, object routeValues, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (linkText == null) + { + throw new ArgumentNullException(nameof(linkText)); + } + return htmlHelper.RouteLink( linkText, routeName: null, @@ -334,12 +433,22 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// A new containing the anchor element. public static IHtmlContent RouteLink( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] string linkText, + this IHtmlHelper htmlHelper, + string linkText, string routeName, object routeValues, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (linkText == null) + { + throw new ArgumentNullException(nameof(linkText)); + } + return htmlHelper.RouteLink( linkText, routeName, diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperNameExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperNameExtensions.cs index 072f41ad41..66de67c598 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperNameExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperNameExtensions.cs @@ -1,8 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; +using System; namespace Microsoft.AspNet.Mvc.Rendering { @@ -16,8 +15,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// The instance this method extends. /// A containing the element name. - public static string NameForModel([NotNull] this IHtmlHelper htmlHelper) + public static string NameForModel(this IHtmlHelper htmlHelper) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Name(expression: null); } @@ -26,8 +30,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// The instance this method extends. /// A containing the element Id. - public static string IdForModel([NotNull] this IHtmlHelper htmlHelper) + public static string IdForModel(this IHtmlHelper htmlHelper) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Id(expression: null); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperPartialExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperPartialExtensions.cs index bf0dd3ada9..a53893bd34 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperPartialExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperPartialExtensions.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Threading.Tasks; using Microsoft.AspNet.Html.Abstractions; using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Rendering { @@ -25,9 +25,19 @@ namespace Microsoft.AspNet.Mvc.Rendering /// the created HTML. /// public static Task PartialAsync( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] string partialViewName) + this IHtmlHelper htmlHelper, + string partialViewName) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (partialViewName == null) + { + throw new ArgumentNullException(nameof(partialViewName)); + } + return htmlHelper.PartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: null); } @@ -44,10 +54,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// the created HTML. /// public static Task PartialAsync( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] string partialViewName, + this IHtmlHelper htmlHelper, + string partialViewName, ViewDataDictionary viewData) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (partialViewName == null) + { + throw new ArgumentNullException(nameof(partialViewName)); + } + return htmlHelper.PartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: viewData); } @@ -64,10 +84,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// the created HTML. /// public static Task PartialAsync( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] string partialViewName, + this IHtmlHelper htmlHelper, + string partialViewName, object model) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (partialViewName == null) + { + throw new ArgumentNullException(nameof(partialViewName)); + } + return htmlHelper.PartialAsync(partialViewName, model, viewData: null); } @@ -86,9 +116,19 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent Partial( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] string partialViewName) + this IHtmlHelper htmlHelper, + string partialViewName) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (partialViewName == null) + { + throw new ArgumentNullException(nameof(partialViewName)); + } + return Partial(htmlHelper, partialViewName, htmlHelper.ViewData.Model, viewData: null); } @@ -108,10 +148,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent Partial( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] string partialViewName, + this IHtmlHelper htmlHelper, + string partialViewName, ViewDataDictionary viewData) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (partialViewName == null) + { + throw new ArgumentNullException(nameof(partialViewName)); + } + return Partial(htmlHelper, partialViewName, htmlHelper.ViewData.Model, viewData); } @@ -131,10 +181,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent Partial( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] string partialViewName, + this IHtmlHelper htmlHelper, + string partialViewName, object model) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (partialViewName == null) + { + throw new ArgumentNullException(nameof(partialViewName)); + } + return Partial(htmlHelper, partialViewName, model, viewData: null); } @@ -155,11 +215,21 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// public static IHtmlContent Partial( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] string partialViewName, + this IHtmlHelper htmlHelper, + string partialViewName, object model, ViewDataDictionary viewData) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (partialViewName == null) + { + throw new ArgumentNullException(nameof(partialViewName)); + } + var result = htmlHelper.PartialAsync(partialViewName, model, viewData); return result.GetAwaiter().GetResult(); } @@ -176,9 +246,19 @@ namespace Microsoft.AspNet.Mvc.Rendering /// In this context, "renders" means the method writes its output using . /// public static Task RenderPartialAsync( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] string partialViewName) + this IHtmlHelper htmlHelper, + string partialViewName) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (partialViewName == null) + { + throw new ArgumentNullException(nameof(partialViewName)); + } + return htmlHelper.RenderPartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: htmlHelper.ViewData); } @@ -196,10 +276,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// In this context, "renders" means the method writes its output using . /// public static Task RenderPartialAsync( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] string partialViewName, + this IHtmlHelper htmlHelper, + string partialViewName, ViewDataDictionary viewData) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (partialViewName == null) + { + throw new ArgumentNullException(nameof(partialViewName)); + } + return htmlHelper.RenderPartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: viewData); } @@ -216,10 +306,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// In this context, "renders" means the method writes its output using . /// public static Task RenderPartialAsync( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] string partialViewName, + this IHtmlHelper htmlHelper, + string partialViewName, object model) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (partialViewName == null) + { + throw new ArgumentNullException(nameof(partialViewName)); + } + return htmlHelper.RenderPartialAsync(partialViewName, model, htmlHelper.ViewData); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperSelectExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperSelectExtensions.cs index 45603e6479..0d82f6e396 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperSelectExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperSelectExtensions.cs @@ -5,8 +5,6 @@ using System; using System.Collections.Generic; using System.Linq.Expressions; using Microsoft.AspNet.Html.Abstractions; -using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Rendering { @@ -22,12 +20,17 @@ namespace Microsoft.AspNet.Mvc.Rendering /// Expression name, relative to the current model. /// A new containing the <select> element. /// - /// Combines and to set + /// Combines and to set /// <select> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// - public static IHtmlContent DropDownList([NotNull] this IHtmlHelper htmlHelper, string expression) + public static IHtmlContent DropDownList(this IHtmlHelper htmlHelper, string expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.DropDownList(expression, selectList: null, optionLabel: null, htmlAttributes: null); } @@ -42,15 +45,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// A new containing the <select> element. /// - /// Combines and to set + /// Combines and to set /// <select> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// public static IHtmlContent DropDownList( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, string optionLabel) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.DropDownList( expression, selectList: null, @@ -70,15 +78,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// A new containing the <select> element. /// - /// Combines and to set + /// Combines and to set /// <select> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// public static IHtmlContent DropDownList( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, IEnumerable selectList) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.DropDownList(expression, selectList, optionLabel: null, htmlAttributes: null); } @@ -98,16 +111,21 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// A new containing the <select> element. /// - /// Combines and to set + /// Combines and to set /// <select> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// public static IHtmlContent DropDownList( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, IEnumerable selectList, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.DropDownList(expression, selectList, optionLabel: null, htmlAttributes: htmlAttributes); } @@ -126,16 +144,21 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// A new containing the <select> element. /// - /// Combines and to set + /// Combines and to set /// <select> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// public static IHtmlContent DropDownList( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, IEnumerable selectList, string optionLabel) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.DropDownList(expression, selectList, optionLabel, htmlAttributes: null); } @@ -153,15 +176,25 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The type of the result. /// A new containing the <select> element. /// - /// Combines and the string representation of the + /// Combines and the string representation of the /// to set <select> element's "name" attribute. Sanitizes the string /// representation of the to set element's "id" attribute. /// public static IHtmlContent DropDownListFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, IEnumerable selectList) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.DropDownListFor(expression, selectList, optionLabel: null, htmlAttributes: null); } @@ -183,16 +216,26 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The type of the result. /// A new containing the <select> element. /// - /// Combines and the string representation of the + /// Combines and the string representation of the /// to set <select> element's "name" attribute. Sanitizes the string /// representation of the to set element's "id" attribute. /// public static IHtmlContent DropDownListFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, IEnumerable selectList, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.DropDownListFor( expression, selectList, @@ -217,16 +260,26 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The type of the result. /// A new containing the <select> element. /// - /// Combines and the string representation of the + /// Combines and the string representation of the /// to set <select> element's "name" attribute. Sanitizes the string /// representation of the to set element's "id" attribute. /// public static IHtmlContent DropDownListFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, IEnumerable selectList, string optionLabel) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.DropDownListFor(expression, selectList, optionLabel, htmlAttributes: null); } @@ -237,12 +290,17 @@ namespace Microsoft.AspNet.Mvc.Rendering /// Expression name, relative to the current model. /// A new containing the <select> element. /// - /// Combines and to set + /// Combines and to set /// <select> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// - public static IHtmlContent ListBox([NotNull] this IHtmlHelper htmlHelper, string expression) + public static IHtmlContent ListBox(this IHtmlHelper htmlHelper, string expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.ListBox(expression, selectList: null, htmlAttributes: null); } @@ -258,15 +316,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// A new containing the <select> element. /// - /// Combines and to set + /// Combines and to set /// <select> element's "name" attribute. Sanitizes to set element's "id" /// attribute. /// public static IHtmlContent ListBox( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, IEnumerable selectList) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.ListBox(expression, selectList, htmlAttributes: null); } @@ -284,15 +347,25 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The type of the result. /// A new containing the <select> element. /// - /// Combines and the string representation of the + /// Combines and the string representation of the /// to set <select> element's "name" attribute. Sanitizes the string /// representation of the to set element's "id" attribute. /// public static IHtmlContent ListBoxFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, IEnumerable selectList) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.ListBoxFor(expression, selectList, htmlAttributes: null); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperValidationExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperValidationExtensions.cs index ac87d1237a..4d07e973f2 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperValidationExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperValidationExtensions.cs @@ -4,8 +4,6 @@ using System; using System.Linq.Expressions; using Microsoft.AspNet.Html.Abstractions; -using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Rendering { @@ -29,9 +27,14 @@ namespace Microsoft.AspNet.Mvc.Rendering /// will always be visible but client-side validation may update the associated CSS class. /// public static IHtmlContent ValidationMessage( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.ValidationMessage(expression, message: null, htmlAttributes: null, tag: null); } @@ -51,10 +54,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// null if the is valid and client-side validation is disabled. /// public static IHtmlContent ValidationMessage( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, string message) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.ValidationMessage(expression, message, htmlAttributes: null, tag: null); } @@ -79,10 +87,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// will always be visible but client-side validation may update the associated CSS class. /// public static IHtmlContent ValidationMessage( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.ValidationMessage(expression, message: null, htmlAttributes: htmlAttributes, tag: null); } @@ -106,11 +119,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// is valid and client-side validation is disabled. /// public static IHtmlContent ValidationMessage( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, string message, string tag) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.ValidationMessage(expression, message, htmlAttributes: null, tag: tag); } @@ -136,11 +154,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// null if the is valid and client-side validation is disabled. /// public static IHtmlContent ValidationMessage( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string expression, string message, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.ValidationMessage(expression, message, htmlAttributes, tag: null); } @@ -161,9 +184,19 @@ namespace Microsoft.AspNet.Mvc.Rendering /// will always be visible but client-side validation may update the associated CSS class. /// public static IHtmlContent ValidationMessageFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression) + this IHtmlHelper htmlHelper, + Expression> expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.ValidationMessageFor(expression, message: null, htmlAttributes: null, tag: null); } @@ -185,10 +218,20 @@ namespace Microsoft.AspNet.Mvc.Rendering /// null if the is valid and client-side validation is disabled. /// public static IHtmlContent ValidationMessageFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, string message) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.ValidationMessageFor(expression, message, htmlAttributes: null, tag: null); } @@ -216,11 +259,21 @@ namespace Microsoft.AspNet.Mvc.Rendering /// null if the is valid and client-side validation is disabled. /// public static IHtmlContent ValidationMessageFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, string message, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.ValidationMessageFor(expression, message, htmlAttributes, tag: null); } @@ -246,11 +299,21 @@ namespace Microsoft.AspNet.Mvc.Rendering /// is valid and client-side validation is disabled. /// public static IHtmlContent ValidationMessageFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression, + this IHtmlHelper htmlHelper, + Expression> expression, string message, string tag) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.ValidationMessageFor(expression, message, htmlAttributes: null, tag: tag); } @@ -263,8 +326,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// New containing a <div> element wrapping the <ul> element. /// if the current model is valid and client-side validation is disabled). /// - public static IHtmlContent ValidationSummary([NotNull] this IHtmlHelper htmlHelper) + public static IHtmlContent ValidationSummary(this IHtmlHelper htmlHelper) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.ValidationSummary( excludePropertyErrors: false, message: null, @@ -284,8 +352,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// New containing a <div> element wrapping the <ul> element. /// if the current model is valid and client-side validation is disabled). /// - public static IHtmlContent ValidationSummary([NotNull] this IHtmlHelper htmlHelper, bool excludePropertyErrors) + public static IHtmlContent ValidationSummary(this IHtmlHelper htmlHelper, bool excludePropertyErrors) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.ValidationSummary( excludePropertyErrors, message: null, @@ -305,8 +378,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// ) and the <ul> element. if the current model /// is valid and client-side validation is disabled). /// - public static IHtmlContent ValidationSummary([NotNull] this IHtmlHelper htmlHelper, string message) + public static IHtmlContent ValidationSummary(this IHtmlHelper htmlHelper, string message) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.ValidationSummary( excludePropertyErrors: false, message: message, @@ -329,8 +407,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// and the <ul> element. if the current model is valid and client-side /// validation is disabled). /// - public static IHtmlContent ValidationSummary([NotNull] this IHtmlHelper htmlHelper, string message, string tag) + public static IHtmlContent ValidationSummary(this IHtmlHelper htmlHelper, string message, string tag) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.ValidationSummary( excludePropertyErrors: false, message: message, @@ -354,10 +437,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// is valid and client-side validation is disabled). /// public static IHtmlContent ValidationSummary( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, bool excludePropertyErrors, string message) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.ValidationSummary( excludePropertyErrors, message, @@ -383,10 +471,15 @@ namespace Microsoft.AspNet.Mvc.Rendering /// is valid and client-side validation is disabled). /// public static IHtmlContent ValidationSummary( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string message, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.ValidationSummary( excludePropertyErrors: false, message: message, @@ -415,11 +508,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// validation is disabled). /// public static IHtmlContent ValidationSummary( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, string message, object htmlAttributes, string tag) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.ValidationSummary( excludePropertyErrors: false, message: message, @@ -446,11 +544,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// validation is disabled). /// public static IHtmlContent ValidationSummary( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, bool excludePropertyErrors, string message, string tag) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.ValidationSummary( excludePropertyErrors, message, @@ -479,11 +582,16 @@ namespace Microsoft.AspNet.Mvc.Rendering /// is valid and client-side validation is disabled). /// public static IHtmlContent ValidationSummary( - [NotNull] this IHtmlHelper htmlHelper, + this IHtmlHelper htmlHelper, bool excludePropertyErrors, string message, object htmlAttributes) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.ValidationSummary(excludePropertyErrors, message, htmlAttributes, tag: null); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperValueExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperValueExtensions.cs index 78446a32a5..4f35197df7 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperValueExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperValueExtensions.cs @@ -3,8 +3,6 @@ using System; using System.Linq.Expressions; -using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Rendering { @@ -22,8 +20,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// Converts the expression result to a directly. /// - public static string Value([NotNull] this IHtmlHelper htmlHelper, string expression) + public static string Value(this IHtmlHelper htmlHelper, string expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Value(expression, format: null); } @@ -39,9 +42,19 @@ namespace Microsoft.AspNet.Mvc.Rendering /// Converts the result to a directly. /// public static string ValueFor( - [NotNull] this IHtmlHelper htmlHelper, - [NotNull] Expression> expression) + this IHtmlHelper htmlHelper, + Expression> expression) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return htmlHelper.ValueFor(expression, format: null); } @@ -53,8 +66,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// Converts the model value to a directly. /// - public static string ValueForModel([NotNull] this IHtmlHelper htmlHelper) + public static string ValueForModel(this IHtmlHelper htmlHelper) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Value(expression: null, format: null); } @@ -70,8 +88,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// Converts the model value to a directly if /// is null or empty. /// - public static string ValueForModel([NotNull] this IHtmlHelper htmlHelper, string format) + public static string ValueForModel(this IHtmlHelper htmlHelper, string format) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return htmlHelper.Value(expression: null, format: format); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlString.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlString.cs index dfe2267d84..687d697fbb 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlString.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlString.cs @@ -4,7 +4,6 @@ using System; using System.IO; using Microsoft.AspNet.Html.Abstractions; -using Microsoft.Framework.Internal; using Microsoft.Framework.WebEncoders; namespace Microsoft.AspNet.Mvc.Rendering @@ -36,8 +35,18 @@ namespace Microsoft.AspNet.Mvc.Rendering } /// - public void WriteTo([NotNull] TextWriter writer, [NotNull] IHtmlEncoder encoder) + public void WriteTo(TextWriter writer, IHtmlEncoder encoder) { + if (writer == null) + { + throw new ArgumentNullException(nameof(writer)); + } + + if (encoder == null) + { + throw new ArgumentNullException(nameof(encoder)); + } + writer.Write(_input); } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IHtmlHelper.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IHtmlHelper.cs index 603606f806..804d3a1679 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IHtmlHelper.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IHtmlHelper.cs @@ -8,7 +8,6 @@ using Microsoft.AspNet.Html.Abstractions; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding.Validation; using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; using Microsoft.Framework.WebEncoders; namespace Microsoft.AspNet.Mvc.Rendering @@ -86,7 +85,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// A new containing the anchor element. IHtmlContent ActionLink( - [NotNull] string linkText, + string linkText, string actionName, string controllerName, string protocol, @@ -360,7 +359,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// Fully-qualified expression name, ignoring the current model. Must not be null. /// /// A containing the element Id. - string GenerateIdFromName([NotNull] string fullName); + string GenerateIdFromName(string fullName); /// /// Returns information about about client validation rules for the specified or @@ -402,7 +401,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// Thrown if is not an or if it has a /// . /// - IEnumerable GetEnumSelectList([NotNull] Type enumType); + IEnumerable GetEnumSelectList(Type enumType); /// /// Returns an <input> element of type "hidden" for the specified . @@ -502,7 +501,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// A that on completion returns a new containing /// the created HTML. /// - Task PartialAsync([NotNull] string partialViewName, object model, ViewDataDictionary viewData); + Task PartialAsync(string partialViewName, object model, ViewDataDictionary viewData); /// /// Returns an <input> element of type "password" for the specified . @@ -617,7 +616,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// In this context, "renders" means the method writes its output using . /// - Task RenderPartialAsync([NotNull] string partialViewName, object model, ViewDataDictionary viewData); + Task RenderPartialAsync(string partialViewName, object model, ViewDataDictionary viewData); /// /// Returns an anchor (<a>) element that contains a URL path to the specified route. @@ -639,7 +638,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// A new containing the anchor element. IHtmlContent RouteLink( - [NotNull] string linkText, + string linkText, string routeName, string protocol, string hostName, diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IHtmlHelperOfT.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IHtmlHelperOfT.cs index 6ced83b465..90f0356ec3 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IHtmlHelperOfT.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IHtmlHelperOfT.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Linq.Expressions; using Microsoft.AspNet.Html.Abstractions; using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Rendering { @@ -55,7 +54,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// if the values is true; does not include the attribute otherwise. /// /// - IHtmlContent CheckBoxFor([NotNull] Expression> expression, object htmlAttributes); + IHtmlContent CheckBoxFor(Expression> expression, object htmlAttributes); /// /// Returns HTML markup for the , using a display template, specified HTML field @@ -80,7 +79,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// result. /// IHtmlContent DisplayFor( - [NotNull] Expression> expression, + Expression> expression, string templateName, string htmlFieldName, object additionalViewData); @@ -91,7 +90,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// An expression to be evaluated against the current model. /// The type of the result. /// A containing the display name. - string DisplayNameFor([NotNull] Expression> expression); + string DisplayNameFor(Expression> expression); /// /// Returns the display name for the specified @@ -102,7 +101,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The type of the result. /// A containing the display name. string DisplayNameForInnerType( - [NotNull] Expression> expression); + Expression> expression); /// /// Returns the simple display text for the specified . @@ -114,7 +113,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// If the result is null, returns /// . /// - string DisplayTextFor([NotNull] Expression> expression); + string DisplayTextFor(Expression> expression); /// /// Returns a single-selection HTML <select> element for the , using the @@ -140,7 +139,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// representation of the to set element's "id" attribute. /// IHtmlContent DropDownListFor( - [NotNull] Expression> expression, + Expression> expression, IEnumerable selectList, string optionLabel, object htmlAttributes); @@ -168,7 +167,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// elements for each property in the result. /// IHtmlContent EditorFor( - [NotNull] Expression> expression, + Expression> expression, string templateName, string htmlFieldName, object additionalViewData); @@ -210,7 +209,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// IHtmlContent HiddenFor( - [NotNull] Expression> expression, + Expression> expression, object htmlAttributes); /// @@ -219,7 +218,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// An expression to be evaluated against the current model. /// The type of the result. /// A containing the element Id. - string IdFor([NotNull] Expression> expression); + string IdFor(Expression> expression); /// /// Returns a <label> element for the specified . @@ -233,7 +232,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The type of the result. /// A new containing the <label> element. IHtmlContent LabelFor( - [NotNull] Expression> expression, + Expression> expression, string labelText, object htmlAttributes); @@ -258,7 +257,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// representation of the to set element's "id" attribute. /// IHtmlContent ListBoxFor( - [NotNull] Expression> expression, + Expression> expression, IEnumerable selectList, object htmlAttributes); @@ -268,7 +267,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// An expression to be evaluated against the current model. /// The type of the result. /// A containing the element name. - string NameFor([NotNull] Expression> expression); + string NameFor(Expression> expression); /// /// Returns an <input> element of type "password" for the specified . @@ -297,7 +296,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// IHtmlContent PasswordFor( - [NotNull] Expression> expression, + Expression> expression, object htmlAttributes); /// @@ -337,8 +336,8 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// IHtmlContent RadioButtonFor( - [NotNull] Expression> expression, - [NotNull] object value, + Expression> expression, + object value, object htmlAttributes); /// @@ -378,7 +377,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// IHtmlContent TextAreaFor( - [NotNull] Expression> expression, + Expression> expression, int rows, int columns, object htmlAttributes); @@ -418,7 +417,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// /// IHtmlContent TextBoxFor( - [NotNull] Expression> expression, + Expression> expression, string format, object htmlAttributes); @@ -446,7 +445,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// is valid and client-side validation is disabled. /// IHtmlContent ValidationMessageFor( - [NotNull] Expression> expression, + Expression> expression, string message, object htmlAttributes, string tag); @@ -465,7 +464,7 @@ namespace Microsoft.AspNet.Mvc.Rendering /// is null or empty. /// string ValueFor( - [NotNull] Expression> expression, + Expression> expression, string format); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IJsonHelper.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IJsonHelper.cs index e9a3203806..20c9247164 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IJsonHelper.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IJsonHelper.cs @@ -1,7 +1,6 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.Framework.Internal; using Newtonsoft.Json; namespace Microsoft.AspNet.Mvc.Rendering @@ -24,6 +23,6 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The value to serialize as JSON. /// The to be used by the serializer. /// A new containing the serialized JSON. - HtmlString Serialize(object value, [NotNull] JsonSerializerSettings serializerSettings); + HtmlString Serialize(object value, JsonSerializerSettings serializerSettings); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/MultiSelectList.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/MultiSelectList.cs index d64e0bab7c..6622c5df3f 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/MultiSelectList.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/MultiSelectList.cs @@ -7,7 +7,6 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Rendering { @@ -15,28 +14,44 @@ namespace Microsoft.AspNet.Mvc.Rendering { private IList _groups; - public MultiSelectList([NotNull] IEnumerable items) + public MultiSelectList(IEnumerable items) : this(items, selectedValues: null) { + if (items == null) + { + throw new ArgumentNullException(nameof(items)); + } } - public MultiSelectList([NotNull] IEnumerable items, IEnumerable selectedValues) + public MultiSelectList(IEnumerable items, IEnumerable selectedValues) : this(items, dataValueField: null, dataTextField: null, selectedValues: selectedValues) { + if (items == null) + { + throw new ArgumentNullException(nameof(items)); + } } - public MultiSelectList([NotNull] IEnumerable items, string dataValueField, string dataTextField) + public MultiSelectList(IEnumerable items, string dataValueField, string dataTextField) : this(items, dataValueField, dataTextField, selectedValues: null) { + if (items == null) + { + throw new ArgumentNullException(nameof(items)); + } } public MultiSelectList( - [NotNull] IEnumerable items, + IEnumerable items, string dataValueField, string dataTextField, IEnumerable selectedValues) : this(items, dataValueField, dataTextField, selectedValues, dataGroupField: null) { + if (items == null) + { + throw new ArgumentNullException(nameof(items)); + } } /// @@ -53,12 +68,17 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The data group field. Used to match the Group property of the corresponding /// . public MultiSelectList( - [NotNull] IEnumerable items, + IEnumerable items, string dataValueField, string dataTextField, IEnumerable selectedValues, string dataGroupField) { + if (items == null) + { + throw new ArgumentNullException(nameof(items)); + } + Items = items; DataValueField = dataValueField; DataTextField = dataTextField; diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/MvcForm.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/MvcForm.cs index 46b76893a9..2962a8db60 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/MvcForm.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/MvcForm.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Rendering { @@ -12,8 +11,13 @@ namespace Microsoft.AspNet.Mvc.Rendering private readonly ViewContext _viewContext; private bool _disposed; - public MvcForm([NotNull] ViewContext viewContext) + public MvcForm(ViewContext viewContext) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + _viewContext = viewContext; // Push the new FormContext; GenerateEndForm() does the corresponding pop. diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/SelectList.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/SelectList.cs index f5da4bbeeb..915b2161bd 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/SelectList.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/SelectList.cs @@ -1,35 +1,52 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Rendering { public class SelectList : MultiSelectList { - public SelectList([NotNull] IEnumerable items) + public SelectList(IEnumerable items) : this(items, selectedValue: null) { + if (items == null) + { + throw new ArgumentNullException(nameof(items)); + } } - public SelectList([NotNull] IEnumerable items, object selectedValue) + public SelectList(IEnumerable items, object selectedValue) : this(items, dataValueField: null, dataTextField: null, selectedValue: selectedValue) { + if (items == null) + { + throw new ArgumentNullException(nameof(items)); + } } - public SelectList([NotNull] IEnumerable items, string dataValueField, string dataTextField) + public SelectList(IEnumerable items, string dataValueField, string dataTextField) : this(items, dataValueField, dataTextField, selectedValue: null) { + if (items == null) + { + throw new ArgumentNullException(nameof(items)); + } } public SelectList( - [NotNull] IEnumerable items, + IEnumerable items, string dataValueField, string dataTextField, object selectedValue) : base(items, dataValueField, dataTextField, ToEnumerable(selectedValue)) { + if (items == null) + { + throw new ArgumentNullException(nameof(items)); + } + SelectedValue = selectedValue; } @@ -47,13 +64,18 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The data group field. Used to match the Group property of the corresponding /// . public SelectList( - [NotNull] IEnumerable items, + IEnumerable items, string dataValueField, string dataTextField, object selectedValue, string dataGroupField) : base(items, dataValueField, dataTextField, ToEnumerable(selectedValue), dataGroupField) { + if (items == null) + { + throw new ArgumentNullException(nameof(items)); + } + SelectedValue = selectedValue; } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/TagBuilder.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/TagBuilder.cs index 0b4ab7764a..a329153a6c 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/TagBuilder.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/TagBuilder.cs @@ -71,8 +71,13 @@ namespace Microsoft.AspNet.Mvc.Rendering /// Valid HTML 4.01 "id" attribute for an element with the given . /// /// Valid "id" attributes are defined in http://www.w3.org/TR/html401/types.html#type-id - public static string CreateSanitizedId(string name, [NotNull] string invalidCharReplacement) + public static string CreateSanitizedId(string name, string invalidCharReplacement) { + if (invalidCharReplacement == null) + { + throw new ArgumentNullException(nameof(invalidCharReplacement)); + } + if (string.IsNullOrEmpty(name)) { return string.Empty; @@ -127,8 +132,13 @@ namespace Microsoft.AspNet.Mvc.Rendering return stringBuffer.ToString(); } - public void GenerateId(string name, [NotNull] string idAttributeDotReplacement) + public void GenerateId(string name, string idAttributeDotReplacement) { + if (idAttributeDotReplacement == null) + { + throw new ArgumentNullException(nameof(idAttributeDotReplacement)); + } + if (!Attributes.ContainsKey("id")) { var sanitizedId = CreateSanitizedId(name, idAttributeDotReplacement); diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/ViewComponentHelperExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/ViewComponentHelperExtensions.cs index 396cbc20e8..9d49ac4f01 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/ViewComponentHelperExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/ViewComponentHelperExtensions.cs @@ -1,36 +1,54 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Threading.Tasks; -using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.AspNet.Mvc.ViewComponents; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Rendering { public static class ViewComponentHelperExtensions { - public static HtmlString Invoke([NotNull] this IViewComponentHelper helper, + public static HtmlString Invoke(this IViewComponentHelper helper, params object[] args) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + return helper.Invoke(typeof(TComponent), args); } - public static void RenderInvoke([NotNull] this IViewComponentHelper helper, + public static void RenderInvoke(this IViewComponentHelper helper, params object[] args) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + helper.RenderInvoke(typeof(TComponent), args); } - public static Task InvokeAsync([NotNull] this IViewComponentHelper helper, + public static Task InvokeAsync(this IViewComponentHelper helper, params object[] args) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + return helper.InvokeAsync(typeof(TComponent), args); } - public static Task RenderInvokeAsync([NotNull] this IViewComponentHelper helper, + public static Task RenderInvokeAsync(this IViewComponentHelper helper, params object[] args) { + if (helper == null) + { + throw new ArgumentNullException(nameof(helper)); + } + return helper.RenderInvokeAsync(typeof(TComponent), args); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/ViewContext.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/ViewContext.cs index 954ec1a849..c342295ceb 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/ViewContext.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/ViewContext.cs @@ -1,11 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.IO; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ViewEngines; using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.Rendering { @@ -40,14 +40,44 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The . /// The to render output to. public ViewContext( - [NotNull] ActionContext actionContext, - [NotNull] IView view, - [NotNull] ViewDataDictionary viewData, - [NotNull] ITempDataDictionary tempData, - [NotNull] TextWriter writer, - [NotNull] HtmlHelperOptions htmlHelperOptions) + ActionContext actionContext, + IView view, + ViewDataDictionary viewData, + ITempDataDictionary tempData, + TextWriter writer, + HtmlHelperOptions htmlHelperOptions) : base(actionContext) { + if (actionContext == null) + { + throw new ArgumentNullException(nameof(actionContext)); + } + + if (view == null) + { + throw new ArgumentNullException(nameof(view)); + } + + if (viewData == null) + { + throw new ArgumentNullException(nameof(viewData)); + } + + if (tempData == null) + { + throw new ArgumentNullException(nameof(tempData)); + } + + if (writer == null) + { + throw new ArgumentNullException(nameof(writer)); + } + + if (htmlHelperOptions == null) + { + throw new ArgumentNullException(nameof(htmlHelperOptions)); + } + View = view; ViewData = viewData; TempData = tempData; @@ -68,12 +98,32 @@ namespace Microsoft.AspNet.Mvc.Rendering /// The . /// The to render output to. public ViewContext( - [NotNull] ViewContext viewContext, - [NotNull] IView view, - [NotNull] ViewDataDictionary viewData, - [NotNull] TextWriter writer) + ViewContext viewContext, + IView view, + ViewDataDictionary viewData, + TextWriter writer) : base(viewContext) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + + if (view == null) + { + throw new ArgumentNullException(nameof(view)); + } + + if (viewData == null) + { + throw new ArgumentNullException(nameof(viewData)); + } + + if (writer == null) + { + throw new ArgumentNullException(nameof(writer)); + } + _formContext = viewContext.FormContext; ClientValidationEnabled = viewContext.ClientValidationEnabled; Html5DateRenderingMode = viewContext.Html5DateRenderingMode; diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/SkipStatusCodePagesAttribute.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/SkipStatusCodePagesAttribute.cs index d0573e883b..a6f387df2a 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/SkipStatusCodePagesAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/SkipStatusCodePagesAttribute.cs @@ -5,7 +5,6 @@ using System; using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Mvc.Filters; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc { @@ -16,13 +15,22 @@ namespace Microsoft.AspNet.Mvc public class SkipStatusCodePagesAttribute : Attribute, IResourceFilter { /// - public void OnResourceExecuted([NotNull] ResourceExecutedContext context) + public void OnResourceExecuted(ResourceExecutedContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } } /// - public void OnResourceExecuting([NotNull] ResourceExecutingContext context) + public void OnResourceExecuting(ResourceExecutingContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var statusCodeFeature = context.HttpContext.Features.Get(); if (statusCodeFeature != null) { diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponent.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponent.cs index a6e2f918d5..2e7c30fc77 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponent.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponent.cs @@ -1,17 +1,16 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Security.Principal; using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.ViewComponents; using Microsoft.AspNet.Mvc.ViewEngines; using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.AspNet.Routing; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; using Newtonsoft.Json; namespace Microsoft.AspNet.Mvc @@ -114,10 +113,13 @@ namespace Microsoft.AspNet.Mvc return _url; } - - [param: NotNull] set { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + _url = value; } } @@ -135,10 +137,13 @@ namespace Microsoft.AspNet.Mvc return _viewComponentContext; } - - [param: NotNull] set { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + _viewComponentContext = value; } } @@ -181,10 +186,13 @@ namespace Microsoft.AspNet.Mvc return _viewEngine; } - - [param: NotNull] set { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + _viewEngine = value; } } @@ -194,8 +202,13 @@ namespace Microsoft.AspNet.Mvc /// /// The content, will be HTML encoded before output. /// A . - public ContentViewComponentResult Content([NotNull] string content) + public ContentViewComponentResult Content(string content) { + if (content == null) + { + throw new ArgumentNullException(nameof(content)); + } + return new ContentViewComponentResult(content); } @@ -218,8 +231,13 @@ namespace Microsoft.AspNet.Mvc /// A . /// Callers should cache an instance of to avoid /// recreating cached data with each call. - public JsonViewComponentResult Json(object value, [NotNull] JsonSerializerSettings serializerSettings) + public JsonViewComponentResult Json(object value, JsonSerializerSettings serializerSettings) { + if (serializerSettings == null) + { + throw new ArgumentNullException(nameof(serializerSettings)); + } + return new JsonViewComponentResult(value, serializerSettings); } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponentResult.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponentResult.cs index aa3d1ec3a5..0906bb2a55 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponentResult.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponentResult.cs @@ -6,7 +6,6 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.AspNet.Mvc.ViewComponents; using Microsoft.AspNet.Mvc.ViewEngines; using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.AspNet.Mvc.ViewFeatures.Internal; diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ContentViewComponentResult.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ContentViewComponentResult.cs index 5f54d1e6c6..f2880a5111 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ContentViewComponentResult.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ContentViewComponentResult.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ViewComponents { @@ -26,8 +26,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents /// Initializes a new . /// /// Content to write. The content be HTML encoded when output. - public ContentViewComponentResult([NotNull] string content) + public ContentViewComponentResult(string content) { + if (content == null) + { + throw new ArgumentNullException(nameof(content)); + } + Content = content; EncodedContent = new HtmlString(WebUtility.HtmlEncode(content)); } @@ -39,8 +44,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents /// Content to write. The content is treated as already HTML encoded, and no further encoding /// will be performed. /// - public ContentViewComponentResult([NotNull] HtmlString encodedContent) + public ContentViewComponentResult(HtmlString encodedContent) { + if (encodedContent == null) + { + throw new ArgumentNullException(nameof(encodedContent)); + } + EncodedContent = encodedContent; Content = WebUtility.HtmlDecode(encodedContent.ToString()); } @@ -59,8 +69,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents /// Writes the . /// /// The . - public void Execute([NotNull] ViewComponentContext context) + public void Execute(ViewComponentContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + context.Writer.Write(EncodedContent.ToString()); } @@ -69,8 +84,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents /// /// The . /// A completed . - public Task ExecuteAsync([NotNull] ViewComponentContext context) + public Task ExecuteAsync(ViewComponentContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + return context.Writer.WriteAsync(EncodedContent.ToString()); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentActivator.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentActivator.cs index 8920bfd695..a7f5e6916b 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentActivator.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentActivator.cs @@ -35,8 +35,18 @@ namespace Microsoft.AspNet.Mvc.ViewComponents } /// - public virtual void Activate([NotNull] object viewComponent, [NotNull] ViewComponentContext context) + public virtual void Activate(object viewComponent, ViewComponentContext context) { + if (viewComponent == null) + { + throw new ArgumentNullException(nameof(viewComponent)); + } + + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var propertiesToActivate = _injectActions.GetOrAdd( viewComponent.GetType(), _getPropertiesToActivate); diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentDescriptorProvider.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentDescriptorProvider.cs index 4dd0dfd62d..0cd2f12fc5 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentDescriptorProvider.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentDescriptorProvider.cs @@ -1,11 +1,11 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Microsoft.AspNet.Mvc.Infrastructure; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ViewComponents { @@ -53,8 +53,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents /// /// true if represents a View Component class, otherwise false. /// - protected virtual bool IsViewComponentType([NotNull] TypeInfo typeInfo) + protected virtual bool IsViewComponentType(TypeInfo typeInfo) { + if (typeInfo == null) + { + throw new ArgumentNullException(nameof(typeInfo)); + } + return ViewComponentConventions.IsComponent(typeInfo); } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentHelper.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentHelper.cs index b67f77d312..ca48195364 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentHelper.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentHelper.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.AspNet.Mvc.ViewFeatures.Internal; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ViewComponents { @@ -19,22 +18,47 @@ namespace Microsoft.AspNet.Mvc.ViewComponents private ViewContext _viewContext; public DefaultViewComponentHelper( - [NotNull] IViewComponentDescriptorCollectionProvider descriptorProvider, - [NotNull] IViewComponentSelector selector, - [NotNull] IViewComponentInvokerFactory invokerFactory) + IViewComponentDescriptorCollectionProvider descriptorProvider, + IViewComponentSelector selector, + IViewComponentInvokerFactory invokerFactory) { + if (descriptorProvider == null) + { + throw new ArgumentNullException(nameof(descriptorProvider)); + } + + if (selector == null) + { + throw new ArgumentNullException(nameof(selector)); + } + + if (invokerFactory == null) + { + throw new ArgumentNullException(nameof(invokerFactory)); + } + _descriptorProvider = descriptorProvider; _selector = selector; _invokerFactory = invokerFactory; } - public void Contextualize([NotNull] ViewContext viewContext) + public void Contextualize(ViewContext viewContext) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + _viewContext = viewContext; } - public HtmlString Invoke([NotNull] string name, params object[] arguments) + public HtmlString Invoke(string name, params object[] arguments) { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + var descriptor = SelectComponent(name); using (var writer = new StringWriter()) @@ -44,8 +68,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents } } - public HtmlString Invoke([NotNull] Type componentType, params object[] arguments) + public HtmlString Invoke(Type componentType, params object[] arguments) { + if (componentType == null) + { + throw new ArgumentNullException(nameof(componentType)); + } + var descriptor = SelectComponent(componentType); using (var writer = new StringWriter()) @@ -55,20 +84,35 @@ namespace Microsoft.AspNet.Mvc.ViewComponents } } - public void RenderInvoke([NotNull] string name, params object[] arguments) + public void RenderInvoke(string name, params object[] arguments) { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + var descriptor = SelectComponent(name); InvokeCore(_viewContext.Writer, descriptor, arguments); } - public void RenderInvoke([NotNull] Type componentType, params object[] arguments) + public void RenderInvoke(Type componentType, params object[] arguments) { + if (componentType == null) + { + throw new ArgumentNullException(nameof(componentType)); + } + var descriptor = SelectComponent(componentType); InvokeCore(_viewContext.Writer, descriptor, arguments); } - public async Task InvokeAsync([NotNull] string name, params object[] arguments) + public async Task InvokeAsync(string name, params object[] arguments) { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + var descriptor = SelectComponent(name); using (var writer = new StringWriter()) @@ -78,8 +122,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents } } - public async Task InvokeAsync([NotNull] Type componentType, params object[] arguments) + public async Task InvokeAsync(Type componentType, params object[] arguments) { + if (componentType == null) + { + throw new ArgumentNullException(nameof(componentType)); + } + var descriptor = SelectComponent(componentType); using (var writer = new StringWriter()) @@ -89,14 +138,24 @@ namespace Microsoft.AspNet.Mvc.ViewComponents } } - public Task RenderInvokeAsync([NotNull] string name, params object[] arguments) + public Task RenderInvokeAsync(string name, params object[] arguments) { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + var descriptor = SelectComponent(name); return InvokeCoreAsync(_viewContext.Writer, descriptor, arguments); } - public Task RenderInvokeAsync([NotNull] Type componentType, params object[] arguments) + public Task RenderInvokeAsync(Type componentType, params object[] arguments) { + if (componentType == null) + { + throw new ArgumentNullException(nameof(componentType)); + } + var descriptor = SelectComponent(componentType); return InvokeCoreAsync(_viewContext.Writer, descriptor, arguments); } @@ -128,10 +187,20 @@ namespace Microsoft.AspNet.Mvc.ViewComponents } private Task InvokeCoreAsync( - [NotNull] TextWriter writer, - [NotNull] ViewComponentDescriptor descriptor, + TextWriter writer, + ViewComponentDescriptor descriptor, object[] arguments) { + if (writer == null) + { + throw new ArgumentNullException(nameof(writer)); + } + + if (descriptor == null) + { + throw new ArgumentNullException(nameof(descriptor)); + } + var context = new ViewComponentContext(descriptor, arguments, _viewContext, writer); var invoker = _invokerFactory.CreateInstance(context); @@ -145,10 +214,20 @@ namespace Microsoft.AspNet.Mvc.ViewComponents } private void InvokeCore( - [NotNull] TextWriter writer, - [NotNull] ViewComponentDescriptor descriptor, + TextWriter writer, + ViewComponentDescriptor descriptor, object[] arguments) { + if (writer == null) + { + throw new ArgumentNullException(nameof(writer)); + } + + if (descriptor == null) + { + throw new ArgumentNullException(nameof(descriptor)); + } + var context = new ViewComponentContext(descriptor, arguments, _viewContext, writer); var invoker = _invokerFactory.CreateInstance(context); diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentInvoker.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentInvoker.cs index 4159667630..88c569b9b1 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentInvoker.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentInvoker.cs @@ -9,7 +9,6 @@ using Microsoft.AspNet.Mvc.Controllers; using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ViewComponents { @@ -19,15 +18,30 @@ namespace Microsoft.AspNet.Mvc.ViewComponents private readonly IViewComponentActivator _viewComponentActivator; public DefaultViewComponentInvoker( - [NotNull] ITypeActivatorCache typeActivatorCache, - [NotNull] IViewComponentActivator viewComponentActivator) + ITypeActivatorCache typeActivatorCache, + IViewComponentActivator viewComponentActivator) { + if (typeActivatorCache == null) + { + throw new ArgumentNullException(nameof(typeActivatorCache)); + } + + if (viewComponentActivator == null) + { + throw new ArgumentNullException(nameof(viewComponentActivator)); + } + _typeActivatorCache = typeActivatorCache; _viewComponentActivator = viewComponentActivator; } - public void Invoke([NotNull] ViewComponentContext context) + public void Invoke(ViewComponentContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var method = ViewComponentMethodSelector.FindSyncMethod( context.ViewComponentDescriptor.Type.GetTypeInfo(), context.Arguments); @@ -41,8 +55,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents result.Execute(context); } - public async Task InvokeAsync([NotNull] ViewComponentContext context) + public async Task InvokeAsync(ViewComponentContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + IViewComponentResult result; var asyncMethod = ViewComponentMethodSelector.FindAsyncMethod( @@ -74,20 +93,35 @@ namespace Microsoft.AspNet.Mvc.ViewComponents await result.ExecuteAsync(context); } - private object CreateComponent([NotNull] ViewComponentContext context) + private object CreateComponent(ViewComponentContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var services = context.ViewContext.HttpContext.RequestServices; var component = _typeActivatorCache.CreateInstance( - services, + services, context.ViewComponentDescriptor.Type); _viewComponentActivator.Activate(component, context); return component; } private async Task InvokeAsyncCore( - [NotNull] MethodInfo method, - [NotNull] ViewComponentContext context) + MethodInfo method, + ViewComponentContext context) { + if (method == null) + { + throw new ArgumentNullException(nameof(method)); + } + + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var component = CreateComponent(context); var result = await ControllerActionExecutor.ExecuteAsync(method, component, context.Arguments); @@ -95,8 +129,18 @@ namespace Microsoft.AspNet.Mvc.ViewComponents return CoerceToViewComponentResult(result); } - public IViewComponentResult InvokeSyncCore([NotNull] MethodInfo method, [NotNull] ViewComponentContext context) + public IViewComponentResult InvokeSyncCore(MethodInfo method, ViewComponentContext context) { + if (method == null) + { + throw new ArgumentNullException(nameof(method)); + } + + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var component = CreateComponent(context); object result = null; diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentInvokerFactory.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentInvokerFactory.cs index 58c1faeb91..bfa67c2c1d 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentInvokerFactory.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentInvokerFactory.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNet.Mvc.Infrastructure; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ViewComponents { @@ -23,8 +23,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents // We don't currently make use of the descriptor or the arguments here (they are available on the context). // We might do this some day to cache which method we select, so resist the urge to 'clean' this without // considering that possibility. - public IViewComponentInvoker CreateInstance([NotNull] ViewComponentContext context) + public IViewComponentInvoker CreateInstance(ViewComponentContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + return new DefaultViewComponentInvoker( _typeActivatorCache, _viewComponentActivator); diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentSelector.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentSelector.cs index 994ae493ce..ec3978cd2a 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentSelector.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/DefaultViewComponentSelector.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ViewComponents { @@ -28,8 +27,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents } /// - public ViewComponentDescriptor SelectComponent([NotNull] string componentName) + public ViewComponentDescriptor SelectComponent(string componentName) { + if (componentName == null) + { + throw new ArgumentNullException(nameof(componentName)); + } + var collection = _descriptorProvider.ViewComponents; if (_cache == null || _cache.Version != collection.Version) { diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/IViewComponentInvoker.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/IViewComponentInvoker.cs index 203f5cbd86..7e9e5d7f8f 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/IViewComponentInvoker.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/IViewComponentInvoker.cs @@ -2,14 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ViewComponents { public interface IViewComponentInvoker { - void Invoke([NotNull] ViewComponentContext context); + void Invoke(ViewComponentContext context); - Task InvokeAsync([NotNull] ViewComponentContext context); + Task InvokeAsync(ViewComponentContext context); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/IViewComponentInvokerFactory.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/IViewComponentInvokerFactory.cs index 726da7c7bd..82e629f7d1 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/IViewComponentInvokerFactory.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/IViewComponentInvokerFactory.cs @@ -1,12 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.Framework.Internal; - namespace Microsoft.AspNet.Mvc.ViewComponents { public interface IViewComponentInvokerFactory { - IViewComponentInvoker CreateInstance([NotNull] ViewComponentContext context); + IViewComponentInvoker CreateInstance(ViewComponentContext context); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/IViewComponentSelector.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/IViewComponentSelector.cs index c4ef441249..d4813b4d57 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/IViewComponentSelector.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/IViewComponentSelector.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.Framework.Internal; - namespace Microsoft.AspNet.Mvc.ViewComponents { /// @@ -15,6 +13,6 @@ namespace Microsoft.AspNet.Mvc.ViewComponents /// /// The View Component name. /// A , or null if no match is found. - ViewComponentDescriptor SelectComponent([NotNull] string componentName); + ViewComponentDescriptor SelectComponent(string componentName); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/JsonViewComponentResult.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/JsonViewComponentResult.cs index 295d431427..4b583dd3a5 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/JsonViewComponentResult.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/JsonViewComponentResult.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Threading.Tasks; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; using Microsoft.Framework.OptionsModel; using Newtonsoft.Json; @@ -31,8 +31,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents /// The value to format as JSON text. /// The to be used by /// the formatter. - public JsonViewComponentResult(object value, [NotNull] JsonSerializerSettings serializerSettings) + public JsonViewComponentResult(object value, JsonSerializerSettings serializerSettings) { + if (serializerSettings == null) + { + throw new ArgumentNullException(nameof(serializerSettings)); + } + Value = value; _serializerSettings = serializerSettings; } @@ -46,8 +51,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents /// Renders JSON text to the output. /// /// The . - public void Execute([NotNull] ViewComponentContext context) + public void Execute(ViewComponentContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var serializerSettings = _serializerSettings; if (serializerSettings == null) { @@ -73,8 +83,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents /// /// The . /// A completed . - public Task ExecuteAsync([NotNull] ViewComponentContext context) + public Task ExecuteAsync(ViewComponentContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + Execute(context); return Task.FromResult(true); } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewComponentContext.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewComponentContext.cs index 9f780f58c2..4029fd929e 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewComponentContext.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewComponentContext.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.IO; using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ViewComponents { @@ -36,11 +36,31 @@ namespace Microsoft.AspNet.Mvc.ViewComponents /// The . /// The for writing output. public ViewComponentContext( - [NotNull] ViewComponentDescriptor viewComponentDescriptor, - [NotNull] object[] arguments, - [NotNull] ViewContext viewContext, - [NotNull] TextWriter writer) + ViewComponentDescriptor viewComponentDescriptor, + object[] arguments, + ViewContext viewContext, + TextWriter writer) { + if (viewComponentDescriptor == null) + { + throw new ArgumentNullException(nameof(viewComponentDescriptor)); + } + + if (arguments == null) + { + throw new ArgumentNullException(nameof(arguments)); + } + + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + + if (writer == null) + { + throw new ArgumentNullException(nameof(writer)); + } + ViewComponentDescriptor = viewComponentDescriptor; Arguments = arguments; @@ -48,7 +68,7 @@ namespace Microsoft.AspNet.Mvc.ViewComponents // aren't visible in the calling view. ViewContext = new ViewContext( viewContext, - viewContext.View, + viewContext.View, new ViewDataDictionary(viewContext.ViewData), writer); } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewComponentConventions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewComponentConventions.cs index 656a6e8fdd..a0e459fd41 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewComponentConventions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewComponentConventions.cs @@ -3,7 +3,6 @@ using System; using System.Reflection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ViewComponents { @@ -11,8 +10,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents { private const string ViewComponentSuffix = "ViewComponent"; - public static string GetComponentName([NotNull] TypeInfo componentType) + public static string GetComponentName(TypeInfo componentType) { + if (componentType == null) + { + throw new ArgumentNullException(nameof(componentType)); + } + var attribute = componentType.GetCustomAttribute(); if (attribute != null && !string.IsNullOrEmpty(attribute.Name)) { @@ -30,8 +34,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents return GetShortNameByConvention(componentType); } - public static string GetComponentFullName([NotNull] TypeInfo componentType) + public static string GetComponentFullName(TypeInfo componentType) { + if (componentType == null) + { + throw new ArgumentNullException(nameof(componentType)); + } + var attribute = componentType.GetCustomAttribute(); if (!string.IsNullOrEmpty(attribute?.Name)) { @@ -63,8 +72,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents } } - public static bool IsComponent([NotNull] TypeInfo typeInfo) + public static bool IsComponent(TypeInfo typeInfo) { + if (typeInfo == null) + { + throw new ArgumentNullException(nameof(typeInfo)); + } + if (!typeInfo.IsClass || !typeInfo.IsPublic || typeInfo.IsAbstract || diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewComponentDescriptorCollection.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewComponentDescriptorCollection.cs index e13d6a2879..2c1a317e07 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewComponentDescriptorCollection.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewComponentDescriptorCollection.cs @@ -1,8 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ViewComponents { @@ -16,8 +16,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents /// /// The result of view component discovery /// The unique version of discovered view components. - public ViewComponentDescriptorCollection([NotNull] IEnumerable items, int version) + public ViewComponentDescriptorCollection(IEnumerable items, int version) { + if (items == null) + { + throw new ArgumentNullException(nameof(items)); + } + Items = new List(items); Version = version; } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewComponentMethodSelector.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewComponentMethodSelector.cs index 8f6498844a..2d5e8cc1df 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewComponentMethodSelector.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewComponentMethodSelector.cs @@ -6,7 +6,6 @@ using System.Linq.Expressions; using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ViewComponents { @@ -15,8 +14,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents public const string AsyncMethodName = "InvokeAsync"; public const string SyncMethodName = "Invoke"; - public static MethodInfo FindAsyncMethod([NotNull] TypeInfo componentType, object[] args) + public static MethodInfo FindAsyncMethod(TypeInfo componentType, object[] args) { + if (componentType == null) + { + throw new ArgumentNullException(nameof(componentType)); + } + var method = GetMethod(componentType, args, AsyncMethodName); if (method == null) { @@ -33,8 +37,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents return method; } - public static MethodInfo FindSyncMethod([NotNull] TypeInfo componentType, object[] args) + public static MethodInfo FindSyncMethod(TypeInfo componentType, object[] args) { + if (componentType == null) + { + throw new ArgumentNullException(nameof(componentType)); + } + var method = GetMethod(componentType, args, SyncMethodName); if (method == null) { diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewViewComponentResult.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewViewComponentResult.cs index b2d561826d..4c73e85df5 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewViewComponentResult.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewViewComponentResult.cs @@ -8,7 +8,6 @@ using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.ViewEngines; using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ViewComponents { @@ -49,8 +48,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents /// /// This method synchronously calls and blocks on . /// - public void Execute([NotNull] ViewComponentContext context) + public void Execute(ViewComponentContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var task = ExecuteAsync(context); task.GetAwaiter().GetResult(); } @@ -61,8 +65,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents /// /// The for the current component execution. /// A which will complete when view rendering is completed. - public async Task ExecuteAsync([NotNull] ViewComponentContext context) + public async Task ExecuteAsync(ViewComponentContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + var viewEngine = ViewEngine ?? ResolveViewEngine(context); var viewData = ViewData ?? context.ViewData; var isNullOrEmptyViewName = string.IsNullOrEmpty(ViewName); diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/CompositeViewEngine.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/CompositeViewEngine.cs index 115ec3307d..0cc348b943 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/CompositeViewEngine.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/CompositeViewEngine.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.Linq; -using Microsoft.Framework.Internal; using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Mvc.ViewEngines @@ -25,17 +25,37 @@ namespace Microsoft.AspNet.Mvc.ViewEngines /// public ViewEngineResult FindPartialView( - [NotNull] ActionContext context, - [NotNull] string partialViewName) + ActionContext context, + string partialViewName) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (partialViewName == null) + { + throw new ArgumentNullException(nameof(partialViewName)); + } + return FindView(context, partialViewName, partial: true); } /// public ViewEngineResult FindView( - [NotNull] ActionContext context, - [NotNull] string viewName) + ActionContext context, + string viewName) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (viewName == null) + { + throw new ArgumentNullException(nameof(viewName)); + } + return FindView(context, viewName, partial: false); } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/IView.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/IView.cs index f4acc9cab0..f86ef5772a 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/IView.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/IView.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ViewEngines { @@ -22,6 +21,6 @@ namespace Microsoft.AspNet.Mvc.ViewEngines /// /// The . /// A that on completion renders the view. - Task RenderAsync([NotNull] ViewContext context); + Task RenderAsync(ViewContext context); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/ViewEngineResult.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/ViewEngineResult.cs index 9ac25fc67a..635c03ec19 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/ViewEngineResult.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/ViewEngineResult.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Mvc.ViewFeatures; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ViewEngines { @@ -26,9 +25,19 @@ namespace Microsoft.AspNet.Mvc.ViewEngines } public static ViewEngineResult NotFound( - [NotNull] string viewName, - [NotNull] IEnumerable searchedLocations) + string viewName, + IEnumerable searchedLocations) { + if (viewName == null) + { + throw new ArgumentNullException(nameof(viewName)); + } + + if (searchedLocations == null) + { + throw new ArgumentNullException(nameof(searchedLocations)); + } + return new ViewEngineResult { SearchedLocations = searchedLocations, @@ -36,8 +45,18 @@ namespace Microsoft.AspNet.Mvc.ViewEngines }; } - public static ViewEngineResult Found([NotNull] string viewName, [NotNull] IView view) + public static ViewEngineResult Found(string viewName, IView view) { + if (viewName == null) + { + throw new ArgumentNullException(nameof(viewName)); + } + + if (view == null) + { + throw new ArgumentNullException(nameof(view)); + } + return new ViewEngineResult { View = view, diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/CachedExpressionCompiler.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/CachedExpressionCompiler.cs index 7604fc8e73..d6ec492422 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/CachedExpressionCompiler.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/CachedExpressionCompiler.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Concurrent; using System.Linq.Expressions; using System.Reflection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Mvc.ViewFeatures { @@ -17,8 +16,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures // If the provided expression is particularly obscure and the system doesn't know // how to handle it, we'll just compile the expression as normal. public static Func Process( - [NotNull] Expression> expression) + Expression> expression) { + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return Compiler.Compile(expression); } @@ -32,8 +36,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures private static readonly ConcurrentDictionary> _constMemberAccessCache = new ConcurrentDictionary>(); - public static Func Compile([NotNull] Expression> expression) + public static Func Compile(Expression> expression) { + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + return CompileFromIdentityFunc(expression) ?? CompileFromConstLookup(expression) ?? CompileFromMemberAccess(expression) @@ -41,8 +50,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures } private static Func CompileFromConstLookup( - [NotNull] Expression> expression) + Expression> expression) { + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + var constantExpression = expression.Body as ConstantExpression; if (constantExpression != null) { @@ -56,8 +70,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures } private static Func CompileFromIdentityFunc( - [NotNull] Expression> expression) + Expression> expression) { + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + if (expression.Body == expression.Parameters[0]) { // model => model @@ -75,8 +94,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures } private static Func CompileFromMemberAccess( - [NotNull] Expression> expression) + Expression> expression) { + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + // Performance tests show that on the x64 platform, special-casing static member and // captured local variable accesses is faster than letting the fingerprinting system // handle them. On the x86 platform, the fingerprinting system is faster, but only @@ -118,8 +142,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures return null; } - private static Func CompileSlow([NotNull] Expression> expression) + private static Func CompileSlow(Expression> expression) { + if (expression == null) + { + throw new ArgumentNullException(nameof(expression)); + } + // fallback compilation system - just compile the expression directly return expression.Compile(); } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/DefaultEditorTemplates.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/DefaultEditorTemplates.cs index cf64f34ddc..7c74d3e462 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/DefaultEditorTemplates.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/DefaultEditorTemplates.cs @@ -280,7 +280,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var valueDivTag = new TagBuilder("div"); valueDivTag.AddCssClass("editor-field"); - + valueDivTag.InnerHtml.Append(templateBuilderResult); valueDivTag.InnerHtml.AppendEncoded(" "); valueDivTag.InnerHtml.Append(htmlHelper.ValidationMessage( @@ -365,13 +365,23 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures return GenerateTextBox(htmlHelper, inputType: "number"); } - public static IHtmlContent FileInputTemplate([NotNull] IHtmlHelper htmlHelper) + public static IHtmlContent FileInputTemplate(IHtmlHelper htmlHelper) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + return GenerateTextBox(htmlHelper, inputType: "file"); } - public static IHtmlContent FileCollectionInputTemplate([NotNull] IHtmlHelper htmlHelper) + public static IHtmlContent FileCollectionInputTemplate(IHtmlHelper htmlHelper) { + if (htmlHelper == null) + { + throw new ArgumentNullException(nameof(htmlHelper)); + } + var htmlAttributes = CreateHtmlAttributes(htmlHelper, className: "text-box single-line", inputType: "file"); htmlAttributes["multiple"] = "multiple"; diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/DefaultHtmlGenerator.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/DefaultHtmlGenerator.cs index ff4855a00e..bdd6e8be7d 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/DefaultHtmlGenerator.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/DefaultHtmlGenerator.cs @@ -13,7 +13,6 @@ using Microsoft.AspNet.Html.Abstractions; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding.Validation; using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.ViewFeatures.Internal; using Microsoft.Framework.Internal; using Microsoft.Framework.OptionsModel; @@ -43,12 +42,37 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// The . /// The . public DefaultHtmlGenerator( - [NotNull] IAntiforgery antiforgery, - [NotNull] IOptions optionsAccessor, - [NotNull] IModelMetadataProvider metadataProvider, - [NotNull] IUrlHelper urlHelper, - [NotNull] IHtmlEncoder htmlEncoder) + IAntiforgery antiforgery, + IOptions optionsAccessor, + IModelMetadataProvider metadataProvider, + IUrlHelper urlHelper, + IHtmlEncoder htmlEncoder) { + if (antiforgery == null) + { + throw new ArgumentNullException(nameof(antiforgery)); + } + + if (optionsAccessor == null) + { + throw new ArgumentNullException(nameof(optionsAccessor)); + } + + if (metadataProvider == null) + { + throw new ArgumentNullException(nameof(metadataProvider)); + } + + if (urlHelper == null) + { + throw new ArgumentNullException(nameof(urlHelper)); + } + + if (htmlEncoder == null) + { + throw new ArgumentNullException(nameof(htmlEncoder)); + } + _antiforgery = antiforgery; var clientValidatorProviders = optionsAccessor.Value.ClientModelValidatorProviders; _clientModelValidatorProvider = new CompositeClientModelValidatorProvider(clientValidatorProviders); @@ -83,7 +107,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// public virtual TagBuilder GenerateActionLink( - [NotNull] string linkText, + string linkText, string actionName, string controllerName, string protocol, @@ -92,25 +116,40 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures object routeValues, object htmlAttributes) { + if (linkText == null) + { + throw new ArgumentNullException(nameof(linkText)); + } + var url = _urlHelper.Action(actionName, controllerName, routeValues, protocol, hostname, fragment); return GenerateLink(linkText, url, htmlAttributes); } /// - public virtual IHtmlContent GenerateAntiforgery([NotNull] ViewContext viewContext) + public virtual IHtmlContent GenerateAntiforgery(ViewContext viewContext) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + var tag = _antiforgery.GetHtml(viewContext.HttpContext); return new HtmlString(tag); } /// public virtual TagBuilder GenerateCheckBox( - [NotNull] ViewContext viewContext, + ViewContext viewContext, ModelExplorer modelExplorer, string expression, bool? isChecked, object htmlAttributes) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + if (modelExplorer != null) { // CheckBoxFor() case. That API does not support passing isChecked directly. @@ -150,10 +189,15 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// public virtual TagBuilder GenerateHiddenForCheckbox( - [NotNull] ViewContext viewContext, + ViewContext viewContext, ModelExplorer modelExplorer, string expression) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + var tagBuilder = new TagBuilder("input"); tagBuilder.MergeAttribute("type", GetInputTypeString(InputType.Hidden)); tagBuilder.MergeAttribute("value", "false"); @@ -167,13 +211,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// public virtual TagBuilder GenerateForm( - [NotNull] ViewContext viewContext, + ViewContext viewContext, string actionName, string controllerName, object routeValues, string method, object htmlAttributes) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + var defaultMethod = false; if (string.IsNullOrEmpty(method)) { @@ -203,12 +252,17 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// public TagBuilder GenerateRouteForm( - [NotNull] ViewContext viewContext, + ViewContext viewContext, string routeName, object routeValues, string method, object htmlAttributes) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + var action = _urlHelper.RouteUrl(routeName, values: routeValues, protocol: null, host: null, fragment: null); @@ -217,13 +271,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// public virtual TagBuilder GenerateHidden( - [NotNull] ViewContext viewContext, + ViewContext viewContext, ModelExplorer modelExplorer, string expression, object value, bool useViewData, object htmlAttributes) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + // Special-case opaque values and arbitrary binary data. var byteArrayValue = value as byte[]; if (byteArrayValue != null) @@ -248,12 +307,22 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// public virtual TagBuilder GenerateLabel( - [NotNull] ViewContext viewContext, - [NotNull] ModelExplorer modelExplorer, + ViewContext viewContext, + ModelExplorer modelExplorer, string expression, string labelText, object htmlAttributes) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + + if (modelExplorer == null) + { + throw new ArgumentNullException(nameof(modelExplorer)); + } + var resolvedLabelText = labelText ?? modelExplorer.Metadata.DisplayName ?? modelExplorer.Metadata.PropertyName; @@ -280,12 +349,17 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// public virtual TagBuilder GeneratePassword( - [NotNull] ViewContext viewContext, + ViewContext viewContext, ModelExplorer modelExplorer, string expression, object value, object htmlAttributes) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + var htmlAttributeDictionary = GetHtmlAttributeDictionaryOrNull(htmlAttributes); return GenerateInput( viewContext, @@ -303,13 +377,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// public virtual TagBuilder GenerateRadioButton( - [NotNull] ViewContext viewContext, + ViewContext viewContext, ModelExplorer modelExplorer, string expression, object value, bool? isChecked, object htmlAttributes) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + var htmlAttributeDictionary = GetHtmlAttributeDictionaryOrNull(htmlAttributes); if (modelExplorer == null) { @@ -367,7 +446,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// public virtual TagBuilder GenerateRouteLink( - [NotNull] string linkText, + string linkText, string routeName, string protocol, string hostName, @@ -375,13 +454,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures object routeValues, object htmlAttributes) { + if (linkText == null) + { + throw new ArgumentNullException(nameof(linkText)); + } + var url = _urlHelper.RouteUrl(routeName, routeValues, protocol, hostName, fragment); return GenerateLink(linkText, url, htmlAttributes); } /// public TagBuilder GenerateSelect( - [NotNull] ViewContext viewContext, + ViewContext viewContext, ModelExplorer modelExplorer, string optionLabel, string expression, @@ -389,6 +473,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures bool allowMultiple, object htmlAttributes) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + var currentValues = GetCurrentValues(viewContext, modelExplorer, expression, allowMultiple); return GenerateSelect( viewContext, @@ -403,7 +492,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// public virtual TagBuilder GenerateSelect( - [NotNull] ViewContext viewContext, + ViewContext viewContext, ModelExplorer modelExplorer, string optionLabel, string expression, @@ -412,6 +501,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures bool allowMultiple, object htmlAttributes) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + var fullName = GetFullHtmlFieldName(viewContext, expression); if (string.IsNullOrEmpty(fullName)) { @@ -423,7 +517,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures nameof(IHtmlHelper.EditorFor), "htmlFieldName"), nameof(expression)); - } + } // If we got a null selectList, try to use ViewData to get the list of items. if (selectList == null) @@ -468,13 +562,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// public virtual TagBuilder GenerateTextArea( - [NotNull] ViewContext viewContext, + ViewContext viewContext, ModelExplorer modelExplorer, string expression, int rows, int columns, object htmlAttributes) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + if (rows < 0) { throw new ArgumentOutOfRangeException(nameof(rows), Resources.HtmlHelper_TextAreaParameterOutOfRange); @@ -545,13 +644,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// public virtual TagBuilder GenerateTextBox( - [NotNull] ViewContext viewContext, + ViewContext viewContext, ModelExplorer modelExplorer, string expression, object value, string format, object htmlAttributes) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + var htmlAttributeDictionary = GetHtmlAttributeDictionaryOrNull(htmlAttributes); return GenerateInput( viewContext, @@ -569,12 +673,17 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// public virtual TagBuilder GenerateValidationMessage( - [NotNull] ViewContext viewContext, + ViewContext viewContext, string expression, string message, string tag, object htmlAttributes) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + var fullName = GetFullHtmlFieldName(viewContext, expression); if (string.IsNullOrEmpty(fullName)) { @@ -649,12 +758,17 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// public virtual TagBuilder GenerateValidationSummary( - [NotNull] ViewContext viewContext, + ViewContext viewContext, bool excludePropertyErrors, string message, string headerTag, object htmlAttributes) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + var formContext = viewContext.ClientValidationEnabled ? viewContext.FormContext : null; if (viewContext.ViewData.ModelState.IsValid && (formContext == null || excludePropertyErrors)) { @@ -717,7 +831,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures { tagBuilder.AddCssClass(HtmlHelper.ValidationSummaryCssClassName); } - + tagBuilder.InnerHtml.Append(wrappedMessage); tagBuilder.InnerHtml.Append(htmlSummary); @@ -732,10 +846,15 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// public IEnumerable GetClientValidationRules( - [NotNull] ViewContext viewContext, + ViewContext viewContext, ModelExplorer modelExplorer, string expression) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + modelExplorer = modelExplorer ?? ExpressionMetadataProvider.FromStringExpression(expression, viewContext.ViewData, _metadataProvider); var validationContext = new ClientModelValidationContext( @@ -752,11 +871,16 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// public virtual IReadOnlyCollection GetCurrentValues( - [NotNull] ViewContext viewContext, + ViewContext viewContext, ModelExplorer modelExplorer, string expression, bool allowMultiple) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + var fullName = GetFullHtmlFieldName(viewContext, expression); if (string.IsNullOrEmpty(fullName)) { @@ -953,11 +1077,16 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// A instance for the </form> element. /// protected virtual TagBuilder GenerateFormCore( - [NotNull] ViewContext viewContext, + ViewContext viewContext, string action, string method, object htmlAttributes) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + var tagBuilder = new TagBuilder("form"); tagBuilder.MergeAttributes(GetHtmlAttributeDictionaryOrNull(htmlAttributes)); @@ -978,7 +1107,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures } protected virtual TagBuilder GenerateInput( - [NotNull] ViewContext viewContext, + ViewContext viewContext, InputType inputType, ModelExplorer modelExplorer, string expression, @@ -990,6 +1119,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures string format, IDictionary htmlAttributes) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + // Not valid to use TextBoxForModel() and so on in a top-level view; would end up with an unnamed input // elements. But we support the *ForModel() methods in any lower-level template, once HtmlFieldPrefix is // non-empty. @@ -1104,10 +1238,15 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures } protected virtual TagBuilder GenerateLink( - [NotNull] string linkText, - [NotNull] string url, + string linkText, + string url, object htmlAttributes) { + if (linkText == null) + { + throw new ArgumentNullException(nameof(linkText)); + } + var tagBuilder = new TagBuilder("a"); tagBuilder.InnerHtml.SetContent(linkText); @@ -1215,9 +1354,14 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures } private static IEnumerable GetSelectListItems( - [NotNull] ViewContext viewContext, + ViewContext viewContext, string expression) { + if (viewContext == null) + { + throw new ArgumentNullException(nameof(viewContext)); + } + // Method is called only if user did not pass a select list in. They must provide select list items in the // ViewData dictionary and definitely not as the Model. (Even if the Model datatype were correct, a //