Skip to content

Commit 7a97b13

Browse files
committed
Cleanup pass in Rendering (and Common)
- correct `ArgumentNullOrEmpty` and pass parameter name to `ArgumentException` constructor - remove `[SuppressMessage]` attributes - `AnonymousObjectToHtmlAttributes` should return an `IDictionary` - `var` - remove straggling copyright notices - wrap long lines (did not reword any comments) - align a few parameters
1 parent dad87c5 commit 7a97b13

16 files changed

+72
-69
lines changed

src/Common/TypeExtensions.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2-
3-
using System;
1+
using System;
42
using System.Linq;
53
using System.Reflection;
64

@@ -94,7 +92,7 @@ public static bool AllowsNullValue([NotNull] this Type type)
9492

9593
public static bool HasStringConverter([NotNull] this Type type)
9694
{
97-
TypeInfo typeInfo = type.GetTypeInfo();
95+
var typeInfo = type.GetTypeInfo();
9896
if (typeInfo.IsPrimitive || type == typeof(string))
9997
{
10098
return true;
@@ -110,13 +108,13 @@ public static bool HasStringConverter([NotNull] this Type type)
110108

111109
public static Type[] GetTypeArgumentsIfMatch([NotNull] Type closedType, Type matchingOpenType)
112110
{
113-
TypeInfo closedTypeInfo = closedType.GetTypeInfo();
111+
var closedTypeInfo = closedType.GetTypeInfo();
114112
if (!closedTypeInfo.IsGenericType)
115113
{
116114
return null;
117115
}
118116

119-
Type openType = closedType.GetGenericTypeDefinition();
117+
var openType = closedType.GetGenericTypeDefinition();
120118
return (matchingOpenType == openType) ? closedTypeInfo.GenericTypeArguments : null;
121119
}
122120
}

src/Microsoft.AspNet.Mvc.Rendering/Expressions/ExpressionHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private static string GetIndexerInvocation([NotNull] Expression expression,
103103
{
104104
throw new InvalidOperationException(
105105
Resources.FormatExpressionHelper_InvalidIndexerExpression(expression, parameters[0].Name),
106-
ex);
106+
ex);
107107
}
108108

109109
return "[" + Convert.ToString(func(null), CultureInfo.InvariantCulture) + "]";

src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics.CodeAnalysis;
43
using System.Globalization;
54
using System.IO;
65
using System.Net;
@@ -77,7 +76,7 @@ public ViewDataDictionary ViewData
7776
}
7877

7978
/// <summary>
80-
/// Creates a dictionary of HTML attributes from the input object,
79+
/// Creates a dictionary of HTML attributes from the input object,
8180
/// translating underscores to dashes.
8281
/// <example>
8382
/// new { data_name="value" } will translate to the entry { "data-name" , "value" }
@@ -86,10 +85,10 @@ public ViewDataDictionary ViewData
8685
/// </summary>
8786
/// <param name="htmlAttributes">Anonymous object describing HTML attributes.</param>
8887
/// <returns>A dictionary that represents HTML attributes.</returns>
89-
public static Dictionary<string, object> AnonymousObjectToHtmlAttributes(object htmlAttributes)
88+
public static IDictionary<string, object> AnonymousObjectToHtmlAttributes(object htmlAttributes)
9089
{
9190
Dictionary<string, object> result;
92-
IDictionary<string, object> valuesAsDictionary = htmlAttributes as IDictionary<string, object>;
91+
var valuesAsDictionary = htmlAttributes as IDictionary<string, object>;
9392
if (valuesAsDictionary != null)
9493
{
9594
result = new Dictionary<string, object>(valuesAsDictionary, StringComparer.OrdinalIgnoreCase);
@@ -102,8 +101,8 @@ public static Dictionary<string, object> AnonymousObjectToHtmlAttributes(object
102101
{
103102
foreach (var prop in htmlAttributes.GetType().GetRuntimeProperties())
104103
{
105-
object val = prop.GetValue(htmlAttributes);
106-
result.Add(prop.Name, val);
104+
var value = prop.GetValue(htmlAttributes);
105+
result.Add(prop.Name, value);
107106
}
108107
}
109108
}
@@ -116,13 +115,11 @@ public virtual void Contextualize([NotNull] ViewContext viewContext)
116115
ViewContext = viewContext;
117116
}
118117

119-
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "For consistency, all helpers are instance methods.")]
120118
public string Encode(string value)
121119
{
122120
return (!string.IsNullOrEmpty(value)) ? WebUtility.HtmlEncode(value) : string.Empty;
123121
}
124122

125-
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "For consistency, all helpers are instance methods.")]
126123
public string Encode(object value)
127124
{
128125
return value != null ? WebUtility.HtmlEncode(value.ToString()) : string.Empty;
@@ -134,15 +131,14 @@ public string GenerateIdFromName([NotNull] string name)
134131
}
135132

136133
/// <inheritdoc />
137-
[SuppressMessage("Microsoft.Naming", "CA1719:ParameterNamesShouldNotMatchMemberNames",
138-
MessageId = "1#", Justification = "This is a shipped API.")]
139134
public virtual HtmlString Name(string name)
140135
{
141136
var fullName = ViewData.TemplateInfo.GetFullHtmlFieldName(name);
142137
return new HtmlString(Encode(fullName));
143138
}
144139

145-
public async Task<HtmlString> PartialAsync([NotNull] string partialViewName, object model, ViewDataDictionary viewData)
140+
public async Task<HtmlString> PartialAsync([NotNull] string partialViewName, object model,
141+
ViewDataDictionary viewData)
146142
{
147143
using (var writer = new StringWriter(CultureInfo.CurrentCulture))
148144
{
@@ -157,10 +153,10 @@ public Task RenderPartialAsync([NotNull] string partialViewName, object model, V
157153
return RenderPartialCoreAsync(partialViewName, model, viewData, ViewContext.Writer);
158154
}
159155

160-
protected virtual async Task RenderPartialCoreAsync([NotNull] string partialViewName,
161-
object model,
162-
ViewDataDictionary viewData,
163-
TextWriter writer)
156+
protected virtual async Task RenderPartialCoreAsync([NotNull] string partialViewName,
157+
object model,
158+
ViewDataDictionary viewData,
159+
TextWriter writer)
164160
{
165161
// Determine which ViewData we should use to construct a new ViewData
166162
var baseViewData = viewData ?? ViewData;
@@ -306,13 +302,11 @@ public static string GetInputTypeString(InputType inputType)
306302
}
307303
}
308304

309-
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "For consistency, all helpers are instance methods.")]
310305
public HtmlString Raw(string value)
311306
{
312307
return new HtmlString(value);
313308
}
314309

315-
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "For consistency, all helpers are instance methods.")]
316310
public HtmlString Raw(object value)
317311
{
318312
return new HtmlString(value == null ? null : value.ToString());

src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelperOfT.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Diagnostics.CodeAnalysis;
32
using System.Linq.Expressions;
43
using Microsoft.AspNet.Mvc.Rendering.Expressions;
54

@@ -40,10 +39,6 @@ public override void Contextualize([NotNull] ViewContext viewContext)
4039
}
4140

4241
/// <inheritdoc />
43-
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures",
44-
Justification = "This is an appropriate nesting of generic types")]
45-
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters",
46-
Justification = "Users cannot use anonymous methods with the LambdaExpression type")]
4742
public HtmlString NameFor<TProperty>([NotNull] Expression<Func<TModel, TProperty>> expression)
4843
{
4944
var expressionName = GetExpressionName(expression);

src/Microsoft.AspNet.Mvc.Rendering/Html/Partials/PartialAsyncExtensions.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ public static class PartialAsyncExtensions
1010
/// <typeparam name="T">The <see cref="Type"/> of the model.</typeparam>
1111
/// <param name="htmlHelper">The <see cref="HtmlHelper"/> instance that this method extends.</param>
1212
/// <param name="partialViewName">The name of the partial view to render.</param>
13-
/// <returns>A <see cref="Task{T}"/> that represents when rendering to the <see cref="HtmlString"/> has completed.</returns>
13+
/// <returns>
14+
/// A <see cref="Task{T}"/> that represents when rendering to the <see cref="HtmlString"/> has completed.
15+
/// </returns>
1416
public static Task<HtmlString> PartialAsync<T>(this IHtmlHelper<T> htmlHelper, [NotNull] string partialViewName)
1517
{
1618
return htmlHelper.PartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: null);
@@ -22,9 +24,14 @@ public static Task<HtmlString> PartialAsync<T>(this IHtmlHelper<T> htmlHelper, [
2224
/// <typeparam name="T">The <see cref="Type"/> of the model.</typeparam>
2325
/// <param name="htmlHelper">The <see cref="HtmlHelper"/> instance that this method extends.</param>
2426
/// <param name="partialViewName">The name of the partial view to render.</param>
25-
/// <param name="viewData">The <see cref="ViewDataDictionary"/> that is provided to the partial view that will be rendered.</param>
26-
/// <returns>A <see cref="Task{T}"/> that represents when rendering to the <see cref="HtmlString"/> has completed.</returns>
27-
public static Task<HtmlString> PartialAsync<T>(this IHtmlHelper<T> htmlHelper, [NotNull] string partialViewName, ViewDataDictionary viewData)
27+
/// <param name="viewData">
28+
/// The <see cref="ViewDataDictionary"/> that is provided to the partial view that will be rendered.
29+
/// </param>
30+
/// <returns>
31+
/// A <see cref="Task{T}"/> that represents when rendering to the <see cref="HtmlString"/> has completed.
32+
/// </returns>
33+
public static Task<HtmlString> PartialAsync<T>(this IHtmlHelper<T> htmlHelper, [NotNull] string partialViewName,
34+
ViewDataDictionary viewData)
2835
{
2936
return htmlHelper.PartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: viewData);
3037
}
@@ -36,8 +43,11 @@ public static Task<HtmlString> PartialAsync<T>(this IHtmlHelper<T> htmlHelper, [
3643
/// <param name="htmlHelper">The <see cref="HtmlHelper"/> instance that this method extends.</param>
3744
/// <param name="partialViewName">The name of the partial view to render.</param>
3845
/// <param name="model">The model to provide to the partial view that will be rendered.</param>
39-
/// <returns>A <see cref="Task{T}"/> that represents when rendering to the <see cref="HtmlString"/> has completed.</returns>
40-
public static Task<HtmlString> PartialAsync<T>(this IHtmlHelper<T> htmlHelper, [NotNull] string partialViewName, object model)
46+
/// <returns>
47+
/// A <see cref="Task{T}"/> that represents when rendering to the <see cref="HtmlString"/> has completed.
48+
/// </returns>
49+
public static Task<HtmlString> PartialAsync<T>(this IHtmlHelper<T> htmlHelper, [NotNull] string partialViewName,
50+
object model)
4151
{
4252
return htmlHelper.PartialAsync(partialViewName, model, viewData: null);
4353
}

src/Microsoft.AspNet.Mvc.Rendering/Html/Partials/RenderPartialAsyncExtensions.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public static class RenderPartialAsyncExtensions
1414
/// <returns>A <see cref="Task"/> that represents when rendering has completed.</returns>
1515
public static Task RenderPartialAsync<T>(this IHtmlHelper<T> htmlHelper, [NotNull] string partialViewName)
1616
{
17-
return htmlHelper.RenderPartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: htmlHelper.ViewData);
17+
return htmlHelper.RenderPartialAsync(partialViewName, htmlHelper.ViewData.Model,
18+
viewData: htmlHelper.ViewData);
1819
}
1920

2021
/// <summary>
@@ -23,9 +24,12 @@ public static Task RenderPartialAsync<T>(this IHtmlHelper<T> htmlHelper, [NotNul
2324
/// <typeparam name="T">The <see cref="Type"/> of the model.</typeparam>
2425
/// <param name="htmlHelper">The <see cref="HtmlHelper"/> instance that this method extends.</param>
2526
/// <param name="partialViewName">The name of the partial view to render.</param>
26-
/// <param name="viewData">The <see cref="ViewDataDictionary"/> that is provided to the partial view that will be rendered.</param>
27+
/// <param name="viewData">
28+
/// The <see cref="ViewDataDictionary"/> that is provided to the partial view that will be rendered.
29+
/// </param>
2730
/// <returns>A <see cref="Task"/> that represents when rendering has completed.</returns>
28-
public static Task RenderPartialAsync<T>(this IHtmlHelper<T> htmlHelper, [NotNull] string partialViewName, ViewDataDictionary viewData)
31+
public static Task RenderPartialAsync<T>(this IHtmlHelper<T> htmlHelper, [NotNull] string partialViewName,
32+
ViewDataDictionary viewData)
2933
{
3034
return htmlHelper.RenderPartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: viewData);
3135
}
@@ -38,7 +42,8 @@ public static Task RenderPartialAsync<T>(this IHtmlHelper<T> htmlHelper, [NotNul
3842
/// <param name="partialViewName">The name of the partial view to render.</param>
3943
/// <param name="model">The model to provide to the partial view that will be rendered.</param>
4044
/// <returns>A <see cref="Task"/> that represents when rendering has completed.</returns>
41-
public static Task RenderPartialAsync<T>(this IHtmlHelper<T> htmlHelper, [NotNull] string partialViewName, object model)
45+
public static Task RenderPartialAsync<T>(this IHtmlHelper<T> htmlHelper, [NotNull] string partialViewName,
46+
object model)
4247
{
4348
return htmlHelper.RenderPartialAsync(partialViewName, model, htmlHelper.ViewData);
4449
}

src/Microsoft.AspNet.Mvc.Rendering/Html/TagBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public TagBuilder(string tagName)
1414
{
1515
if (string.IsNullOrEmpty(tagName))
1616
{
17-
throw new ArgumentException(Resources.FormatArgumentNullOrEmpty("tagName"));
17+
throw new ArgumentException(Resources.ArgumentNullOrEmpty, "tagName");
1818
}
1919

2020
TagName = tagName;
@@ -113,7 +113,7 @@ public void MergeAttribute(string key, string value, bool replaceExisting)
113113
{
114114
if (string.IsNullOrEmpty(key))
115115
{
116-
throw new ArgumentException(Resources.FormatArgumentNullOrEmpty("key"));
116+
throw new ArgumentException(Resources.ArgumentNullOrEmpty, "key");
117117
}
118118

119119
if (replaceExisting || !Attributes.ContainsKey(key))

src/Microsoft.AspNet.Mvc.Rendering/Properties/AssemblyInfo.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2-
3-
using System.Reflection;
1+
using System.Reflection;
42
using System.Runtime.InteropServices;
53

6-
// General Information about an assembly is controlled through the following
4+
// General Information about an assembly is controlled through the following
75
// set of attributes. Change these attribute values to modify the information
86
// associated with an assembly.
97
[assembly: AssemblyTitle("Microsoft.AspNet.Mvc.Rendering")]
@@ -15,8 +13,8 @@
1513
[assembly: AssemblyTrademark("")]
1614
[assembly: AssemblyCulture("")]
1715

18-
// Setting ComVisible to false makes the types in this assembly not visible
19-
// to COM components. If you need to access a type in this assembly from
16+
// Setting ComVisible to false makes the types in this assembly not visible
17+
// to COM components. If you need to access a type in this assembly from
2018
// COM, set the ComVisible attribute to true on that type.
2119
[assembly: ComVisible(false)]
2220

@@ -26,11 +24,11 @@
2624
// Version information for an assembly consists of the following four values:
2725
//
2826
// Major Version
29-
// Minor Version
27+
// Minor Version
3028
// Build Number
3129
// Revision
3230
//
33-
// You can specify all the values or you can default the Build and Revision Numbers
31+
// You can specify all the values or you can default the Build and Revision Numbers
3432
// by using the '*' as shown below:
3533
// [assembly: AssemblyVersion("1.0.*")]
3634
[assembly: AssemblyVersion("1.0.0.0")]

src/Microsoft.AspNet.Mvc.Rendering/Properties/Resources.Designer.cs

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Microsoft.AspNet.Mvc.Rendering/Properties/Resources.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120120
<data name="ArgumentNullOrEmpty" xml:space="preserve">
121-
<value>The argument '{0}' is null or empty.</value>
121+
<value>The argument must not be null or empty.</value>
122122
</data>
123123
<data name="ArgumentPropertyNull" xml:space="preserve">
124124
<value>Property '{0}' must not be null.</value>

0 commit comments

Comments
 (0)