Cleanup pass: Move Rendering classes to correct namespace

- use Microsoft.AspNet.Mvc.Rendering namespace throughout assembly

Also
- move `IdAttributeDotReplacement` from `TagBuilder` to `HtmlHelper`
- remove commented-out code in `HtmlHelper`
- use `var` and `[NotNull]` more
- `String` -> `string`
- correct Resources references; add missing resources
This commit is contained in:
dougbu 2014-03-18 11:10:49 -07:00
parent 478c220ddb
commit 3a0add8be8
33 changed files with 120 additions and 267 deletions

View File

@ -1,5 +1,6 @@
 
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Rendering;
namespace MvcSample.Web namespace MvcSample.Web
{ {

View File

@ -1,5 +1,5 @@
using System; using System;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.Rendering;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {

View File

@ -3,7 +3,7 @@ using System.Globalization;
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.Rendering;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {

View File

@ -1,4 +1,5 @@
using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.Mvc.Rendering;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {

View File

@ -4,7 +4,7 @@ using System.Reflection;
using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Mvc.Rendering;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {

View File

@ -1,4 +1,4 @@
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.Rendering;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {

View File

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc

View File

@ -14,7 +14,8 @@ namespace Microsoft.AspNet.Mvc.Razor
"System.Linq", "System.Linq",
"System.Collections.Generic", "System.Collections.Generic",
"Microsoft.AspNet.Mvc", "Microsoft.AspNet.Mvc",
"Microsoft.AspNet.Mvc.Razor" "Microsoft.AspNet.Mvc.Razor",
"Microsoft.AspNet.Mvc.Rendering"
}; };
// CodeGenerationContext.DefaultBaseClass is set to MyBaseType<dynamic>. // CodeGenerationContext.DefaultBaseClass is set to MyBaseType<dynamic>.

View File

@ -3,8 +3,8 @@ using System.IO;
using System.Net; using System.Net;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection;
using Microsoft.AspNet.Mvc.Rendering;
namespace Microsoft.AspNet.Mvc.Razor namespace Microsoft.AspNet.Mvc.Razor
{ {
@ -133,7 +133,7 @@ namespace Microsoft.AspNet.Mvc.Razor
// value might be a bool. If the value is the bool 'true' we want to write the attribute name instead // value might be a bool. If the value is the bool 'true' we want to write the attribute name instead
// of the string 'true'. If the value is the bool 'false' we don't want to write anything. // of the string 'true'. If the value is the bool 'false' we don't want to write anything.
// //
// Otherwise the value is another object (perhaps an IHtmlString), and we'll ask it to format itself. // Otherwise the value is another object (perhaps an HtmlString), and we'll ask it to format itself.
string stringValue; string stringValue;
bool? boolValue = val.Value as bool?; bool? boolValue = val.Value as bool?;
if (boolValue == true) if (boolValue == true)

View File

@ -1,5 +1,6 @@
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Rendering;
namespace Microsoft.AspNet.Mvc.Razor namespace Microsoft.AspNet.Mvc.Razor
{ {

View File

@ -1,5 +1,6 @@
 
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Rendering;
namespace Microsoft.AspNet.Mvc.Razor namespace Microsoft.AspNet.Mvc.Razor
{ {

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Rendering;
namespace Microsoft.AspNet.Mvc.Razor namespace Microsoft.AspNet.Mvc.Razor
{ {

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.FileSystems; using Microsoft.AspNet.FileSystems;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.Net.Runtime; using Microsoft.Net.Runtime;
namespace Microsoft.AspNet.Mvc.Razor namespace Microsoft.AspNet.Mvc.Razor

View File

@ -1,5 +1,4 @@
 namespace Microsoft.AspNet.Mvc.Rendering
namespace Microsoft.AspNet.Mvc
{ {
public enum FormMethod public enum FormMethod
{ {

View File

@ -1,15 +1,12 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Net; using System.Net;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.Abstractions;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.Rendering
{ {
public class HtmlHelper public class HtmlHelper
{ {
@ -24,10 +21,12 @@ namespace Microsoft.AspNet.Mvc
{ {
HttpContext = httpContext; HttpContext = httpContext;
ViewData = viewData; ViewData = viewData;
// ClientValidationRuleFactory = (name, metadata) => ModelValidatorProviders.Providers.GetValidators(metadata ?? ModelMetadata.FromStringExpression(name, ViewData), ViewContext).SelectMany(v => v.GetClientValidationRules());
// Underscores are fine characters in id's.
IdAttributeDotReplacement = "_";
} }
//internal Func<string, ModelMetadata, IEnumerable<ModelClientValidationRule>> ClientValidationRuleFactory { get; set; } public string IdAttributeDotReplacement { get; set; }
public HttpContext HttpContext { get; private set; } public HttpContext HttpContext { get; private set; }
@ -72,62 +71,20 @@ namespace Microsoft.AspNet.Mvc
return result; return result;
} }
//[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "For consistency, all helpers are instance methods.")]
//public HtmlString AntiForgeryToken()
//{
// return new HtmlString(AntiForgery.GetHtml().ToString());
//}
///// <summary>
///// Set this property to <see cref="Mvc.Html5DateRenderingMode.Rfc3339"/> to have templated helpers such as Html.EditorFor render date and time
///// values as Rfc3339 compliant strings.
///// </summary>
///// <remarks>
///// The scope of this setting is for the current view alone. Sub views and parent views
///// will default to <see cref="Mvc.Html5DateRenderingMode.CurrentCulture"/> unless explicitly set otherwise.
///// </remarks>
//[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "The usage of the property is as an instance property of the helper.")]
//public Html5DateRenderingMode Html5DateRenderingMode
//{
// get
// {
// object value;
// if (ScopeStorage.CurrentScope.TryGetValue(_html5InputsModeKey, out value))
// {
// return (Html5DateRenderingMode)value;
// }
// return default(Html5DateRenderingMode);
// }
// set
// {
// ScopeStorage.CurrentScope[_html5InputsModeKey] = value;
// }
//}
//[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "For consistency, all helpers are instance methods.")]
//public string AttributeEncode(string value)
//{
// return (!String.IsNullOrEmpty(value)) ? HttpUtility.HtmlAttributeEncode(value) : String.Empty;
//}
//public string AttributeEncode(object value)
//{
// return AttributeEncode(Convert.ToString(value, CultureInfo.InvariantCulture));
//}
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "For consistency, all helpers are instance methods.")] [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "For consistency, all helpers are instance methods.")]
public string Encode(string value) public string Encode(string value)
{ {
return (!String.IsNullOrEmpty(value)) ? WebUtility.HtmlEncode(value) : String.Empty; return (!string.IsNullOrEmpty(value)) ? WebUtility.HtmlEncode(value) : string.Empty;
} }
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "For consistency, all helpers are instance methods.")] [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "For consistency, all helpers are instance methods.")]
public string Encode(object value) public string Encode(object value)
{ {
return value != null ? WebUtility.HtmlEncode(value.ToString()) : String.Empty; return value != null ? WebUtility.HtmlEncode(value.ToString()) : string.Empty;
} }
internal static IView FindPartialView(ViewContext viewContext, string partialViewName, IViewEngine viewEngine) internal static IView FindPartialView([NotNull] ViewContext viewContext, string partialViewName,
[NotNull] IViewEngine viewEngine)
{ {
ViewEngineResult result = viewEngine.FindView(viewContext, partialViewName).Result; ViewEngineResult result = viewEngine.FindView(viewContext, partialViewName).Result;
if (result.View != null) if (result.View != null)
@ -142,18 +99,13 @@ namespace Microsoft.AspNet.Mvc
locationsText.Append(location); locationsText.Append(location);
} }
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, throw new InvalidOperationException(Resources.FormatCommon_PartialViewNotFound(partialViewName,
"MvcResources.Common_PartialViewNotFound", partialViewName, locationsText)); locationsText));
} }
public static string GenerateIdFromName(string name) public string GenerateIdFromName([NotNull] string name)
{ {
if (name == null) return TagBuilder.CreateSanitizedId(name, IdAttributeDotReplacement);
{
throw new ArgumentNullException("name");
}
return TagBuilder.CreateSanitizedId(name);
} }
public static string GetFormMethodString(FormMethod method) public static string GetFormMethodString(FormMethod method)
@ -188,57 +140,6 @@ namespace Microsoft.AspNet.Mvc
} }
} }
//internal object GetModelStateValue(string key, Type destinationType)
//{
// ModelState modelState;
// if (ViewData.ModelState.TryGetValue(key, out modelState))
// {
// if (modelState.Value != null)
// {
// return modelState.Value.ConvertTo(destinationType, null /* culture */);
// }
// }
// return null;
//}
//public IDictionary<string, object> GetUnobtrusiveValidationAttributes(string name)
//{
// return GetUnobtrusiveValidationAttributes(name, metadata: null);
//}
//// Only render attributes if unobtrusive client-side validation is enabled, and then only if we've
//// never rendered validation for a field with this name in this form. Also, if there's no form context,
//// then we can't render the attributes (we'd have no <form> to attach them to).
//public IDictionary<string, object> GetUnobtrusiveValidationAttributes(string name, ModelMetadata metadata)
//{
// Dictionary<string, object> results = new Dictionary<string, object>();
// // The ordering of these 3 checks (and the early exits) is for performance reasons.
// if (!ViewContext.UnobtrusiveJavaScriptEnabled)
// {
// return results;
// }
// FormContext formContext = ViewContext.GetFormContextForClientValidation();
// if (formContext == null)
// {
// return results;
// }
// string fullName = ViewData.TemplateInfo.GetFullHtmlFieldName(name);
// if (formContext.RenderedField(fullName))
// {
// return results;
// }
// formContext.RenderedField(fullName, true);
// IEnumerable<ModelClientValidationRule> clientRules = ClientValidationRuleFactory(name, metadata);
// UnobtrusiveValidationAttributesGenerator.GetValidationAttributes(clientRules, results);
// return results;
//}
/// <summary> /// <summary>
/// Wraps HTML markup in an IHtmlString, which will enable HTML markup to be /// Wraps HTML markup in an IHtmlString, which will enable HTML markup to be
/// rendered to the output without getting HTML encoded. /// rendered to the output without getting HTML encoded.
@ -262,42 +163,5 @@ namespace Microsoft.AspNet.Mvc
{ {
return new HtmlString(value == null ? null : value.ToString()); return new HtmlString(value == null ? null : value.ToString());
} }
//internal virtual void RenderPartialInternal<TModel>(string partialViewName, ViewData viewData, TModel model, TextWriter writer, IViewEngine viewEngine)
//{
// if (String.IsNullOrEmpty(partialViewName))
// {
// throw new ArgumentException("MvcResources.Common_NullOrEmpty", "partialViewName");
// }
// ViewData<TModel> newViewData = null;
// if (model == null)
// {
// if (viewData == null)
// {
// newViewData = new ViewData<TModel>(ViewContext.ViewData);
// }
// else
// {
// newViewData = new ViewData<TModel>(viewData);
// }
// }
// else
// {
// if (viewData == null)
// {
// newViewData = new ViewData(model);
// }
// else
// {
// newViewData = new ViewData(viewData) { Model = model };
// }
// }
// ViewContext newViewContext = new ViewContext(ViewContext, ViewContext.View, newViewData, ViewContext.TempData, writer);
// IView view = FindPartialView(newViewContext, partialViewName, viewEngine);
// view.Render(newViewContext, writer);
//}
} }
} }

View File

@ -1,6 +1,6 @@
using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.Abstractions;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.Rendering
{ {
public class HtmlHelper<TModel> : HtmlHelper public class HtmlHelper<TModel> : HtmlHelper
{ {

View File

@ -1,5 +1,4 @@
 namespace Microsoft.AspNet.Mvc.Rendering
namespace Microsoft.AspNet.Mvc
{ {
public class HtmlString public class HtmlString
{ {

View File

@ -1,9 +1,4 @@
using System; namespace Microsoft.AspNet.Mvc.Rendering
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Microsoft.AspNet.Mvc
{ {
public enum InputType public enum InputType
{ {

View File

@ -1,24 +1,20 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Net; using System.Net;
using System.Text; using System.Text;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.Rendering
{ {
public class TagBuilder public class TagBuilder
{ {
private string _idAttributeDotReplacement;
private string _innerHtml; private string _innerHtml;
public TagBuilder(string tagName) public TagBuilder(string tagName)
{ {
if (String.IsNullOrEmpty(tagName)) if (string.IsNullOrEmpty(tagName))
{ {
throw new ArgumentException("CommonResources.Argument_Cannot_Be_Null_Or_Empty", "tagName"); throw new ArgumentException(Resources.FormatArgumentNullOrEmpty("tagName"));
} }
TagName = tagName; TagName = tagName;
@ -29,7 +25,7 @@ namespace Microsoft.AspNet.Mvc
public string InnerHtml public string InnerHtml
{ {
get { return _innerHtml ?? String.Empty; } get { return _innerHtml ?? string.Empty; }
set { _innerHtml = value; } set { _innerHtml = value; }
} }
@ -49,32 +45,22 @@ namespace Microsoft.AspNet.Mvc
} }
} }
public static string CreateSanitizedId(string originalId) public static string CreateSanitizedId(string originalId, [NotNull] string invalidCharReplacement)
{ {
return CreateSanitizedId(originalId, "." /*HtmlHelper.IdAttributeDotReplacement*/); if (string.IsNullOrEmpty(originalId))
}
public static string CreateSanitizedId(string originalId, string invalidCharReplacement)
{
if (String.IsNullOrEmpty(originalId))
{ {
return null; return string.Empty;
} }
if (invalidCharReplacement == null) var firstChar = originalId[0];
{
throw new ArgumentNullException("invalidCharReplacement");
}
char firstChar = originalId[0]; var sb = new StringBuilder(originalId.Length);
StringBuilder sb = new StringBuilder(originalId.Length);
sb.Append(firstChar); sb.Append(firstChar);
for (int i = 1; i < originalId.Length; i++) for (var i = 1; i < originalId.Length; i++)
{ {
char thisChar = originalId[i]; var thisChar = originalId[i];
if (!Char.IsWhiteSpace(thisChar)) if (!char.IsWhiteSpace(thisChar))
{ {
sb.Append(thisChar); sb.Append(thisChar);
} }
@ -87,12 +73,12 @@ namespace Microsoft.AspNet.Mvc
return sb.ToString(); return sb.ToString();
} }
public void GenerateId(string name) public void GenerateId(string name, [NotNull] string idAttributeDotReplacement)
{ {
if (!Attributes.ContainsKey("id")) if (!Attributes.ContainsKey("id"))
{ {
string sanitizedId = name; // CreateSanitizedId(name, IdAttributeDotReplacement); var sanitizedId = CreateSanitizedId(name, idAttributeDotReplacement);
if (!String.IsNullOrEmpty(sanitizedId)) if (!string.IsNullOrEmpty(sanitizedId))
{ {
Attributes["id"] = sanitizedId; Attributes["id"] = sanitizedId;
} }
@ -103,13 +89,13 @@ namespace Microsoft.AspNet.Mvc
{ {
foreach (var attribute in Attributes) foreach (var attribute in Attributes)
{ {
string key = attribute.Key; var key = attribute.Key;
if (String.Equals(key, "id", StringComparison.Ordinal) && String.IsNullOrEmpty(attribute.Value)) if (string.Equals(key, "id", StringComparison.Ordinal) && string.IsNullOrEmpty(attribute.Value))
{ {
continue; continue;
} }
//string value = HttpUtility.HtmlAttributeEncode(attribute.Value);
string value = WebUtility.HtmlEncode(attribute.Value); var value = WebUtility.HtmlEncode(attribute.Value);
sb.Append(' ') sb.Append(' ')
.Append(key) .Append(key)
.Append("=\"") .Append("=\"")
@ -125,9 +111,9 @@ namespace Microsoft.AspNet.Mvc
public void MergeAttribute(string key, string value, bool replaceExisting) public void MergeAttribute(string key, string value, bool replaceExisting)
{ {
if (String.IsNullOrEmpty(key)) if (string.IsNullOrEmpty(key))
{ {
throw new ArgumentException("CommonResources.Argument_Cannot_Be_Null_Or_Empty", "key"); throw new ArgumentException(Resources.FormatArgumentNullOrEmpty("key"));
} }
if (replaceExisting || !Attributes.ContainsKey(key)) if (replaceExisting || !Attributes.ContainsKey(key))
@ -147,8 +133,8 @@ namespace Microsoft.AspNet.Mvc
{ {
foreach (var entry in attributes) foreach (var entry in attributes)
{ {
string key = Convert.ToString(entry.Key, CultureInfo.InvariantCulture); var key = Convert.ToString(entry.Key, CultureInfo.InvariantCulture);
string value = Convert.ToString(entry.Value, CultureInfo.InvariantCulture); var value = Convert.ToString(entry.Value, CultureInfo.InvariantCulture);
MergeAttribute(key, value, replaceExisting); MergeAttribute(key, value, replaceExisting);
} }
} }
@ -159,7 +145,7 @@ namespace Microsoft.AspNet.Mvc
InnerHtml = WebUtility.HtmlEncode(innerText); InnerHtml = WebUtility.HtmlEncode(innerText);
} }
internal HtmlString ToHtmlString(TagRenderMode renderMode) public HtmlString ToHtmlString(TagRenderMode renderMode)
{ {
return new HtmlString(ToString(renderMode)); return new HtmlString(ToString(renderMode));
} }
@ -171,7 +157,7 @@ namespace Microsoft.AspNet.Mvc
public string ToString(TagRenderMode renderMode) public string ToString(TagRenderMode renderMode)
{ {
StringBuilder sb = new StringBuilder(); var sb = new StringBuilder();
switch (renderMode) switch (renderMode)
{ {
case TagRenderMode.StartTag: case TagRenderMode.StartTag:
@ -202,6 +188,7 @@ namespace Microsoft.AspNet.Mvc
.Append('>'); .Append('>');
break; break;
} }
return sb.ToString(); return sb.ToString();
} }
} }

View File

@ -1,8 +1,4 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. namespace Microsoft.AspNet.Mvc.Rendering
using System.Runtime.CompilerServices;
namespace Microsoft.AspNet.Mvc
{ {
public enum TagRenderMode public enum TagRenderMode
{ {

View File

@ -1,5 +1,4 @@
 namespace Microsoft.AspNet.Mvc.Rendering
namespace Microsoft.AspNet.Mvc
{ {
public interface IUrlHelper public interface IUrlHelper
{ {

View File

@ -1,15 +1,16 @@
using System.Reflection; // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System.Runtime.CompilerServices;
using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("Microsoft.AspNet.Mvc.Helpers")] [assembly: AssemblyTitle("Microsoft.AspNet.Mvc.Rendering")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Microsoft.AspNet.Mvc.Helpers")] [assembly: AssemblyProduct("Microsoft.AspNet.Mvc.Rendering")]
[assembly: AssemblyCopyright("Copyright © 2014")] [assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]

View File

@ -10,6 +10,38 @@ namespace Microsoft.AspNet.Mvc.Rendering
private static readonly ResourceManager _resourceManager private static readonly ResourceManager _resourceManager
= new ResourceManager("Microsoft.AspNet.Mvc.Rendering.Resources", typeof(Resources).GetTypeInfo().Assembly); = new ResourceManager("Microsoft.AspNet.Mvc.Rendering.Resources", typeof(Resources).GetTypeInfo().Assembly);
/// <summary>
/// The argument '{0}' is null or empty.
/// </summary>
internal static string ArgumentNullOrEmpty
{
get { return GetString("ArgumentNullOrEmpty"); }
}
/// <summary>
/// The argument '{0}' is null or empty.
/// </summary>
internal static string FormatArgumentNullOrEmpty(object p0)
{
return string.Format(CultureInfo.CurrentCulture, GetString("ArgumentNullOrEmpty"), p0);
}
/// <summary>
/// The partial view '{0}' was not found or no view engine supports the searched locations. The following locations were searched:{1}
/// </summary>
internal static string Common_PartialViewNotFound
{
get { return GetString("Common_PartialViewNotFound"); }
}
/// <summary>
/// The partial view '{0}' was not found or no view engine supports the searched locations. The following locations were searched:{1}
/// </summary>
internal static string FormatCommon_PartialViewNotFound(object p0, object p1)
{
return string.Format(CultureInfo.CurrentCulture, GetString("Common_PartialViewNotFound"), p0, p1);
}
/// <summary> /// <summary>
/// The model item passed is null, but this ViewData instance requires a non-null model item of type '{0}'. /// The model item passed is null, but this ViewData instance requires a non-null model item of type '{0}'.
/// </summary> /// </summary>

View File

@ -117,6 +117,12 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<data name="ArgumentNullOrEmpty" xml:space="preserve">
<value>The argument '{0}' is null or empty.</value>
</data>
<data name="Common_PartialViewNotFound" xml:space="preserve">
<value>The partial view '{0}' was not found or no view engine supports the searched locations. The following locations were searched:{1}</value>
</data>
<data name="ViewData_ModelCannotBeNull" xml:space="preserve"> <data name="ViewData_ModelCannotBeNull" xml:space="preserve">
<value>The model item passed is null, but this ViewData instance requires a non-null model item of type '{0}'.</value> <value>The model item passed is null, but this ViewData instance requires a non-null model item of type '{0}'.</value>
</data> </data>

View File

@ -1,5 +1,4 @@
 namespace Microsoft.AspNet.Mvc.Rendering
namespace Microsoft.AspNet.Mvc
{ {
public static class UrlHelperExtensions public static class UrlHelperExtensions
{ {

View File

@ -1,8 +1,7 @@
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.ModelBinding;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.Rendering
{ {
public interface IView public interface IView
{ {

View File

@ -1,6 +1,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.Rendering
{ {
public interface IViewEngine public interface IViewEngine
{ {

View File

@ -1,7 +1,7 @@
using System; using System;
using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.Abstractions;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.Rendering
{ {
public class ViewContext public class ViewContext
{ {

View File

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Dynamic; using System.Dynamic;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.Rendering
{ {
public class ViewData : DynamicObject public class ViewData : DynamicObject
{ {
@ -14,13 +14,8 @@ namespace Microsoft.AspNet.Mvc
_data = new Dictionary<object, dynamic>(); _data = new Dictionary<object, dynamic>();
} }
public ViewData(ViewData source) public ViewData([NotNull] ViewData source)
{ {
if (source == null)
{
throw new ArgumentNullException("source");
}
_data = source._data; _data = source._data;
SetModel(source.Model); SetModel(source.Model);
} }

View File

@ -1,9 +1,7 @@
using System; using System;
using System.Globalization;
using Microsoft.AspNet.Mvc.ModelBinding.Internal; using Microsoft.AspNet.Mvc.ModelBinding.Internal;
using Microsoft.AspNet.Mvc.Rendering;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.Rendering
{ {
public class ViewData<TModel> : ViewData public class ViewData<TModel> : ViewData
{ {
@ -25,7 +23,8 @@ namespace Microsoft.AspNet.Mvc
protected override void SetModel(object value) protected override void SetModel(object value)
{ {
// IsCompatibleObject verifies if the value is either an instance of TModel or if value happens to be null that TModel is nullable type. // IsCompatibleObject verifies if the value is either an instance of TModel or (if value is null) that
// TModel is a nullable type.
bool castWillSucceed = typeof(TModel).IsCompatibleWith(value); bool castWillSucceed = typeof(TModel).IsCompatibleWith(value);
if (castWillSucceed) if (castWillSucceed)
@ -37,11 +36,11 @@ namespace Microsoft.AspNet.Mvc
string message; string message;
if (value == null) if (value == null)
{ {
message = String.Format(CultureInfo.CurrentCulture, Resources.ViewData_ModelCannotBeNull, typeof(TModel)); message = Resources.FormatViewData_ModelCannotBeNull(typeof(TModel));
} }
else else
{ {
message = String.Format(CultureInfo.CurrentCulture, Resources.ViewData_WrongTModelType, value.GetType(), typeof(TModel)); message = Resources.FormatViewData_WrongTModelType(value.GetType(), typeof(TModel));
} }
throw new InvalidOperationException(message); throw new InvalidOperationException(message);
} }

View File

@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc.Rendering
{ {
public class ViewEngineResult public class ViewEngineResult
{ {
@ -18,26 +18,16 @@ namespace Microsoft.AspNet.Mvc
get { return View != null; } get { return View != null; }
} }
public static ViewEngineResult NotFound(IEnumerable<string> searchedLocations) public static ViewEngineResult NotFound([NotNull] IEnumerable<string> searchedLocations)
{ {
if (searchedLocations == null)
{
throw new ArgumentNullException("searchedLocations");
}
return new ViewEngineResult return new ViewEngineResult
{ {
SearchedLocations = searchedLocations SearchedLocations = searchedLocations
}; };
} }
public static ViewEngineResult Found(IView view) public static ViewEngineResult Found([NotNull] IView view)
{ {
if (view == null)
{
throw new ArgumentNullException("view");
}
return new ViewEngineResult return new ViewEngineResult
{ {
View = view View = view

View File

@ -6,6 +6,7 @@ using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Razor; using Microsoft.AspNet.Mvc.Razor;
using Microsoft.AspNet.Mvc.Razor.Compilation; using Microsoft.AspNet.Mvc.Razor.Compilation;
using Microsoft.AspNet.Mvc.Rendering;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {

View File

@ -1,16 +0,0 @@
using System;
using Xunit;
namespace Microsoft.AspNet.Mvc.ModelBinding.Test
{
public class ViewDataDictionaryTest
{
[Fact]
public void ConstructorThrowsIfParameterIsNull()
{
// Act & Assert
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(() => new ViewData(source: null));
Assert.Equal("source", ex.ParamName);
}
}
}