diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Binders/DictionaryModelBinder.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Binders/DictionaryModelBinder.cs index 5053327371..53cea8a8d0 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Binders/DictionaryModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Binders/DictionaryModelBinder.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding IEnumerable> incomingElements, Func> creator) { - IDictionary dictionary = bindingContext.Model as IDictionary; + var dictionary = bindingContext.Model as IDictionary; if (dictionary == null || dictionary.IsReadOnly) { dictionary = creator(); diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Internal/DictionaryHelper.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Internal/DictionaryHelper.cs index 080d662583..1ca0e3fb11 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Internal/DictionaryHelper.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Internal/DictionaryHelper.cs @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Internal } else { - char charAfterPrefix = key[prefix.Length]; + var charAfterPrefix = key[prefix.Length]; switch (charAfterPrefix) { case '[': diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/AssociatedMetadataProvider.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/AssociatedMetadataProvider.cs index 3f8e065e3e..e2c5e2d4da 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/AssociatedMetadataProvider.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/AssociatedMetadataProvider.cs @@ -67,7 +67,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding Func modelAccessor = null; if (container != null) { - Func propertyGetter = propertyInfo.ValueAccessor; + var propertyGetter = propertyInfo.ValueAccessor; modelAccessor = () => propertyGetter(container); } yield return CreatePropertyMetadata(modelAccessor, propertyInfo); diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/ModelMetadata.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/ModelMetadata.cs index 2e6d883444..65a407d70e 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/ModelMetadata.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Metadata/ModelMetadata.cs @@ -185,17 +185,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding return PropertyName ?? ModelType.Name; } - // TODO: Revive ModelValidators - //public virtual IEnumerable GetValidators(IEnumerable validatorProviders) - //{ - // if (validatorProviders == null) - // { - // throw Error.ArgumentNull("validatorProviders"); - // } - - // return validatorProviders.SelectMany(provider => provider.GetValidators(this, validatorProviders)); - //} - protected virtual string ComputeSimpleDisplayText() { if (Model == null) @@ -228,10 +217,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding return Convert.ToString(firstProperty.Model, CultureInfo.CurrentCulture); } - private static EfficientTypePropertyKey CreateCacheKey(Type containerType, Type modelType, string propertyName) + private static EfficientTypePropertyKey CreateCacheKey(Type containerType, + Type modelType, + string propertyName) { // If metadata is for a property then containerType != null && propertyName != null - // If metadata is for a type then containerType == null && propertyName == null, so we have to use modelType for the cache key. + // If metadata is for a type then containerType == null && propertyName == null, + // so we have to use modelType for the cache key. return new EfficientTypePropertyKey(containerType ?? modelType, propertyName); } } diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/AssociatedValidatorProvider.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/AssociatedValidatorProvider.cs index ed69b97a4f..d86ce02d09 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/AssociatedValidatorProvider.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/AssociatedValidatorProvider.cs @@ -25,8 +25,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding private IEnumerable GetValidatorsForProperty(ModelMetadata metadata) { var propertyName = metadata.PropertyName; + var bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase; var property = metadata.ContainerType - .GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); + .GetProperty(propertyName, bindingFlags); if (property == null) { diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/CompareAttributeAdapter.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/CompareAttributeAdapter.cs index e173128410..6e74b9f017 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/CompareAttributeAdapter.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/CompareAttributeAdapter.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding { var errorMessage = ((CompareAttributeWrapper)Attribute).FormatErrorMessage(context); var clientRule = new ModelClientValidationEqualToRule(errorMessage, - FormatPropertyForClientValidation(Attribute.OtherProperty)); + FormatPropertyForClientValidation(Attribute.OtherProperty)); return new[] { clientRule }; } @@ -58,9 +58,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding private string GetOtherPropertyDisplayName(ClientModelValidationContext context) { - // The System.ComponentModel.DataAnnotations.CompareAttribute doesn't populate the OtherPropertyDisplayName - // until after IsValid() is called. Therefore, by the time we get the error message for client validation, - // the display name is not populated and won't be used. + // The System.ComponentModel.DataAnnotations.CompareAttribute doesn't populate the + // OtherPropertyDisplayName until after IsValid() is called. Therefore, by the time we get + // the error message for client validation, the display name is not populated and won't be used. var metadata = context.ModelMetadata; var otherPropertyDisplayName = OtherPropertyDisplayName; if (otherPropertyDisplayName == null && metadata.ContainerType != null) diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/CompositeModelValidator.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/CompositeModelValidator.cs index 9ce7126697..0f3355c093 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/CompositeModelValidator.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/CompositeModelValidator.cs @@ -50,7 +50,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } } - private static ModelValidationResult CreateSubPropertyResult(ModelMetadata propertyMetadata, ModelValidationResult propertyResult) + private static ModelValidationResult CreateSubPropertyResult(ModelMetadata propertyMetadata, + ModelValidationResult propertyResult) { return new ModelValidationResult(propertyMetadata.PropertyName + '.' + propertyResult.MemberName, propertyResult.Message); diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/DataAnnotationsModelValidator.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/DataAnnotationsModelValidator.cs index bc67e85c4a..40bd110474 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/DataAnnotationsModelValidator.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/DataAnnotationsModelValidator.cs @@ -37,13 +37,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var result = Attribute.GetValidationResult(metadata.Model, context); if (result != ValidationResult.Success) { - // ModelValidationResult.MemberName is used by invoking validators (such as ModelValidator) to - // construct the ModelKey for ModelStateDictionary. When validating at type level we want to append the - // returned MemberNames if specified (e.g. person.Address.FirstName). For property validation, the - // ModelKey can be constructed using the ModelMetadata and we should ignore MemberName (we don't want - // (person.Name.Name). However the invoking validator does not have a way to distinguish between these two - // cases. Consequently we'll only set MemberName if this validation returns a MemberName that is different - // from the property being validated. + // ModelValidationResult.MemberName is used by invoking validators (such as ModelValidator) to + // construct the ModelKey for ModelStateDictionary. When validating at type level we want to append + // the returned MemberNames if specified (e.g. person.Address.FirstName). For property validation, the + // ModelKey can be constructed using the ModelMetadata and we should ignore MemberName (we don't want + // (person.Name.Name). However the invoking validator does not have a way to distinguish between these + // two cases. Consequently we'll only set MemberName if this validation returns a MemberName that is + // different from the property being validated. var errorMemberName = result.MemberNames.FirstOrDefault(); if (string.Equals(errorMemberName, memberName, StringComparison.Ordinal)) diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/DataAnnotationsModelValidatorProvider.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/DataAnnotationsModelValidatorProvider.cs index 4608916473..d0ad00e8f1 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/DataAnnotationsModelValidatorProvider.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/DataAnnotationsModelValidatorProvider.cs @@ -48,7 +48,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding set { _addImplicitRequiredAttributeForValueTypes = value; } } - protected override IEnumerable GetValidators(ModelMetadata metadata, IEnumerable attributes) + protected override IEnumerable GetValidators(ModelMetadata metadata, + IEnumerable attributes) { var results = new List(); @@ -104,9 +105,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding return dict; } - private static void AddValidationAttributeAdapter(Dictionary dictionary, - Type validationAttributeType, - DataAnnotationsModelValidationFactory factory) + private static void AddValidationAttributeAdapter( + Dictionary dictionary, + Type validationAttributeType, + DataAnnotationsModelValidationFactory factory) { if (validationAttributeType != null) { @@ -114,9 +116,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } } - private static void AddDataTypeAttributeAdapter(Dictionary dictionary, - Type attributeType, - string ruleName) + private static void AddDataTypeAttributeAdapter( + Dictionary dictionary, + Type attributeType, + string ruleName) { AddValidationAttributeAdapter( dictionary, diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/DataMemberModelValidatorProvider.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/DataMemberModelValidatorProvider.cs index 7f12b5e00c..059816c1c3 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/DataMemberModelValidatorProvider.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/DataMemberModelValidatorProvider.cs @@ -10,7 +10,8 @@ using System.Runtime.Serialization; namespace Microsoft.AspNet.Mvc.ModelBinding { /// - /// This provides a required ModelValidator for members marked as [DataMember(IsRequired=true)]. + /// This provides a required ModelValidator for members marked + /// as [DataMember(IsRequired=true)]. /// public class DataMemberModelValidatorProvider : AssociatedValidatorProvider { @@ -38,10 +39,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding if (dataMemberAttribute != null) { // isDataContract == true iff the container type has at least one DataContractAttribute - bool isDataContract = containerType.GetTypeInfo() - .GetCustomAttributes() - .OfType() - .Any(); + var isDataContract = containerType.GetTypeInfo() + .GetCustomAttributes() + .OfType() + .Any(); if (isDataContract && dataMemberAttribute.IsRequired) { return true; diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/ValueProviders/QueryStringValueProviderFactory.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/ValueProviders/QueryStringValueProviderFactory.cs index fe9e88b4f7..563392e432 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/ValueProviders/QueryStringValueProviderFactory.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/ValueProviders/QueryStringValueProviderFactory.cs @@ -1,8 +1,8 @@ // 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 Microsoft.AspNet.Routing; using System.Globalization; +using Microsoft.AspNet.Routing; namespace Microsoft.AspNet.Mvc.ModelBinding { diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/ValueProviders/ValueProviderResult.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/ValueProviders/ValueProviderResult.cs index a5cc95d77a..a0d2ddbf04 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/ValueProviders/ValueProviderResult.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/ValueProviders/ValueProviderResult.cs @@ -108,7 +108,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding if (valueAsArray != null) { // case 1: both destination + source type are arrays, so convert each element - IList converted = Array.CreateInstance(destinationElementType, valueAsArray.Length); + var converted = (IList)Array.CreateInstance(destinationElementType, valueAsArray.Length); for (var i = 0; i < valueAsArray.Length; i++) { converted[i] = ConvertSimpleType(culture, valueAsArray.GetValue(i), destinationElementType); @@ -117,9 +117,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } else { - // case 2: destination type is array but source is single element, so wrap element in array + convert + // case 2: destination type is array but source is single element, so wrap element in + // array + convert var element = ConvertSimpleType(culture, value, destinationElementType); - IList converted = Array.CreateInstance(destinationElementType, 1); + var converted = (IList)Array.CreateInstance(destinationElementType, 1); converted[0] = element; return converted; } diff --git a/src/Microsoft.AspNet.Mvc.Razor/AttributeValue.cs b/src/Microsoft.AspNet.Mvc.Razor/AttributeValue.cs index d760bba2d3..af86176c21 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/AttributeValue.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/AttributeValue.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics.CodeAnalysis; namespace Microsoft.AspNet.Mvc.Razor { @@ -21,25 +20,23 @@ namespace Microsoft.AspNet.Mvc.Razor public bool Literal { get; private set; } - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "We are using tuples here to avoid dependencies from Razor to WebPages")] public static AttributeValue FromTuple(Tuple, Tuple, bool> value) { return new AttributeValue(value.Item1, value.Item2, value.Item3); } - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "We are using tuples here to avoid dependencies from Razor to WebPages")] public static AttributeValue FromTuple(Tuple, Tuple, bool> value) { - return new AttributeValue(value.Item1, new PositionTagged(value.Item2.Item1, value.Item2.Item2), value.Item3); + return new AttributeValue(value.Item1, + new PositionTagged(value.Item2.Item1, value.Item2.Item2), + value.Item3); } - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "We are using tuples here to avoid dependencies from Razor to WebPages")] public static implicit operator AttributeValue(Tuple, Tuple, bool> value) { return FromTuple(value); } - [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "We are using tuples here to avoid dependencies from Razor to WebPages")] public static implicit operator AttributeValue(Tuple, Tuple, bool> value) { return FromTuple(value); diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilerCache.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilerCache.cs index 33de68f858..bdc1884c0e 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilerCache.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilerCache.cs @@ -19,12 +19,12 @@ namespace Microsoft.AspNet.Mvc.Razor public CompilationResult GetOrAdd(IFileInfo file, Func compile) { // Generate a content id - string contentId = file.PhysicalPath + '|' + file.LastModified.Ticks; + var contentId = file.PhysicalPath + '|' + file.LastModified.Ticks; Type compiledType; if (!_cache.TryGetValue(contentId, out compiledType)) { - CompilationResult result = compile(); + var result = compile(); _cache.TryAdd(contentId, result.CompiledType); return result; diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs index a01d73190e..460bb806ec 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs @@ -2,23 +2,23 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Collections.Concurrent; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; -using System.Threading.Tasks; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Emit; using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.Emit; using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.Mvc.Razor.Compilation { public class RoslynCompilationService : ICompilationService { - private static readonly ConcurrentDictionary _metadataFileCache = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); - + private static readonly ConcurrentDictionary _metadataFileCache = + new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + private readonly ILibraryManager _libraryManager; private readonly IApplicationEnvironment _environment; private readonly IAssemblyLoaderEngine _loader; @@ -50,13 +50,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation { using (var pdb = new MemoryStream()) { - EmitResult result = null; + EmitResult result; if (PlatformHelper.IsMono) { result = compilation.Emit(ms, pdbStream: null); } - else + else { result = compilation.Emit(ms, pdbStream: pdb); } @@ -65,12 +65,15 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation { var formatter = new DiagnosticFormatter(); - var messages = result.Diagnostics.Where(IsError).Select(d => GetCompilationMessage(formatter, d)).ToList(); + var messages = result.Diagnostics + .Where(IsError) + .Select(d => GetCompilationMessage(formatter, d)) + .ToList(); return CompilationResult.Failed(content, messages); } - Assembly assembly = null; + Assembly assembly; ms.Seek(0, SeekOrigin.Begin); if (PlatformHelper.IsMono) @@ -86,7 +89,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation var type = assembly.GetExportedTypes() .First(); - return CompilationResult.Successful(String.Empty, type); + return CompilationResult.Successful(string.Empty, type); } } } @@ -121,7 +124,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation private MetadataReference CreateMetadataFileReference(string path) { - return _metadataFileCache.GetOrAdd(path, _ => + return _metadataFileCache.GetOrAdd(path, _ => { // TODO: What about access to the file system? We need to be able to // read files from anywhere on disk, not just under the web root diff --git a/src/Microsoft.AspNet.Mvc.Razor/Extensions/DictionaryExtensions.cs b/src/Microsoft.AspNet.Mvc.Razor/Extensions/DictionaryExtensions.cs index 9352c456d3..d80489a366 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Extensions/DictionaryExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Extensions/DictionaryExtensions.cs @@ -7,7 +7,8 @@ namespace System.Collections.Generic { internal static class DictionaryExtensions { - public static T GetValueOrDefault([NotNull] this IDictionary dictionary, [NotNull] string key) + public static T GetValueOrDefault([NotNull] this IDictionary dictionary, + [NotNull] string key) { object valueAsObject; if (dictionary.TryGetValue(key, out valueAsObject)) diff --git a/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorCompilationService.cs b/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorCompilationService.cs index c5fff474ec..461ba34304 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorCompilationService.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorCompilationService.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Mvc.Razor _appRoot = EnsureTrailingSlash(environment.ApplicationBasePath); } - public CompilationResult Compile([NotNull]IFileInfo file) + public CompilationResult Compile([NotNull] IFileInfo file) { return _cache.GetOrAdd(file, () => CompileCore(file)); } @@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Mvc.Razor public CompilationResult CompileCore(IFileInfo file) { GeneratorResults results; - using (Stream inputStream = file.CreateReadStream()) + using (var inputStream = file.CreateReadStream()) { Contract.Assert(file.PhysicalPath.StartsWith(_appRoot, StringComparison.OrdinalIgnoreCase)); var rootRelativePath = file.PhysicalPath.Substring(_appRoot.Length); diff --git a/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs b/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs index e7ce1f7c7e..d00497374c 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs @@ -159,7 +159,6 @@ namespace Microsoft.AspNet.Mvc.Razor if (helperResult != null) { helperResult.WriteTo(writer); - } else { @@ -203,8 +202,8 @@ namespace Microsoft.AspNet.Mvc.Razor PositionTagged suffix, params AttributeValue[] values) { - bool first = true; - bool wroteSomething = false; + var first = true; + var wroteSomething = false; if (values.Length == 0) { // Explicitly empty attribute, so write the prefix and suffix @@ -213,11 +212,11 @@ namespace Microsoft.AspNet.Mvc.Razor } else { - for (int i = 0; i < values.Length; i++) + for (var i = 0; i < values.Length; i++) { - AttributeValue attrVal = values[i]; - PositionTagged val = attrVal.Value; - PositionTagged next = i == values.Length - 1 ? + var attrVal = values[i]; + var val = attrVal.Value; + var next = i == values.Length - 1 ? suffix : // End of the list, grab the suffix values[i + 1].Prefix; // Still in the list, grab the next prefix @@ -228,12 +227,11 @@ namespace Microsoft.AspNet.Mvc.Razor } // The special cases here are that the value we're writing might already be a string, or that the - // 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 HtmlString), and we'll ask it to format itself. + // 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 HtmlString) and we'll ask it to format itself. string stringValue; - bool? boolValue = val.Value as bool?; + var boolValue = val.Value as bool?; if (boolValue == true) { stringValue = name; @@ -258,7 +256,7 @@ namespace Microsoft.AspNet.Mvc.Razor } // Calculate length of the source span by the position of the next value (or suffix) - int sourceLength = next.Position - attrVal.Value.Position; + var sourceLength = next.Position - attrVal.Value.Position; if (attrVal.Literal) { @@ -360,7 +358,8 @@ namespace Microsoft.AspNet.Mvc.Razor { if (BodyContent != null) { - var sectionsNotRendered = PreviousSectionWriters.Keys.Except(_renderedSections, StringComparer.OrdinalIgnoreCase); + var sectionsNotRendered = PreviousSectionWriters.Keys.Except(_renderedSections, + StringComparer.OrdinalIgnoreCase); if (sectionsNotRendered.Any()) { var sectionNames = String.Join(", ", sectionsNotRendered); diff --git a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs index 59a2094d66..42f1ca483d 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs @@ -89,7 +89,6 @@ namespace Microsoft.AspNet.Mvc.Razor private static bool IsSpecificPath(string name) { - char c = name[0]; return name[0] == '~' || name[0] == '/'; } @@ -109,8 +108,7 @@ namespace Microsoft.AspNet.Mvc.Razor } var formattedPaths = unformattedPaths.Select(path => - string.Format(CultureInfo.InvariantCulture, path, viewName, controllerName, areaName) - ); + string.Format(CultureInfo.InvariantCulture, path, viewName, controllerName, areaName)); return formattedPaths; } diff --git a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/VirtualPathViewFactory.cs b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/VirtualPathViewFactory.cs index ab6bfc4dd0..68869beb93 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/VirtualPathViewFactory.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/VirtualPathViewFactory.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Threading.Tasks; using Microsoft.AspNet.FileSystems; using Microsoft.AspNet.Mvc.Rendering; using Microsoft.Framework.DependencyInjection; @@ -34,7 +33,7 @@ namespace Microsoft.AspNet.Mvc.Razor IFileInfo fileInfo; if (_fileSystem.TryGetFileInfo(virtualPath, out fileInfo)) { - CompilationResult result = _compilationService.Compile(fileInfo); + var result = _compilationService.Compile(fileInfo); return (IView)_activator.CreateInstance(_serviceProvider, result.CompiledType); }