Fixing style issues in Mvc.Core

This commit is contained in:
Ryan Nowak 2014-06-04 20:40:12 -07:00
parent ecbc179d76
commit cf0304b897
27 changed files with 75 additions and 80 deletions

View File

@ -3,9 +3,9 @@
using System; using System;
using System.IO; using System.IO;
using System.Text;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Security.DataProtection; using Microsoft.AspNet.Security.DataProtection;
using System.Text;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Mvc
} }
} }
} }
catch(Exception ex) catch (Exception ex)
{ {
// swallow all exceptions - homogenize error if something went wrong // swallow all exceptions - homogenize error if something went wrong
innerException = ex; innerException = ex;

View File

@ -156,10 +156,10 @@ namespace Microsoft.AspNet.Mvc
Contract.Assert(_validator.IsCookieTokenValid(oldCookieToken)); Contract.Assert(_validator.IsCookieTokenValid(oldCookieToken));
AntiForgeryToken formToken = _generator. AntiForgeryToken formToken = _generator.GenerateFormToken(
GenerateFormToken(httpContext, httpContext,
ExtractIdentity(httpContext), ExtractIdentity(httpContext),
oldCookieToken); oldCookieToken);
return new AntiForgeryTokenSetInternal() return new AntiForgeryTokenSetInternal()
{ {

View File

@ -6,9 +6,9 @@ using System.Diagnostics;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts; using System.Diagnostics.Contracts;
using System.Globalization; using System.Globalization;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using Microsoft.AspNet.Security.DataProtection; using Microsoft.AspNet.Security.DataProtection;
using System.Runtime.CompilerServices;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {

View File

@ -3,10 +3,9 @@
using System; using System;
using System.Diagnostics.Contracts; using System.Diagnostics.Contracts;
using System.Security.Principal; using System.Security.Claims;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using System.Security.Claims;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -72,8 +71,7 @@ namespace Microsoft.AspNet.Mvc
{ {
// Application says user is authenticated, but we have no identifier for the user. // Application says user is authenticated, but we have no identifier for the user.
throw new InvalidOperationException( throw new InvalidOperationException(
Resources. Resources.FormatTokenValidator_AuthenticatedUserWithoutUsername(identity.GetType()));
FormatTokenValidator_AuthenticatedUserWithoutUsername(identity.GetType()));
} }
return formToken; return formToken;
@ -132,9 +130,8 @@ namespace Microsoft.AspNet.Mvc
StringComparison.Ordinal : StringComparison.Ordinal :
StringComparison.OrdinalIgnoreCase)) StringComparison.OrdinalIgnoreCase))
{ {
throw new InvalidOperationException(Resources. throw new InvalidOperationException(
FormatAntiForgeryToken_UsernameMismatch(fieldToken.Username, Resources.FormatAntiForgeryToken_UsernameMismatch(fieldToken.Username, currentUsername));
currentUsername));
} }
if (!Equals(fieldToken.ClaimUid, currentClaimUid)) if (!Equals(fieldToken.ClaimUid, currentClaimUid))

View File

@ -22,11 +22,11 @@ namespace Microsoft.AspNet.Mvc
// Iterate all the Reflected Action Descriptor providers and add area or other route constraints // Iterate all the Reflected Action Descriptor providers and add area or other route constraints
foreach (var actionDescriptor in context.Results.OfType<ReflectedActionDescriptor>()) foreach (var actionDescriptor in context.Results.OfType<ReflectedActionDescriptor>())
{ {
var routeConstraints = actionDescriptor. var routeConstraints = actionDescriptor
ControllerDescriptor. .ControllerDescriptor
ControllerTypeInfo. .ControllerTypeInfo
GetCustomAttributes<RouteConstraintAttribute>(). .GetCustomAttributes<RouteConstraintAttribute>()
ToArray(); .ToArray();
foreach (var routeConstraint in routeConstraints) foreach (var routeConstraint in routeConstraints)
{ {

View File

@ -14,5 +14,4 @@ namespace Microsoft.AspNet.Mvc
public Type ParameterType { get; private set; } public Type ParameterType { get; private set; }
} }
} }

View File

@ -314,7 +314,6 @@ namespace Microsoft.AspNet.Mvc
// Ex: These are not in the same equivalence class. // Ex: These are not in the same equivalence class.
// Action 1: constraint keys - { action, controller, area } // Action 1: constraint keys - { action, controller, area }
// Action 2: constraint keys - { action, module } // Action 2: constraint keys - { action, module }
//
private ActionDescriptor FindEquivalenceClass(ActionDescriptor[] candidates) private ActionDescriptor FindEquivalenceClass(ActionDescriptor[] candidates)
{ {
Contract.Assert(candidates.Length > 1); Contract.Assert(candidates.Length > 1);

View File

@ -5,7 +5,7 @@ using System.Reflection;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
public class DefaultControllerDescriptorFactory : IControllerDescriptorFactory public class DefaultControllerDescriptorFactory : IControllerDescriptorFactory
{ {
public ControllerDescriptor CreateControllerDescriptor(TypeInfo typeInfo) public ControllerDescriptor CreateControllerDescriptor(TypeInfo typeInfo)
{ {

View File

@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Mvc
public AuthorizeAttribute(string claimType, string claimValue) public AuthorizeAttribute(string claimType, string claimValue)
{ {
_claims = new [] { new Claim(claimType, claimValue) }; _claims = new[] { new Claim(claimType, claimValue) };
} }
public AuthorizeAttribute(string claimType, string claimValue, params string[] otherClaimValues) public AuthorizeAttribute(string claimType, string claimValue, params string[] otherClaimValues)
@ -53,9 +53,9 @@ namespace Microsoft.AspNet.Mvc
user.Identity == null || user.Identity == null ||
!user.Identity.IsAuthenticated; !user.Identity.IsAuthenticated;
if(userIsAnonymous && !HasAllowAnonymous(context)) if (userIsAnonymous && !HasAllowAnonymous(context))
{ {
base.Fail(context); Fail(context);
} }
} }
else else
@ -71,7 +71,7 @@ namespace Microsoft.AspNet.Mvc
if (!authorized) if (!authorized)
{ {
base.Fail(context); Fail(context);
} }
} }
} }

View File

@ -84,7 +84,6 @@ namespace Microsoft.AspNet.Mvc.Filters
var orderedControllerFilter = controllerFilter as IOrderedFilter; var orderedControllerFilter = controllerFilter as IOrderedFilter;
if (orderedControllerFilter != null) if (orderedControllerFilter != null)
{ {
order = orderedControllerFilter.Order; order = orderedControllerFilter.Order;
} }

View File

@ -9,7 +9,10 @@ namespace Microsoft.AspNet.Mvc
{ {
private static readonly FilterDescriptorOrderComparer _comparer = new FilterDescriptorOrderComparer(); private static readonly FilterDescriptorOrderComparer _comparer = new FilterDescriptorOrderComparer();
public static FilterDescriptorOrderComparer Comparer { get { return _comparer; } } public static FilterDescriptorOrderComparer Comparer
{
get { return _comparer; }
}
public int Compare([NotNull]FilterDescriptor x, [NotNull]FilterDescriptor y) public int Compare([NotNull]FilterDescriptor x, [NotNull]FilterDescriptor y)
{ {

View File

@ -9,7 +9,10 @@ namespace Microsoft.AspNet.Mvc
{ {
private static readonly FilterItemOrderComparer _comparer = new FilterItemOrderComparer(); private static readonly FilterItemOrderComparer _comparer = new FilterItemOrderComparer();
public static FilterItemOrderComparer Comparer { get { return _comparer; } } public static FilterItemOrderComparer Comparer
{
get { return _comparer; }
}
public int Compare([NotNull] FilterItem x, [NotNull] FilterItem y) public int Compare([NotNull] FilterItem x, [NotNull] FilterItem y)
{ {

View File

@ -3,7 +3,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -36,9 +35,10 @@ namespace Microsoft.AspNet.Mvc
/// If the object is already an <see cref="IDictionary{string, object}"/> instance, then a copy /// If the object is already an <see cref="IDictionary{string, object}"/> instance, then a copy
/// is returned. /// is returned.
/// </summary> /// </summary>
// /// <remarks>
// The implementation of PropertyHelper will cache the property accessors per-type. This is /// The implementation of PropertyHelper will cache the property accessors per-type. This is
// faster when the the same type is used multiple times with ObjectToDictionary. /// faster when the the same type is used multiple times with ObjectToDictionary.
/// </remarks>
public static IDictionary<string, object> ObjectToDictionary(object value) public static IDictionary<string, object> ObjectToDictionary(object value)
{ {
var dictionary = value as IDictionary<string, object>; var dictionary = value as IDictionary<string, object>;

View File

@ -1,4 +1,7 @@
using System.Text; // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Text;
namespace Microsoft.AspNet.Mvc.Internal namespace Microsoft.AspNet.Mvc.Internal
{ {

View File

@ -40,8 +40,7 @@ namespace Microsoft.AspNet.Mvc
new CompositeModelBinder(_modelBinders), new CompositeModelBinder(_modelBinders),
new CompositeValueProvider(valueProviders), new CompositeValueProvider(valueProviders),
_inputFormatterProvider, _inputFormatterProvider,
_validatorProviders _validatorProviders);
);
return Task.FromResult(context); return Task.FromResult(context);
} }

View File

@ -1,14 +1,13 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc.Core;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.ExceptionServices; using System.Runtime.ExceptionServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Core;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -128,11 +127,10 @@ namespace Microsoft.AspNet.Mvc
if (innerTaskType != null && typeof(Task).IsAssignableFrom(innerTaskType)) if (innerTaskType != null && typeof(Task).IsAssignableFrom(innerTaskType))
{ {
throw new InvalidOperationException( throw new InvalidOperationException(
Resources.FormatActionExecutor_WrappedTaskInstance( Resources.FormatActionExecutor_WrappedTaskInstance(
methodName, methodName,
declaringType, declaringType,
actualTypeReturned.FullName actualTypeReturned.FullName));
));
} }
} }
} }

View File

@ -281,7 +281,6 @@ namespace Microsoft.AspNet.Mvc
var inputFormatter = actionBindingContext.InputFormatterProvider.GetInputFormatter(providerContext); var inputFormatter = actionBindingContext.InputFormatterProvider.GetInputFormatter(providerContext);
var formatterContext = new InputFormatterContext(actionBindingContext.ActionContext.HttpContext, var formatterContext = new InputFormatterContext(actionBindingContext.ActionContext.HttpContext,
modelMetadata, modelMetadata,
modelState); modelState);
@ -519,7 +518,7 @@ namespace Microsoft.AspNet.Mvc
ActionMethod, ActionMethod,
ResultFilters, ResultFilters,
ActionResult ActionResult
}; }
/// <summary> /// <summary>
/// A one-way cursor for filters. /// A one-way cursor for filters.
@ -543,44 +542,44 @@ namespace Microsoft.AspNet.Mvc
/// </remarks> /// </remarks>
private struct FilterCursor private struct FilterCursor
{ {
private FilterStage Stage; private FilterStage _stage;
private int Index; private int _index;
private readonly IFilter[] Filters; private readonly IFilter[] _filters;
public FilterCursor(FilterStage stage, int index, IFilter[] filters) public FilterCursor(FilterStage stage, int index, IFilter[] filters)
{ {
Stage = stage; _stage = stage;
Index = index; _index = index;
Filters = filters; _filters = filters;
} }
public FilterCursor(IFilter[] filters) public FilterCursor(IFilter[] filters)
{ {
Stage = FilterStage.Undefined; _stage = FilterStage.Undefined;
Index = 0; _index = 0;
Filters = filters; _filters = filters;
} }
public void SetStage(FilterStage stage) public void SetStage(FilterStage stage)
{ {
Stage = stage; _stage = stage;
Index = 0; _index = 0;
} }
public FilterCursorItem<TFilter, TFilterAsync> GetNextFilter<TFilter, TFilterAsync>() public FilterCursorItem<TFilter, TFilterAsync> GetNextFilter<TFilter, TFilterAsync>()
where TFilter : class where TFilter : class
where TFilterAsync : class where TFilterAsync : class
{ {
while (Index < Filters.Length) while (_index < _filters.Length)
{ {
var filter = Filters[Index] as TFilter; var filter = _filters[_index] as TFilter;
var filterAsync = Filters[Index] as TFilterAsync; var filterAsync = _filters[_index] as TFilterAsync;
Index += 1; _index += 1;
if (filter != null || filterAsync != null) if (filter != null || filterAsync != null)
{ {
return new FilterCursorItem<TFilter, TFilterAsync>(Stage, Index, filter, filterAsync); return new FilterCursorItem<TFilter, TFilterAsync>(_stage, _index, filter, filterAsync);
} }
} }
@ -589,7 +588,7 @@ namespace Microsoft.AspNet.Mvc
public bool StillAt<TFilter, TFilterAsync>(FilterCursorItem<TFilter, TFilterAsync> current) public bool StillAt<TFilter, TFilterAsync>(FilterCursorItem<TFilter, TFilterAsync> current)
{ {
return current.Stage == Stage && current.Index == Index; return current.Stage == _stage && current.Index == _index;
} }
} }

View File

@ -76,7 +76,7 @@ namespace Microsoft.AspNet.Mvc.Rendering.Expressions
[NotNull] ViewDataDictionary viewData, [NotNull] ViewDataDictionary viewData,
IModelMetadataProvider metadataProvider) IModelMetadataProvider metadataProvider)
{ {
if(string.IsNullOrEmpty(expression)) if (string.IsNullOrEmpty(expression))
{ {
return viewData.ModelMetadata; return viewData.ModelMetadata;
} }

View File

@ -1291,7 +1291,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var modelErrors = tryGetModelStateResult ? modelState.Errors : null; var modelErrors = tryGetModelStateResult ? modelState.Errors : null;
ModelError modelError = null; ModelError modelError = null;
if(modelErrors != null && modelErrors.Count != 0) if (modelErrors != null && modelErrors.Count != 0)
{ {
modelError = modelErrors.FirstOrDefault(m => !string.IsNullOrEmpty(m.ErrorMessage)) ?? modelErrors[0]; modelError = modelErrors.FirstOrDefault(m => !string.IsNullOrEmpty(m.ErrorMessage)) ?? modelErrors[0];
} }

View File

@ -98,12 +98,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
public HtmlString DisplayNameForInnerType<TInnerModel, TValue>( public HtmlString DisplayNameForInnerType<TInnerModel, TValue>(
[NotNull] Expression<Func<TInnerModel, TValue>> expression) [NotNull] Expression<Func<TInnerModel, TValue>> expression)
{ {
var metadata = ExpressionMetadataProvider. var metadata = ExpressionMetadataProvider.FromLambdaExpression<TInnerModel, TValue>(
FromLambdaExpression<TInnerModel, TValue>( expression,
expression, new ViewDataDictionary<TInnerModel>(MetadataProvider),
new ViewDataDictionary<TInnerModel>( MetadataProvider);
MetadataProvider),
MetadataProvider);
var expressionText = ExpressionHelper.GetExpressionText(expression); var expressionText = ExpressionHelper.GetExpressionText(expression);
if (metadata == null) if (metadata == null)
{ {

View File

@ -125,7 +125,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
private IEnumerable<string> GetViewNames() private IEnumerable<string> GetViewNames()
{ {
var metadata = _viewData.ModelMetadata; var metadata = _viewData.ModelMetadata;
var templateHints = new string[] { var templateHints = new string[]
{
_templateName, _templateName,
metadata.TemplateHint, metadata.TemplateHint,
metadata.DataTypeName metadata.DataTypeName

View File

@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns> /// <returns>
/// The display name for the model. /// The display name for the model.
/// </returns> /// </returns>
public static HtmlString DisplayNameFor<TInnerModel,TValue>( public static HtmlString DisplayNameFor<TInnerModel, TValue>(
[NotNull] this IHtmlHelper<IEnumerable<TInnerModel>> htmlHelper, [NotNull] this IHtmlHelper<IEnumerable<TInnerModel>> htmlHelper,
[NotNull] Expression<Func<TInnerModel, TValue>> expression) [NotNull] Expression<Func<TInnerModel, TValue>> expression)
{ {

View File

@ -197,7 +197,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
public static HtmlString TextArea([NotNull] this IHtmlHelper htmlHelper, public static HtmlString TextArea([NotNull] this IHtmlHelper htmlHelper,
string name, object htmlAttributes) string name, object htmlAttributes)
{ {
return htmlHelper.TextArea(name, value: null, rows: 0, columns:0, htmlAttributes: htmlAttributes); return htmlHelper.TextArea(name, value: null, rows: 0, columns: 0, htmlAttributes: htmlAttributes);
} }
public static HtmlString TextArea([NotNull] this IHtmlHelper htmlHelper, public static HtmlString TextArea([NotNull] this IHtmlHelper htmlHelper,

View File

@ -4,8 +4,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.ModelBinding;
namespace Microsoft.AspNet.Mvc.Rendering namespace Microsoft.AspNet.Mvc.Rendering
{ {

View File

@ -66,7 +66,6 @@ namespace Microsoft.AspNet.Mvc
result = await InvokeAsyncCore(asyncMethod, context.ViewContext); result = await InvokeAsyncCore(asyncMethod, context.ViewContext);
} }
await result.ExecuteAsync(context); await result.ExecuteAsync(context);
} }

View File

@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Mvc
var components = var components =
types types
.Where(ViewComponentConventions.IsComponent) .Where(ViewComponentConventions.IsComponent)
.Select(c => new {Name = ViewComponentConventions.GetComponentName(c), Type = c.AsType()}); .Select(c => new { Name = ViewComponentConventions.GetComponentName(c), Type = c.AsType() });
var matching = var matching =
components components

View File

@ -22,7 +22,6 @@ namespace Microsoft.AspNet.Mvc.Core.Test
#pragma warning disable 1998 #pragma warning disable 1998
public async Task<int> TaskValueTypeAction(int i, string s) public async Task<int> TaskValueTypeAction(int i, string s)
{ {
Console.WriteLine(s);
return i; return i;
} }
#pragma warning restore 1998 #pragma warning restore 1998
@ -59,13 +58,11 @@ namespace Microsoft.AspNet.Mvc.Core.Test
public TaskDerivedType TaskActionWithCustomTaskReturnType(int i, string s) public TaskDerivedType TaskActionWithCustomTaskReturnType(int i, string s)
{ {
Console.WriteLine(s);
return new TaskDerivedType(); return new TaskDerivedType();
} }
public TaskOfTDerivedType<int> TaskActionWithCustomTaskOfTReturnType(int i, string s) public TaskOfTDerivedType<int> TaskActionWithCustomTaskOfTReturnType(int i, string s)
{ {
Console.WriteLine(s);
return new TaskOfTDerivedType<int>(1); return new TaskOfTDerivedType<int>(1);
} }