From 4f67dee048c99c01c49cff9a672861827105cf46 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 3 Apr 2014 10:54:10 -0700 Subject: [PATCH] Addressed code review comments --- .../Html/HtmlHelper.cs | 24 ++---------- .../Html/HtmlHelperOfT.cs | 16 ++++++++ .../TemplatedHelpers/DisplayForExtensions.cs | 38 +++++++++++-------- .../IHtmlHelperOfT.cs | 21 ++++++---- 4 files changed, 55 insertions(+), 44 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs index f4a266fa98..6f7b403bc5 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs @@ -175,24 +175,6 @@ namespace Microsoft.AspNet.Mvc.Rendering additionalViewData); } - public virtual HtmlString DisplayFor(Expression> expression, - string templateName, - string htmlFieldName, - object additionalViewData) - { - var templateBuilder = new TemplateBuilder(ViewContext, - ViewData, - ExpressionMetadataProvider.FromLambdaExpression(expression, (ViewDataDictionary)ViewData, MetadataProvider), - htmlFieldName ?? ExpressionHelper.GetExpressionText(expression), - templateName, - readOnly: true, - additionalViewData: additionalViewData); - - var templateResult = templateBuilder.Build(); - - return new HtmlString(templateResult); - } - /// public virtual HtmlString Name(string name) { @@ -217,9 +199,9 @@ namespace Microsoft.AspNet.Mvc.Rendering } protected virtual HtmlString GenerateDisplay(ModelMetadata metadata, - string htmlFieldName, - string templateName, - object additionalViewData) + string htmlFieldName, + string templateName, + object additionalViewData) { var templateBuilder = new TemplateBuilder(_viewEngine, ViewContext, diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelperOfT.cs b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelperOfT.cs index c8fa02880e..2642ce52b3 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelperOfT.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelperOfT.cs @@ -41,6 +41,22 @@ namespace Microsoft.AspNet.Mvc.Rendering base.Contextualize(viewContext); } + + public HtmlString DisplayFor([NotNull] Expression> expression, + string templateName, + string htmlFieldName, + object additionalViewData) + { + var metadata = ExpressionMetadataProvider.FromLambdaExpression(expression, + ViewData, + MetadataProvider); + + return GenerateDisplay(metadata, + htmlFieldName ?? ExpressionHelper.GetExpressionText(expression), + templateName, + additionalViewData); + } + /// public HtmlString NameFor([NotNull] Expression> expression) { diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Html/TemplatedHelpers/DisplayForExtensions.cs b/src/Microsoft.AspNet.Mvc.Rendering/Html/TemplatedHelpers/DisplayForExtensions.cs index f300357d25..4b66fc3900 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/Html/TemplatedHelpers/DisplayForExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/Html/TemplatedHelpers/DisplayForExtensions.cs @@ -4,36 +4,42 @@ using System.Linq.Expressions; namespace Microsoft.AspNet.Mvc.Rendering { - public static class DisplayForExtensions + public static class HtmlHelperDisplayForExtensions { - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "This is an appropriate nesting of generic types")] - public static HtmlString DisplayFor(this IHtmlHelper html, Expression> expression) + public static HtmlString DisplayFor([NotNull] this IHtmlHelper html, + [NotNull] Expression> expression) { - return html.DisplayFor(expression, templateName: null, htmlFieldName: null, additionalViewData: null); + return html.DisplayFor(expression, templateName: null, htmlFieldName: null, additionalViewData: null); } - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "This is an appropriate nesting of generic types")] - public static HtmlString DisplayFor(this IHtmlHelper html, Expression> expression, object additionalViewData) + public static HtmlString DisplayFor([NotNull] this IHtmlHelper html, + [NotNull] Expression> expression, + object additionalViewData) { - return html.DisplayFor(expression, templateName: null, htmlFieldName: null, additionalViewData: additionalViewData); + return html.DisplayFor(expression, templateName: null, htmlFieldName: null, additionalViewData: additionalViewData); } - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "This is an appropriate nesting of generic types")] - public static HtmlString DisplayFor(this IHtmlHelper html, Expression> expression, string templateName) + public static HtmlString DisplayFor([NotNull] this IHtmlHelper html, + [NotNull] Expression> expression, + string templateName) { - return html.DisplayFor(expression, templateName, htmlFieldName: null, additionalViewData: null); + return html.DisplayFor(expression, templateName, htmlFieldName: null, additionalViewData: null); } - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "This is an appropriate nesting of generic types")] - public static HtmlString DisplayFor(this IHtmlHelper html, Expression> expression, string templateName, object additionalViewData) + public static HtmlString DisplayFor([NotNull] this IHtmlHelper html, + [NotNull] Expression> expression, + string templateName, + object additionalViewData) { - return html.DisplayFor(expression, templateName, htmlFieldName: null, additionalViewData: additionalViewData); + return html.DisplayFor(expression, templateName, htmlFieldName: null, additionalViewData: additionalViewData); } - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "This is an appropriate nesting of generic types")] - public static HtmlString DisplayFor(this IHtmlHelper html, Expression> expression, string templateName, string htmlFieldName) + public static HtmlString DisplayFor([NotNull] this IHtmlHelper html, + [NotNull] Expression> expression, + string templateName, + string htmlFieldName) { - return html.DisplayFor(expression, templateName: templateName, htmlFieldName: htmlFieldName, additionalViewData: null); + return html.DisplayFor(expression, templateName: templateName, htmlFieldName: htmlFieldName, additionalViewData: null); } } } diff --git a/src/Microsoft.AspNet.Mvc.Rendering/IHtmlHelperOfT.cs b/src/Microsoft.AspNet.Mvc.Rendering/IHtmlHelperOfT.cs index 7431c353e8..1551a06dfc 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/IHtmlHelperOfT.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/IHtmlHelperOfT.cs @@ -52,19 +52,26 @@ namespace Microsoft.AspNet.Mvc.Rendering object additionalViewData); /// - /// Returns HTML markup for each property in the object that is represented by the specified expression, using the template, an HTML field ID, and additional view data. + /// Returns HTML markup for each property in the object that is represented by the specified expression, using the + /// template, an HTML field ID, and additional view data. /// /// The type of the model. /// The type of the value. /// An expression that identifies the object that contains the properties to display. /// The name of the template that is used to render the object. - /// A string that is used to disambiguate the names of HTML input elements that are rendered for properties that have the same name. - /// An anonymous object that can contain additional view data that will be merged into the instance that is created for the template. + /// + /// A string that is used to disambiguate the names of HTML input elements that are rendered for properties that have + /// the same name. + /// + /// + /// An anonymous object or dictionary that can contain additional view data that will be merged into the + /// instance that is created for the template. + /// /// The HTML markup for each property in the object that is represented by the expression. - HtmlString DisplayFor(Expression> expression, - string templateName, - string htmlFieldName, - object additionalViewData); + HtmlString DisplayFor(Expression> expression, + string templateName, + string htmlFieldName, + object additionalViewData); /// /// Converts the value of the specified object to an HTML-encoded string.