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:
parent
478c220ddb
commit
3a0add8be8
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
|
||||
namespace MvcSample.Web
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.AspNet.Abstractions;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<dynamic>.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.Rendering
|
||||
{
|
||||
public enum FormMethod
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<string, ModelMetadata, IEnumerable<ModelClientValidationRule>> 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());
|
||||
//}
|
||||
|
||||
///// <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.")]
|
||||
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<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>
|
||||
/// 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<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);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using Microsoft.AspNet.Abstractions;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.Rendering
|
||||
{
|
||||
public class HtmlHelper<TModel> : HtmlHelper
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.Rendering
|
||||
{
|
||||
public class HtmlString
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.Rendering
|
||||
{
|
||||
public interface IUrlHelper
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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("")]
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
/// <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>
|
||||
/// The model item passed is null, but this ViewData instance requires a non-null model item of type '{0}'.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -117,6 +117,12 @@
|
|||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</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">
|
||||
<value>The model item passed is null, but this ViewData instance requires a non-null model item of type '{0}'.</value>
|
||||
</data>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.Rendering
|
||||
{
|
||||
public static class UrlHelperExtensions
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.Rendering
|
||||
{
|
||||
public interface IViewEngine
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using Microsoft.AspNet.Abstractions;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
namespace Microsoft.AspNet.Mvc.Rendering
|
||||
{
|
||||
public class ViewContext
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<object, dynamic>();
|
||||
}
|
||||
|
||||
public ViewData(ViewData source)
|
||||
public ViewData([NotNull] ViewData source)
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
throw new ArgumentNullException("source");
|
||||
}
|
||||
|
||||
_data = source._data;
|
||||
SetModel(source.Model);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<TModel> : 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<string> searchedLocations)
|
||||
public static ViewEngineResult NotFound([NotNull] IEnumerable<string> 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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue