Add high-pri doc comments for views, controllers, HTML helpers, Startup

This commit is contained in:
Eilon Lipton 2015-10-19 20:38:01 -07:00
parent 38b65875db
commit 55b72c04bf
12 changed files with 142 additions and 9 deletions

View File

@ -5,8 +5,18 @@ using System.Threading.Tasks;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
/// <summary>
/// Defines a contract that represents the result of an action method.
/// </summary>
public interface IActionResult public interface IActionResult
{ {
/// <summary>
/// Executes the result operation of the action method asynchronously. This method is called by MVC to process
/// the result of an action method.
/// </summary>
/// <param name="context">The context in which the result is executed. The context information includes
/// information about the action that was executed and request information.</param>
/// <returns>A task that represents the asynchronous execute operation.</returns>
Task ExecuteResultAsync(ActionContext context); Task ExecuteResultAsync(ActionContext context);
} }
} }

View File

@ -5,14 +5,32 @@ using System.Threading.Tasks;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
/// <summary>
/// A default implementation of <see cref="IActionResult"/>.
/// </summary>
public abstract class ActionResult : IActionResult public abstract class ActionResult : IActionResult
{ {
/// <summary>
/// Executes the result operation of the action method asynchronously. This method is called by MVC to process
/// the result of an action method.
/// The default implementation of this method calls the <see cref="ExecuteResult(ActionContext)"/> method and
/// returns a completed task.
/// </summary>
/// <param name="context">The context in which the result is executed. The context information includes
/// information about the action that was executed and request information.</param>
/// <returns>A task that represents the asynchronous execute operation.</returns>
public virtual Task ExecuteResultAsync(ActionContext context) public virtual Task ExecuteResultAsync(ActionContext context)
{ {
ExecuteResult(context); ExecuteResult(context);
return Task.FromResult(true); return Task.FromResult(true);
} }
/// <summary>
/// Executes the result operation of the action method synchronously. This method is called by MVC to process
/// the result of an action method.
/// </summary>
/// <param name="context">The context in which the result is executed. The context information includes
/// information about the action that was executed and request information.</param>
public virtual void ExecuteResult(ActionContext context) public virtual void ExecuteResult(ActionContext context)
{ {
} }

View File

@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Builder
/// Adds MVC to the <see cref="IApplicationBuilder"/> request execution pipeline. /// Adds MVC to the <see cref="IApplicationBuilder"/> request execution pipeline.
/// </summary> /// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/>.</param> /// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
/// <returns>The <paramref name="app"/>.</returns> /// <returns>A reference to this instance after the operation has completed.</returns>
/// <remarks>This method only supports attribute routing. To add conventional routes use /// <remarks>This method only supports attribute routing. To add conventional routes use
/// <see cref="UseMvc(IApplicationBuilder, Action{IRouteBuilder})"/>.</remarks> /// <see cref="UseMvc(IApplicationBuilder, Action{IRouteBuilder})"/>.</remarks>
public static IApplicationBuilder UseMvc(this IApplicationBuilder app) public static IApplicationBuilder UseMvc(this IApplicationBuilder app)
@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Builder
/// '{controller=Home}/{action=Index}/{id?}'. /// '{controller=Home}/{action=Index}/{id?}'.
/// </summary> /// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/>.</param> /// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
/// <returns>The <paramref name="app"/>.</returns> /// <returns>A reference to this instance after the operation has completed.</returns>
public static IApplicationBuilder UseMvcWithDefaultRoute(this IApplicationBuilder app) public static IApplicationBuilder UseMvcWithDefaultRoute(this IApplicationBuilder app)
{ {
if (app == null) if (app == null)
@ -60,7 +60,7 @@ namespace Microsoft.AspNet.Builder
/// </summary> /// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/>.</param> /// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
/// <param name="configureRoutes">A callback to configure MVC routes.</param> /// <param name="configureRoutes">A callback to configure MVC routes.</param>
/// <returns>The <paramref name="app"/>.</returns> /// <returns>A reference to this instance after the operation has completed.</returns>
public static IApplicationBuilder UseMvc( public static IApplicationBuilder UseMvc(
this IApplicationBuilder app, this IApplicationBuilder app,
Action<IRouteBuilder> configureRoutes) Action<IRouteBuilder> configureRoutes)

View File

@ -46,6 +46,9 @@ namespace Microsoft.AspNet.Mvc.Razor
_writerScopes = new Stack<TextWriter>(); _writerScopes = new Stack<TextWriter>();
} }
/// <summary>
/// An <see cref="HttpContext"/> representing the current request execution.
/// </summary>
public HttpContext Context public HttpContext Context
{ {
get get
@ -81,7 +84,7 @@ namespace Microsoft.AspNet.Mvc.Razor
public IPageExecutionContext PageExecutionContext { get; set; } public IPageExecutionContext PageExecutionContext { get; set; }
/// <summary> /// <summary>
/// Gets the TextWriter that the page is writing output to. /// Gets the <see cref="TextWriter"/> that the page is writing output to.
/// </summary> /// </summary>
public virtual TextWriter Output public virtual TextWriter Output
{ {
@ -97,6 +100,9 @@ namespace Microsoft.AspNet.Mvc.Razor
} }
} }
/// <summary>
/// Gets the <see cref="ClaimsPrincipal"/> of the current logged in user.
/// </summary>
public virtual ClaimsPrincipal User public virtual ClaimsPrincipal User
{ {
get get
@ -110,6 +116,9 @@ namespace Microsoft.AspNet.Mvc.Razor
} }
} }
/// <summary>
/// Gets the dynamic view data dictionary.
/// </summary>
public dynamic ViewBag public dynamic ViewBag
{ {
get get
@ -821,6 +830,10 @@ namespace Microsoft.AspNet.Mvc.Razor
EndContext(); EndContext();
} }
/// <summary>
/// In a Razor layout page, renders the portion of a content page that is not within a named section.
/// </summary>
/// <returns>The HTML content to render.</returns>
protected virtual HelperResult RenderBody() protected virtual HelperResult RenderBody()
{ {
if (RenderBodyDelegateAsync == null) if (RenderBodyDelegateAsync == null)
@ -858,6 +871,11 @@ namespace Microsoft.AspNet.Mvc.Razor
SectionWriters[name] = section; SectionWriters[name] = section;
} }
/// <summary>
/// Returns a value that indicates whether the specified section is defined in the content page.
/// </summary>
/// <param name="name">The section name to search for.</param>
/// <returns><c>true</c> if the specified section is defined in the content page; otherwise, <c>false</c>.</returns>
public bool IsSectionDefined(string name) public bool IsSectionDefined(string name)
{ {
if (name == null) if (name == null)

View File

@ -19,6 +19,9 @@ namespace Microsoft.AspNet.Mvc.Razor
{ {
private IModelMetadataProvider _provider; private IModelMetadataProvider _provider;
/// <summary>
/// Gets the Model property of the <see cref="ViewData"/> property.
/// </summary>
public TModel Model public TModel Model
{ {
get get
@ -27,6 +30,9 @@ namespace Microsoft.AspNet.Mvc.Razor
} }
} }
/// <summary>
/// Gets or sets the dictionary for view data.
/// </summary>
[RazorInject] [RazorInject]
public ViewDataDictionary<TModel> ViewData { get; set; } public ViewDataDictionary<TModel> ViewData { get; set; }

View File

@ -10,6 +10,11 @@ using Microsoft.AspNet.Mvc.ViewFeatures;
namespace Microsoft.AspNet.Mvc.Rendering namespace Microsoft.AspNet.Mvc.Rendering
{ {
/// <summary>
/// Represents a list that lets users select multiple items.
/// This class is typically rendered as an HTML <code>&lt;select multiple="multiple"&gt;</code> element with the specified collection
/// of <see cref="SelectListItem"/> objects.
/// </summary>
public class MultiSelectList : IEnumerable<SelectListItem> public class MultiSelectList : IEnumerable<SelectListItem>
{ {
private IList<SelectListGroup> _groups; private IList<SelectListGroup> _groups;

View File

@ -6,6 +6,11 @@ using System.Collections;
namespace Microsoft.AspNet.Mvc.Rendering namespace Microsoft.AspNet.Mvc.Rendering
{ {
/// <summary>
/// Represents a list that lets users select a single item.
/// This class is typically rendered as an HTML <code>&lt;select&gt;</code> element with the specified collection
/// of <see cref="SelectListItem"/> objects.
/// </summary>
public class SelectList : MultiSelectList public class SelectList : MultiSelectList
{ {
public SelectList(IEnumerable items) public SelectList(IEnumerable items)

View File

@ -3,10 +3,17 @@
namespace Microsoft.AspNet.Mvc.Rendering namespace Microsoft.AspNet.Mvc.Rendering
{ {
/// <summary>
/// Represents an item in a <see cref="SelectList"/> or <see cref="MultiSelectList"/>.
/// This class is typically rendered as an HTML <code>&lt;option&gt;</code> element with the specified
/// attribute values.
/// </summary>
public class SelectListItem public class SelectListItem
{ {
/// <summary> /// <summary>
/// Gets or sets a value that indicates whether this <see cref="SelectListItem"/> is disabled. /// Gets or sets a value that indicates whether this <see cref="SelectListItem"/> is disabled.
/// This property is typically rendered as a <code>disabled="disabled"</code> attribute in the HTML
/// <code>&lt;option&gt;</code> element.
/// </summary> /// </summary>
public bool Disabled { get; set; } public bool Disabled { get; set; }
@ -17,10 +24,24 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </summary> /// </summary>
public SelectListGroup Group { get; set; } public SelectListGroup Group { get; set; }
/// <summary>
/// Gets or sets a value that indicates whether this <see cref="SelectListItem"/> is selected.
/// This property is typically rendered as a <code>selected="selected"</code> attribute in the HTML
/// <code>&lt;option&gt;</code> element.
/// </summary>
public bool Selected { get; set; } public bool Selected { get; set; }
/// <summary>
/// Gets or sets a value that indicates the display text of this <see cref="SelectListItem"/>.
/// This property is typically rendered as the inner HTML in the HTML <code>&lt;option&gt;</code> element.
/// </summary>
public string Text { get; set; } public string Text { get; set; }
/// <summary>
/// Gets or sets a value that indicates the value of this <see cref="SelectListItem"/>.
/// This property is typically rendered as a <code>value="..."</code> attribute in the HTML
/// <code>&lt;option&gt;</code> element.
/// </summary>
public string Value { get; set; } public string Value { get; set; }
} }
} }

View File

@ -14,11 +14,19 @@ using Microsoft.Extensions.WebEncoders;
namespace Microsoft.AspNet.Mvc.Rendering namespace Microsoft.AspNet.Mvc.Rendering
{ {
/// <summary>
/// Contains methods and properties that are used to create HTML elements. This class is often used to write HTML
/// helpers and tag helpers.
/// </summary>
[DebuggerDisplay("{DebuggerToString()}")] [DebuggerDisplay("{DebuggerToString()}")]
public class TagBuilder : IHtmlContent public class TagBuilder : IHtmlContent
{ {
private AttributeDictionary _attributes; private AttributeDictionary _attributes;
/// <summary>
/// Creates a new HTML tag that has the specified tag name.
/// </summary>
/// <param name="tagName">An HTML tag name.</param>
public TagBuilder(string tagName) public TagBuilder(string tagName)
{ {
if (string.IsNullOrEmpty(tagName)) if (string.IsNullOrEmpty(tagName))
@ -47,8 +55,14 @@ namespace Microsoft.AspNet.Mvc.Rendering
} }
} }
/// <summary>
/// Gets the inner HTML content of the element.
/// </summary>
public IHtmlContentBuilder InnerHtml { get; } public IHtmlContentBuilder InnerHtml { get; }
/// <summary>
/// Gets the tag name for this tag.
/// </summary>
public string TagName { get; } public string TagName { get; }
/// <summary> /// <summary>
@ -57,6 +71,12 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <remarks>Defaults to <see cref="TagRenderMode.Normal"/>.</remarks> /// <remarks>Defaults to <see cref="TagRenderMode.Normal"/>.</remarks>
public TagRenderMode TagRenderMode { get; set; } = TagRenderMode.Normal; public TagRenderMode TagRenderMode { get; set; } = TagRenderMode.Normal;
/// <summary>
/// Adds a CSS class to the list of CSS classes in the tag.
/// If there are already CSS classes on the tag then a space character and the new class will be appended to
/// the existing list.
/// </summary>
/// <param name="value">The CSS class name to add.</param>
public void AddCssClass(string value) public void AddCssClass(string value)
{ {
string currentValue; string currentValue;
@ -144,16 +164,24 @@ namespace Microsoft.AspNet.Mvc.Rendering
return stringBuffer.ToString(); return stringBuffer.ToString();
} }
public void GenerateId(string name, string idAttributeDotReplacement) /// <summary>
/// Generates a sanitized ID attribute for the tag by using the specified name.
/// </summary>
/// <param name="name">The name to use to generate an ID attribute.</param>
/// <param name="invalidCharReplacement">
/// The <see cref="string"/> (normally a single <see cref="char"/>) to substitute for invalid characters in
/// <paramref name="name"/>.
/// </param>
public void GenerateId(string name, string invalidCharReplacement)
{ {
if (idAttributeDotReplacement == null) if (invalidCharReplacement == null)
{ {
throw new ArgumentNullException(nameof(idAttributeDotReplacement)); throw new ArgumentNullException(nameof(invalidCharReplacement));
} }
if (!Attributes.ContainsKey("id")) if (!Attributes.ContainsKey("id"))
{ {
var sanitizedId = CreateSanitizedId(name, idAttributeDotReplacement); var sanitizedId = CreateSanitizedId(name, invalidCharReplacement);
if (!string.IsNullOrEmpty(sanitizedId)) if (!string.IsNullOrEmpty(sanitizedId))
{ {
Attributes["id"] = sanitizedId; Attributes["id"] = sanitizedId;

View File

@ -9,6 +9,14 @@ using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
/// <summary>
/// Specifies that the class or method that this attribute is applied validates the anti-forgery token.
/// If the anti-forgery token is not available, or if the token is invalid, the validation will fail
/// and the action method will not execute.
/// </summary>
/// <remarks>
/// This attribute helps defend against cross-site request forgery. It won't prevent other forgery or tampering attacks.
/// </remarks>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class ValidateAntiForgeryTokenAttribute : Attribute, IFilterFactory, IOrderedFilter public class ValidateAntiForgeryTokenAttribute : Attribute, IFilterFactory, IOrderedFilter
{ {

View File

@ -7,8 +7,16 @@ using Microsoft.AspNet.Mvc.Internal;
namespace Microsoft.Extensions.DependencyInjection namespace Microsoft.Extensions.DependencyInjection
{ {
/// <summary>
/// Extension methods for setting up MVC services in an <see cref="IServiceCollection" />.
/// </summary>
public static class MvcServiceCollectionExtensions public static class MvcServiceCollectionExtensions
{ {
/// <summary>
/// Adds MVC services to the specified <see cref="IServiceCollection" />.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IMvcBuilder AddMvc(this IServiceCollection services) public static IMvcBuilder AddMvc(this IServiceCollection services)
{ {
if (services == null) if (services == null)
@ -19,6 +27,12 @@ namespace Microsoft.Extensions.DependencyInjection
return AddMvc(services, setupAction: null); return AddMvc(services, setupAction: null);
} }
/// <summary>
/// Adds MVC services to the specified <see cref="IServiceCollection" />.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
/// <param name="setupAction">An action delegate to configure the provided <see cref="MvcOptions"/>.</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IMvcBuilder AddMvc(this IServiceCollection services, Action<MvcOptions> setupAction) public static IMvcBuilder AddMvc(this IServiceCollection services, Action<MvcOptions> setupAction)
{ {
if (services == null) if (services == null)

View File

@ -65,7 +65,7 @@ namespace Microsoft.AspNet.Mvc.Core.Rendering
tagBuilder.Attributes.Add("ID", "something"); tagBuilder.Attributes.Add("ID", "something");
// Act // Act
tagBuilder.GenerateId("else", idAttributeDotReplacement: "-"); tagBuilder.GenerateId("else", invalidCharReplacement: "-");
// Assert // Assert
var attribute = Assert.Single(tagBuilder.Attributes); var attribute = Assert.Single(tagBuilder.Attributes);