diff --git a/samples/MvcSample.Web/LinkController.cs b/samples/MvcSample.Web/LinkController.cs index c68ec8c5dd..2dc7b843f7 100644 --- a/samples/MvcSample.Web/LinkController.cs +++ b/samples/MvcSample.Web/LinkController.cs @@ -1,5 +1,6 @@  using Microsoft.AspNet.Mvc; +using Microsoft.AspNet.Mvc.Rendering; namespace MvcSample.Web { diff --git a/src/Microsoft.AspNet.Mvc.Core/ActionResultHelper.cs b/src/Microsoft.AspNet.Mvc.Core/ActionResultHelper.cs index 8fa66787d8..62c5968246 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ActionResultHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ActionResultHelper.cs @@ -1,5 +1,5 @@ using System; -using Microsoft.AspNet.Mvc.ModelBinding; +using Microsoft.AspNet.Mvc.Rendering; namespace Microsoft.AspNet.Mvc { diff --git a/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs b/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs index 748f5c5180..c473b3b77e 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs @@ -3,7 +3,7 @@ using System.Globalization; using System.IO; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNet.Mvc.ModelBinding; +using Microsoft.AspNet.Mvc.Rendering; namespace Microsoft.AspNet.Mvc { diff --git a/src/Microsoft.AspNet.Mvc.Core/Controller.cs b/src/Microsoft.AspNet.Mvc.Core/Controller.cs index a0856be189..a1d1a0936d 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Controller.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Controller.cs @@ -1,4 +1,5 @@ using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Mvc.Rendering; namespace Microsoft.AspNet.Mvc { diff --git a/src/Microsoft.AspNet.Mvc.Core/DefaultControllerFactory.cs b/src/Microsoft.AspNet.Mvc.Core/DefaultControllerFactory.cs index f08d167d10..56b93404df 100644 --- a/src/Microsoft.AspNet.Mvc.Core/DefaultControllerFactory.cs +++ b/src/Microsoft.AspNet.Mvc.Core/DefaultControllerFactory.cs @@ -4,7 +4,7 @@ using System.Reflection; using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.Mvc.ModelBinding; -using Microsoft.AspNet.Routing; +using Microsoft.AspNet.Mvc.Rendering; namespace Microsoft.AspNet.Mvc { diff --git a/src/Microsoft.AspNet.Mvc.Core/IActionResultHelper.cs b/src/Microsoft.AspNet.Mvc.Core/IActionResultHelper.cs index 41dfef7e20..c0bf5c78a1 100644 --- a/src/Microsoft.AspNet.Mvc.Core/IActionResultHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Core/IActionResultHelper.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNet.Mvc.ModelBinding; +using Microsoft.AspNet.Mvc.Rendering; namespace Microsoft.AspNet.Mvc { diff --git a/src/Microsoft.AspNet.Mvc.Core/UrlHelper.cs b/src/Microsoft.AspNet.Mvc.Core/UrlHelper.cs index 94374a71f3..c42fe2b070 100644 --- a/src/Microsoft.AspNet.Mvc.Core/UrlHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Core/UrlHelper.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Routing; namespace Microsoft.AspNet.Mvc diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorHost.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorHost.cs index 6898707fad..b59bc07e1d 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorHost.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorHost.cs @@ -14,7 +14,8 @@ namespace Microsoft.AspNet.Mvc.Razor "System.Linq", "System.Collections.Generic", "Microsoft.AspNet.Mvc", - "Microsoft.AspNet.Mvc.Razor" + "Microsoft.AspNet.Mvc.Razor", + "Microsoft.AspNet.Mvc.Rendering" }; // CodeGenerationContext.DefaultBaseClass is set to MyBaseType. diff --git a/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs b/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs index a49c75ce56..87a9c6a4cf 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs @@ -3,8 +3,8 @@ using System.IO; using System.Net; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.DependencyInjection; +using Microsoft.AspNet.Mvc.Rendering; 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 // 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; bool? boolValue = val.Value as bool?; if (boolValue == true) diff --git a/src/Microsoft.AspNet.Mvc.Razor/RazorViewOfT.cs b/src/Microsoft.AspNet.Mvc.Razor/RazorViewOfT.cs index 528ce75914..522a72570a 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/RazorViewOfT.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/RazorViewOfT.cs @@ -1,5 +1,6 @@ using System.IO; using System.Threading.Tasks; +using Microsoft.AspNet.Mvc.Rendering; namespace Microsoft.AspNet.Mvc.Razor { diff --git a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/IVirtualPathViewFactory.cs b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/IVirtualPathViewFactory.cs index 8da8822d59..0c6651a6f9 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/IVirtualPathViewFactory.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/IVirtualPathViewFactory.cs @@ -1,5 +1,6 @@  using System.Threading.Tasks; +using Microsoft.AspNet.Mvc.Rendering; namespace Microsoft.AspNet.Mvc.Razor { diff --git a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs index ce7fb46441..9284a161a5 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Globalization; using System.Threading.Tasks; +using Microsoft.AspNet.Mvc.Rendering; namespace Microsoft.AspNet.Mvc.Razor { diff --git a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/VirtualPathViewFactory.cs b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/VirtualPathViewFactory.cs index 0be334ccbc..8caae5ba05 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/VirtualPathViewFactory.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/VirtualPathViewFactory.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.Mvc.Rendering; using Microsoft.Net.Runtime; namespace Microsoft.AspNet.Mvc.Razor diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Html/FormMethod.cs b/src/Microsoft.AspNet.Mvc.Rendering/Html/FormMethod.cs index 8f66b6649f..1468799059 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/Html/FormMethod.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/Html/FormMethod.cs @@ -1,5 +1,4 @@ - -namespace Microsoft.AspNet.Mvc +namespace Microsoft.AspNet.Mvc.Rendering { public enum FormMethod { diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs index 9dd521e838..1836c47795 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs @@ -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.Diagnostics.CodeAnalysis; -using System.Globalization; using System.Net; using System.Reflection; using System.Text; using Microsoft.AspNet.Abstractions; -namespace Microsoft.AspNet.Mvc +namespace Microsoft.AspNet.Mvc.Rendering { public class HtmlHelper { @@ -24,10 +21,12 @@ namespace Microsoft.AspNet.Mvc { HttpContext = httpContext; 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> ClientValidationRuleFactory { get; set; } + public string IdAttributeDotReplacement { get; set; } public HttpContext HttpContext { get; private set; } @@ -72,62 +71,20 @@ namespace Microsoft.AspNet.Mvc return result; } - //[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "For consistency, all helpers are instance methods.")] - //public HtmlString AntiForgeryToken() - //{ - // return new HtmlString(AntiForgery.GetHtml().ToString()); - //} - - ///// - ///// Set this property to to have templated helpers such as Html.EditorFor render date and time - ///// values as Rfc3339 compliant strings. - ///// - ///// - ///// The scope of this setting is for the current view alone. Sub views and parent views - ///// will default to unless explicitly set otherwise. - ///// - //[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.")] 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.")] 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; if (result.View != null) @@ -142,18 +99,13 @@ namespace Microsoft.AspNet.Mvc locationsText.Append(location); } - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, - "MvcResources.Common_PartialViewNotFound", partialViewName, locationsText)); + throw new InvalidOperationException(Resources.FormatCommon_PartialViewNotFound(partialViewName, + locationsText)); } - public static string GenerateIdFromName(string name) + public string GenerateIdFromName([NotNull] string name) { - if (name == null) - { - throw new ArgumentNullException("name"); - } - - return TagBuilder.CreateSanitizedId(name); + return TagBuilder.CreateSanitizedId(name, IdAttributeDotReplacement); } 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 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
to attach them to). - //public IDictionary GetUnobtrusiveValidationAttributes(string name, ModelMetadata metadata) - //{ - // Dictionary results = new Dictionary(); - - // // 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 clientRules = ClientValidationRuleFactory(name, metadata); - // UnobtrusiveValidationAttributesGenerator.GetValidationAttributes(clientRules, results); - - // return results; - //} - /// /// Wraps HTML markup in an IHtmlString, which will enable HTML markup to be /// rendered to the output without getting HTML encoded. @@ -262,42 +163,5 @@ namespace Microsoft.AspNet.Mvc { return new HtmlString(value == null ? null : value.ToString()); } - - //internal virtual void RenderPartialInternal(string partialViewName, ViewData viewData, TModel model, TextWriter writer, IViewEngine viewEngine) - //{ - // if (String.IsNullOrEmpty(partialViewName)) - // { - // throw new ArgumentException("MvcResources.Common_NullOrEmpty", "partialViewName"); - // } - - // ViewData newViewData = null; - - // if (model == null) - // { - // if (viewData == null) - // { - // newViewData = new ViewData(ViewContext.ViewData); - // } - // else - // { - // newViewData = new ViewData(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); - //} } } diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelperOfT.cs b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelperOfT.cs index 41e9d7e581..094ccd1d48 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelperOfT.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelperOfT.cs @@ -1,6 +1,6 @@ using Microsoft.AspNet.Abstractions; -namespace Microsoft.AspNet.Mvc +namespace Microsoft.AspNet.Mvc.Rendering { public class HtmlHelper : HtmlHelper { diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlString.cs b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlString.cs index b71180201d..fe7291dcc4 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlString.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlString.cs @@ -1,5 +1,4 @@ - -namespace Microsoft.AspNet.Mvc +namespace Microsoft.AspNet.Mvc.Rendering { public class HtmlString { diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Html/InputType.cs b/src/Microsoft.AspNet.Mvc.Rendering/Html/InputType.cs index 746db034dd..8dfd1e41f4 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/Html/InputType.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/Html/InputType.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; - -namespace Microsoft.AspNet.Mvc +namespace Microsoft.AspNet.Mvc.Rendering { public enum InputType { diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Html/TagBuilder.cs b/src/Microsoft.AspNet.Mvc.Rendering/Html/TagBuilder.cs index 9b2acaeee4..cb68026678 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/Html/TagBuilder.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/Html/TagBuilder.cs @@ -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.Globalization; using System.Net; using System.Text; -namespace Microsoft.AspNet.Mvc +namespace Microsoft.AspNet.Mvc.Rendering { public class TagBuilder { - private string _idAttributeDotReplacement; - private string _innerHtml; 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; @@ -29,7 +25,7 @@ namespace Microsoft.AspNet.Mvc public string InnerHtml { - get { return _innerHtml ?? String.Empty; } + get { return _innerHtml ?? string.Empty; } 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*/); - } - - public static string CreateSanitizedId(string originalId, string invalidCharReplacement) - { - if (String.IsNullOrEmpty(originalId)) + if (string.IsNullOrEmpty(originalId)) { - return null; + return string.Empty; } - if (invalidCharReplacement == null) - { - throw new ArgumentNullException("invalidCharReplacement"); - } + var firstChar = originalId[0]; - char firstChar = originalId[0]; - - StringBuilder sb = new StringBuilder(originalId.Length); + var sb = new StringBuilder(originalId.Length); sb.Append(firstChar); - for (int i = 1; i < originalId.Length; i++) + for (var i = 1; i < originalId.Length; i++) { - char thisChar = originalId[i]; - if (!Char.IsWhiteSpace(thisChar)) + var thisChar = originalId[i]; + if (!char.IsWhiteSpace(thisChar)) { sb.Append(thisChar); } @@ -87,12 +73,12 @@ namespace Microsoft.AspNet.Mvc return sb.ToString(); } - public void GenerateId(string name) + public void GenerateId(string name, [NotNull] string idAttributeDotReplacement) { if (!Attributes.ContainsKey("id")) { - string sanitizedId = name; // CreateSanitizedId(name, IdAttributeDotReplacement); - if (!String.IsNullOrEmpty(sanitizedId)) + var sanitizedId = CreateSanitizedId(name, idAttributeDotReplacement); + if (!string.IsNullOrEmpty(sanitizedId)) { Attributes["id"] = sanitizedId; } @@ -103,13 +89,13 @@ namespace Microsoft.AspNet.Mvc { foreach (var attribute in Attributes) { - string key = attribute.Key; - if (String.Equals(key, "id", StringComparison.Ordinal) && String.IsNullOrEmpty(attribute.Value)) + var key = attribute.Key; + if (string.Equals(key, "id", StringComparison.Ordinal) && string.IsNullOrEmpty(attribute.Value)) { continue; } - //string value = HttpUtility.HtmlAttributeEncode(attribute.Value); - string value = WebUtility.HtmlEncode(attribute.Value); + + var value = WebUtility.HtmlEncode(attribute.Value); sb.Append(' ') .Append(key) .Append("=\"") @@ -125,9 +111,9 @@ namespace Microsoft.AspNet.Mvc 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)) @@ -147,8 +133,8 @@ namespace Microsoft.AspNet.Mvc { foreach (var entry in attributes) { - string key = Convert.ToString(entry.Key, CultureInfo.InvariantCulture); - string value = Convert.ToString(entry.Value, CultureInfo.InvariantCulture); + var key = Convert.ToString(entry.Key, CultureInfo.InvariantCulture); + var value = Convert.ToString(entry.Value, CultureInfo.InvariantCulture); MergeAttribute(key, value, replaceExisting); } } @@ -159,7 +145,7 @@ namespace Microsoft.AspNet.Mvc InnerHtml = WebUtility.HtmlEncode(innerText); } - internal HtmlString ToHtmlString(TagRenderMode renderMode) + public HtmlString ToHtmlString(TagRenderMode renderMode) { return new HtmlString(ToString(renderMode)); } @@ -171,7 +157,7 @@ namespace Microsoft.AspNet.Mvc public string ToString(TagRenderMode renderMode) { - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); switch (renderMode) { case TagRenderMode.StartTag: @@ -202,6 +188,7 @@ namespace Microsoft.AspNet.Mvc .Append('>'); break; } + return sb.ToString(); } } diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Html/TagRenderMode.cs b/src/Microsoft.AspNet.Mvc.Rendering/Html/TagRenderMode.cs index e727617c66..7eee690246 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/Html/TagRenderMode.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/Html/TagRenderMode.cs @@ -1,8 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. - -using System.Runtime.CompilerServices; - -namespace Microsoft.AspNet.Mvc +namespace Microsoft.AspNet.Mvc.Rendering { public enum TagRenderMode { diff --git a/src/Microsoft.AspNet.Mvc.Rendering/IUrlHelper.cs b/src/Microsoft.AspNet.Mvc.Rendering/IUrlHelper.cs index f5b107285c..59318e4083 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/IUrlHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/IUrlHelper.cs @@ -1,5 +1,4 @@ - -namespace Microsoft.AspNet.Mvc +namespace Microsoft.AspNet.Mvc.Rendering { public interface IUrlHelper { diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Mvc.Rendering/Properties/AssemblyInfo.cs index 6ba2f874f5..cbc0e4b45d 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/Properties/AssemblyInfo.cs @@ -1,15 +1,16 @@ -using System.Reflection; -using System.Runtime.CompilerServices; +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. + +using System.Reflection; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("Microsoft.AspNet.Mvc.Helpers")] +[assembly: AssemblyTitle("Microsoft.AspNet.Mvc.Rendering")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Microsoft.AspNet.Mvc.Helpers")] +[assembly: AssemblyProduct("Microsoft.AspNet.Mvc.Rendering")] [assembly: AssemblyCopyright("Copyright © 2014")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Properties/Resources.Designer.cs b/src/Microsoft.AspNet.Mvc.Rendering/Properties/Resources.Designer.cs index 15ace04265..355f42fc86 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/Properties/Resources.Designer.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/Properties/Resources.Designer.cs @@ -10,6 +10,38 @@ namespace Microsoft.AspNet.Mvc.Rendering private static readonly ResourceManager _resourceManager = new ResourceManager("Microsoft.AspNet.Mvc.Rendering.Resources", typeof(Resources).GetTypeInfo().Assembly); + /// + /// The argument '{0}' is null or empty. + /// + internal static string ArgumentNullOrEmpty + { + get { return GetString("ArgumentNullOrEmpty"); } + } + + /// + /// The argument '{0}' is null or empty. + /// + internal static string FormatArgumentNullOrEmpty(object p0) + { + return string.Format(CultureInfo.CurrentCulture, GetString("ArgumentNullOrEmpty"), p0); + } + + /// + /// The partial view '{0}' was not found or no view engine supports the searched locations. The following locations were searched:{1} + /// + internal static string Common_PartialViewNotFound + { + get { return GetString("Common_PartialViewNotFound"); } + } + + /// + /// The partial view '{0}' was not found or no view engine supports the searched locations. The following locations were searched:{1} + /// + internal static string FormatCommon_PartialViewNotFound(object p0, object p1) + { + return string.Format(CultureInfo.CurrentCulture, GetString("Common_PartialViewNotFound"), p0, p1); + } + /// /// The model item passed is null, but this ViewData instance requires a non-null model item of type '{0}'. /// diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Properties/Resources.resx b/src/Microsoft.AspNet.Mvc.Rendering/Properties/Resources.resx index e8cf52bbb7..6d42ab2a58 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/Properties/Resources.resx +++ b/src/Microsoft.AspNet.Mvc.Rendering/Properties/Resources.resx @@ -117,6 +117,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + The argument '{0}' is null or empty. + + + The partial view '{0}' was not found or no view engine supports the searched locations. The following locations were searched:{1} + The model item passed is null, but this ViewData instance requires a non-null model item of type '{0}'. diff --git a/src/Microsoft.AspNet.Mvc.Rendering/UrlHelperExtensions.cs b/src/Microsoft.AspNet.Mvc.Rendering/UrlHelperExtensions.cs index 9eeedd3000..eeb795f829 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/UrlHelperExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/UrlHelperExtensions.cs @@ -1,5 +1,4 @@ - -namespace Microsoft.AspNet.Mvc +namespace Microsoft.AspNet.Mvc.Rendering { public static class UrlHelperExtensions { diff --git a/src/Microsoft.AspNet.Mvc.Rendering/View/IView.cs b/src/Microsoft.AspNet.Mvc.Rendering/View/IView.cs index c7d6f22a58..f1ea7a916c 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/View/IView.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/View/IView.cs @@ -1,8 +1,7 @@ using System.IO; using System.Threading.Tasks; -using Microsoft.AspNet.Mvc.ModelBinding; -namespace Microsoft.AspNet.Mvc +namespace Microsoft.AspNet.Mvc.Rendering { public interface IView { diff --git a/src/Microsoft.AspNet.Mvc.Rendering/View/IViewEngine.cs b/src/Microsoft.AspNet.Mvc.Rendering/View/IViewEngine.cs index 69746f1be5..4223b3573c 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/View/IViewEngine.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/View/IViewEngine.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace Microsoft.AspNet.Mvc +namespace Microsoft.AspNet.Mvc.Rendering { public interface IViewEngine { diff --git a/src/Microsoft.AspNet.Mvc.Rendering/View/ViewContext.cs b/src/Microsoft.AspNet.Mvc.Rendering/View/ViewContext.cs index 3e68e40f4e..8c332513b9 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/View/ViewContext.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/View/ViewContext.cs @@ -1,7 +1,7 @@ using System; using Microsoft.AspNet.Abstractions; -namespace Microsoft.AspNet.Mvc +namespace Microsoft.AspNet.Mvc.Rendering { public class ViewContext { diff --git a/src/Microsoft.AspNet.Mvc.Rendering/View/ViewData.cs b/src/Microsoft.AspNet.Mvc.Rendering/View/ViewData.cs index b572c480d2..e2919c7db8 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/View/ViewData.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/View/ViewData.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Dynamic; -namespace Microsoft.AspNet.Mvc +namespace Microsoft.AspNet.Mvc.Rendering { public class ViewData : DynamicObject { @@ -14,13 +14,8 @@ namespace Microsoft.AspNet.Mvc _data = new Dictionary(); } - public ViewData(ViewData source) + public ViewData([NotNull] ViewData source) { - if (source == null) - { - throw new ArgumentNullException("source"); - } - _data = source._data; SetModel(source.Model); } diff --git a/src/Microsoft.AspNet.Mvc.Rendering/View/ViewDataOfTModel.cs b/src/Microsoft.AspNet.Mvc.Rendering/View/ViewDataOfTModel.cs index 4a42e88e3a..133a04a482 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/View/ViewDataOfTModel.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/View/ViewDataOfTModel.cs @@ -1,9 +1,7 @@ using System; -using System.Globalization; using Microsoft.AspNet.Mvc.ModelBinding.Internal; -using Microsoft.AspNet.Mvc.Rendering; -namespace Microsoft.AspNet.Mvc +namespace Microsoft.AspNet.Mvc.Rendering { public class ViewData : ViewData { @@ -25,7 +23,8 @@ namespace Microsoft.AspNet.Mvc 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); if (castWillSucceed) @@ -37,11 +36,11 @@ namespace Microsoft.AspNet.Mvc string message; if (value == null) { - message = String.Format(CultureInfo.CurrentCulture, Resources.ViewData_ModelCannotBeNull, typeof(TModel)); + message = Resources.FormatViewData_ModelCannotBeNull(typeof(TModel)); } 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); } diff --git a/src/Microsoft.AspNet.Mvc.Rendering/View/ViewEngineResult.cs b/src/Microsoft.AspNet.Mvc.Rendering/View/ViewEngineResult.cs index 624977da3c..3ef3e86527 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/View/ViewEngineResult.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/View/ViewEngineResult.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.AspNet.Mvc +namespace Microsoft.AspNet.Mvc.Rendering { public class ViewEngineResult { @@ -18,26 +18,16 @@ namespace Microsoft.AspNet.Mvc get { return View != null; } } - public static ViewEngineResult NotFound(IEnumerable searchedLocations) + public static ViewEngineResult NotFound([NotNull] IEnumerable searchedLocations) { - if (searchedLocations == null) - { - throw new ArgumentNullException("searchedLocations"); - } - return new ViewEngineResult { 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 { View = view diff --git a/src/Microsoft.AspNet.Mvc/MvcServices.cs b/src/Microsoft.AspNet.Mvc/MvcServices.cs index 1265e3158a..cac51bdd98 100644 --- a/src/Microsoft.AspNet.Mvc/MvcServices.cs +++ b/src/Microsoft.AspNet.Mvc/MvcServices.cs @@ -6,6 +6,7 @@ using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.Razor; using Microsoft.AspNet.Mvc.Razor.Compilation; +using Microsoft.AspNet.Mvc.Rendering; namespace Microsoft.AspNet.Mvc { diff --git a/test/Microsoft.AspNet.Mvc.Rendering.Test/ViewDataTest.cs b/test/Microsoft.AspNet.Mvc.Rendering.Test/ViewDataTest.cs deleted file mode 100644 index 13e2d0ae80..0000000000 --- a/test/Microsoft.AspNet.Mvc.Rendering.Test/ViewDataTest.cs +++ /dev/null @@ -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(() => new ViewData(source: null)); - Assert.Equal("source", ex.ParamName); - } - } -} \ No newline at end of file