Replace NotNullAttribute with thrown exceptions
This commit is contained in:
parent
ef730790d4
commit
a68d9e4cb1
|
|
@ -5,7 +5,6 @@ using System;
|
|||
using System.Linq;
|
||||
using Microsoft.AspNet.Mvc.Razor.Host;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||
{
|
||||
|
|
@ -25,9 +24,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
/// <returns>The <paramref name="chunk"/> cast to <typeparamref name="TChunk"/>.</returns>
|
||||
/// <exception cref="ArgumentException"><paramref name="chunk"/> is not an instance of
|
||||
/// <typeparamref name="TChunk"/>.</exception>
|
||||
public static TChunk EnsureChunk<TChunk>([NotNull] Chunk chunk)
|
||||
public static TChunk EnsureChunk<TChunk>(Chunk chunk)
|
||||
where TChunk : Chunk
|
||||
{
|
||||
if (chunk == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chunk));
|
||||
}
|
||||
|
||||
var chunkOfT = chunk as TChunk;
|
||||
if (chunkOfT == null)
|
||||
{
|
||||
|
|
@ -45,8 +49,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
/// <param name="chunkTree">The <see cref="ChunkTree"/> to scan for <see cref="ModelChunk"/>s in.</param>
|
||||
/// <returns>The last <see cref="ModelChunk"/> in the <see cref="ChunkTree"/> if found, <c>null</c> otherwise.
|
||||
/// </returns>
|
||||
public static ModelChunk GetModelChunk([NotNull] ChunkTree chunkTree)
|
||||
public static ModelChunk GetModelChunk(ChunkTree chunkTree)
|
||||
{
|
||||
if (chunkTree == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chunkTree));
|
||||
}
|
||||
|
||||
// If there's more than 1 model chunk there will be a Razor error BUT we want intellisense to show up on
|
||||
// the current model chunk that the user is typing.
|
||||
return chunkTree
|
||||
|
|
@ -63,9 +72,19 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
/// <param name="defaultModelName">The <see cref="Type"/> name of the default model.</param>
|
||||
/// <returns>The model type name for the generated page.</returns>
|
||||
public static string GetModelTypeName(
|
||||
[NotNull] ChunkTree chunkTree,
|
||||
[NotNull] string defaultModelName)
|
||||
ChunkTree chunkTree,
|
||||
string defaultModelName)
|
||||
{
|
||||
if (chunkTree == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chunkTree));
|
||||
}
|
||||
|
||||
if (defaultModelName == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(defaultModelName));
|
||||
}
|
||||
|
||||
var modelChunk = GetModelChunk(chunkTree);
|
||||
return modelChunk != null ? modelChunk.ModelType : defaultModelName;
|
||||
}
|
||||
|
|
@ -77,9 +96,20 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
/// <param name="value">The string to replace the token in.</param>
|
||||
/// <param name="modelName">The model name to replace with.</param>
|
||||
/// <returns>A string with the token replaced.</returns>
|
||||
public static string ReplaceTModel([NotNull] string value,
|
||||
[NotNull] string modelName)
|
||||
public static string ReplaceTModel(
|
||||
string value,
|
||||
string modelName)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
if (modelName == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(modelName));
|
||||
}
|
||||
|
||||
return value.Replace(TModelToken, modelName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ using Microsoft.AspNet.FileProviders;
|
|||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Razor.Parser;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||
{
|
||||
|
|
@ -30,10 +29,25 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
/// </param>
|
||||
/// <param name="defaultInheritedChunks">Sequence of <see cref="Chunk"/>s inherited by default.</param>
|
||||
public ChunkInheritanceUtility(
|
||||
[NotNull] MvcRazorHost razorHost,
|
||||
[NotNull] IChunkTreeCache chunkTreeCache,
|
||||
[NotNull] IReadOnlyList<Chunk> defaultInheritedChunks)
|
||||
MvcRazorHost razorHost,
|
||||
IChunkTreeCache chunkTreeCache,
|
||||
IReadOnlyList<Chunk> defaultInheritedChunks)
|
||||
{
|
||||
if (razorHost == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(razorHost));
|
||||
}
|
||||
|
||||
if (chunkTreeCache == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chunkTreeCache));
|
||||
}
|
||||
|
||||
if (defaultInheritedChunks == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(defaultInheritedChunks));
|
||||
}
|
||||
|
||||
_razorHost = razorHost;
|
||||
_defaultInheritedChunks = defaultInheritedChunks;
|
||||
_chunkTreeCache = chunkTreeCache;
|
||||
|
|
@ -49,8 +63,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
/// <param name="pagePath">The path of the page to locate inherited chunks for.</param>
|
||||
/// <returns>A <see cref="IReadOnlyList{ChunkTreeResult}"/> of parsed <c>_ViewImports</c>
|
||||
/// <see cref="ChunkTree"/>s and their file paths.</returns>
|
||||
public virtual IReadOnlyList<ChunkTreeResult> GetInheritedChunkTreeResults([NotNull] string pagePath)
|
||||
public virtual IReadOnlyList<ChunkTreeResult> GetInheritedChunkTreeResults(string pagePath)
|
||||
{
|
||||
if (pagePath == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(pagePath));
|
||||
}
|
||||
|
||||
var inheritedChunkTreeResults = new List<ChunkTreeResult>();
|
||||
var templateEngine = new RazorTemplateEngine(_razorHost);
|
||||
foreach (var viewImportsPath in ViewHierarchyUtility.GetViewImportsLocations(pagePath))
|
||||
|
|
@ -85,10 +104,20 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
/// files.</param>
|
||||
/// <param name="defaultModel">The list of chunks to merge.</param>
|
||||
public void MergeInheritedChunkTrees(
|
||||
[NotNull] ChunkTree chunkTree,
|
||||
[NotNull] IReadOnlyList<ChunkTree> inheritedChunkTrees,
|
||||
ChunkTree chunkTree,
|
||||
IReadOnlyList<ChunkTree> inheritedChunkTrees,
|
||||
string defaultModel)
|
||||
{
|
||||
if (chunkTree == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chunkTree));
|
||||
}
|
||||
|
||||
if (inheritedChunkTrees == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(inheritedChunkTrees));
|
||||
}
|
||||
|
||||
var mergerMappings = GetMergerMappings(chunkTree, defaultModel);
|
||||
IChunkMerger merger;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||
{
|
||||
|
|
@ -17,8 +17,18 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
/// <param name="chunkTree">The <see cref="AspNet.Razor.Chunks.ChunkTree"/> generated from the file at the
|
||||
/// given <paramref name="filePath"/>.</param>
|
||||
/// <param name="filePath">The path to the file that generated the given <paramref name="chunkTree"/>.</param>
|
||||
public ChunkTreeResult([NotNull] ChunkTree chunkTree, [NotNull] string filePath)
|
||||
public ChunkTreeResult(ChunkTree chunkTree, string filePath)
|
||||
{
|
||||
if (chunkTree == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chunkTree));
|
||||
}
|
||||
|
||||
if (filePath == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(filePath));
|
||||
}
|
||||
|
||||
ChunkTree = chunkTree;
|
||||
FilePath = filePath;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ using System;
|
|||
using Microsoft.AspNet.FileProviders;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.Framework.Caching.Memory;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||
{
|
||||
|
|
@ -41,9 +40,19 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
|
||||
/// <inheritdoc />
|
||||
public ChunkTree GetOrAdd(
|
||||
[NotNull] string pagePath,
|
||||
[NotNull] Func<IFileInfo, ChunkTree> getChunkTree)
|
||||
string pagePath,
|
||||
Func<IFileInfo, ChunkTree> getChunkTree)
|
||||
{
|
||||
if (pagePath == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(pagePath));
|
||||
}
|
||||
|
||||
if (getChunkTree == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(getChunkTree));
|
||||
}
|
||||
|
||||
ChunkTree chunkTree;
|
||||
if (!_chunkTreeCache.TryGetValue(pagePath, out chunkTree))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||
{
|
||||
|
|
@ -20,22 +19,42 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
/// Initializes a new instance of <see cref="InjectChunkMerger"/>.
|
||||
/// </summary>
|
||||
/// <param name="modelType">The model type to be used to replace <TModel> tokens.</param>
|
||||
public InjectChunkMerger([NotNull] string modelType)
|
||||
public InjectChunkMerger(string modelType)
|
||||
{
|
||||
if (modelType == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(modelType));
|
||||
}
|
||||
|
||||
_modelType = "<" + modelType + ">";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void VisitChunk([NotNull] Chunk chunk)
|
||||
public void VisitChunk(Chunk chunk)
|
||||
{
|
||||
if (chunk == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chunk));
|
||||
}
|
||||
|
||||
var injectChunk = ChunkHelper.EnsureChunk<InjectChunk>(chunk);
|
||||
injectChunk.TypeName = ChunkHelper.ReplaceTModel(injectChunk.TypeName, _modelType);
|
||||
_addedMemberNames.Add(injectChunk.MemberName);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Merge([NotNull] ChunkTree chunkTree, [NotNull] Chunk chunk)
|
||||
public void Merge(ChunkTree chunkTree, Chunk chunk)
|
||||
{
|
||||
if (chunkTree == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chunkTree));
|
||||
}
|
||||
|
||||
if (chunk == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chunk));
|
||||
}
|
||||
|
||||
var injectChunk = ChunkHelper.EnsureChunk<InjectChunk>(chunk);
|
||||
if (!_addedMemberNames.Contains(injectChunk.MemberName))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||
{
|
||||
|
|
@ -24,16 +24,31 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void VisitChunk([NotNull] Chunk chunk)
|
||||
public void VisitChunk(Chunk chunk)
|
||||
{
|
||||
if (chunk == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chunk));
|
||||
}
|
||||
|
||||
var setBaseTypeChunk = ChunkHelper.EnsureChunk<SetBaseTypeChunk>(chunk);
|
||||
setBaseTypeChunk.TypeName = ChunkHelper.ReplaceTModel(setBaseTypeChunk.TypeName, _modelType);
|
||||
_isBaseTypeSet = true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Merge([NotNull] ChunkTree chunkTree, [NotNull] Chunk chunk)
|
||||
public void Merge(ChunkTree chunkTree, Chunk chunk)
|
||||
{
|
||||
if (chunkTree == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chunkTree));
|
||||
}
|
||||
|
||||
if (chunk == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chunk));
|
||||
}
|
||||
|
||||
if (!_isBaseTypeSet)
|
||||
{
|
||||
var baseTypeChunk = ChunkHelper.EnsureChunk<SetBaseTypeChunk>(chunk);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Directives
|
||||
{
|
||||
|
|
@ -16,15 +15,30 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives
|
|||
private readonly HashSet<string> _currentUsings = new HashSet<string>(StringComparer.Ordinal);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void VisitChunk([NotNull] Chunk chunk)
|
||||
public void VisitChunk(Chunk chunk)
|
||||
{
|
||||
if (chunk == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chunk));
|
||||
}
|
||||
|
||||
var namespaceChunk = ChunkHelper.EnsureChunk<UsingChunk>(chunk);
|
||||
_currentUsings.Add(namespaceChunk.Namespace);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Merge([NotNull] ChunkTree chunkTree, [NotNull] Chunk chunk)
|
||||
public void Merge(ChunkTree chunkTree, Chunk chunk)
|
||||
{
|
||||
if (chunkTree == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chunkTree));
|
||||
}
|
||||
|
||||
if (chunk == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chunk));
|
||||
}
|
||||
|
||||
var namespaceChunk = ChunkHelper.EnsureChunk<UsingChunk>(chunk);
|
||||
|
||||
if (!_currentUsings.Contains(namespaceChunk.Namespace))
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// 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 Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -12,18 +12,38 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
private readonly string _injectAttribute;
|
||||
|
||||
public InjectChunkVisitor([NotNull] CSharpCodeWriter writer,
|
||||
[NotNull] CodeGeneratorContext context,
|
||||
[NotNull] string injectAttributeName)
|
||||
public InjectChunkVisitor(CSharpCodeWriter writer,
|
||||
CodeGeneratorContext context,
|
||||
string injectAttributeName)
|
||||
: base(writer, context)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (injectAttributeName == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(injectAttributeName));
|
||||
}
|
||||
|
||||
_injectAttribute = "[" + injectAttributeName + "]";
|
||||
}
|
||||
|
||||
public IList<InjectChunk> InjectChunks { get; } = new List<InjectChunk>();
|
||||
|
||||
protected override void Visit([NotNull] InjectChunk chunk)
|
||||
protected override void Visit(InjectChunk chunk)
|
||||
{
|
||||
if (chunk == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chunk));
|
||||
}
|
||||
|
||||
Writer.WriteLine(_injectAttribute);
|
||||
|
||||
// Some of the chunks that we visit are either InjectDescriptors that are added by default or
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Internal
|
||||
{
|
||||
|
|
@ -11,13 +10,23 @@ namespace Microsoft.AspNet.Mvc.Razor.Internal
|
|||
{
|
||||
private readonly string _applicationRoot;
|
||||
|
||||
public DesignTimeRazorPathNormalizer([NotNull] string applicationRoot)
|
||||
public DesignTimeRazorPathNormalizer(string applicationRoot)
|
||||
{
|
||||
if (applicationRoot == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(applicationRoot));
|
||||
}
|
||||
|
||||
_applicationRoot = applicationRoot;
|
||||
}
|
||||
|
||||
public override string NormalizePath([NotNull] string path)
|
||||
public override string NormalizePath(string path)
|
||||
{
|
||||
if (path == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(path));
|
||||
}
|
||||
|
||||
// Need to convert path to application relative (rooted paths are passed in during design time).
|
||||
if (Path.IsPathRooted(path) && path.StartsWith(_applicationRoot, StringComparison.Ordinal))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,14 +1,19 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.Framework.Internal;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Internal
|
||||
{
|
||||
public class RazorPathNormalizer
|
||||
{
|
||||
public virtual string NormalizePath([NotNull] string path)
|
||||
public virtual string NormalizePath(string path)
|
||||
{
|
||||
if (path == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(path));
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,28 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
public class ModelChunkVisitor : MvcCSharpCodeVisitor
|
||||
{
|
||||
public ModelChunkVisitor(
|
||||
[NotNull] CSharpCodeWriter writer,
|
||||
[NotNull] CodeGeneratorContext context)
|
||||
CSharpCodeWriter writer,
|
||||
CodeGeneratorContext context)
|
||||
: base(writer, context)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Visit(ModelChunk chunk)
|
||||
|
|
|
|||
|
|
@ -1,19 +1,27 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.Razor.Chunks;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
public abstract class MvcCSharpChunkVisitor : CodeVisitor<CSharpCodeWriter>
|
||||
{
|
||||
public MvcCSharpChunkVisitor([NotNull] CSharpCodeWriter writer,
|
||||
[NotNull] CodeGeneratorContext context)
|
||||
public MvcCSharpChunkVisitor(CSharpCodeWriter writer,
|
||||
CodeGeneratorContext context)
|
||||
: base(writer, context)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
}
|
||||
|
||||
public override void Accept(Chunk chunk)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNet.Mvc.Razor.Directives;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators.Visitors;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -16,12 +16,32 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
private readonly string _injectAttribute;
|
||||
|
||||
public MvcCSharpCodeGenerator(
|
||||
[NotNull] CodeGeneratorContext context,
|
||||
[NotNull] string defaultModel,
|
||||
[NotNull] string injectAttribute,
|
||||
[NotNull] GeneratedTagHelperAttributeContext tagHelperAttributeContext)
|
||||
CodeGeneratorContext context,
|
||||
string defaultModel,
|
||||
string injectAttribute,
|
||||
GeneratedTagHelperAttributeContext tagHelperAttributeContext)
|
||||
: base(context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (defaultModel == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(defaultModel));
|
||||
}
|
||||
|
||||
if (injectAttribute == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(injectAttribute));
|
||||
}
|
||||
|
||||
if (tagHelperAttributeContext == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tagHelperAttributeContext));
|
||||
}
|
||||
|
||||
_tagHelperAttributeContext = tagHelperAttributeContext;
|
||||
_defaultModel = defaultModel;
|
||||
_injectAttribute = injectAttribute;
|
||||
|
|
@ -30,9 +50,19 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
private string Model { get; set; }
|
||||
|
||||
protected override CSharpCodeVisitor CreateCSharpCodeVisitor(
|
||||
[NotNull] CSharpCodeWriter writer,
|
||||
[NotNull] CodeGeneratorContext context)
|
||||
CSharpCodeWriter writer,
|
||||
CodeGeneratorContext context)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
var csharpCodeVisitor = base.CreateCSharpCodeVisitor(writer, context);
|
||||
|
||||
csharpCodeVisitor.TagHelperRenderer.AttributeValueCodeRenderer =
|
||||
|
|
@ -67,8 +97,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
}
|
||||
}
|
||||
|
||||
protected override void BuildConstructor([NotNull] CSharpCodeWriter writer)
|
||||
protected override void BuildConstructor(CSharpCodeWriter writer)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
|
||||
base.BuildConstructor(writer);
|
||||
|
||||
writer.WriteLineHiddenDirective();
|
||||
|
|
|
|||
|
|
@ -1,23 +1,33 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
public abstract class MvcCSharpCodeVisitor : MvcCSharpChunkVisitor
|
||||
{
|
||||
public MvcCSharpCodeVisitor(
|
||||
[NotNull] CSharpCodeWriter writer,
|
||||
[NotNull] CodeGeneratorContext context)
|
||||
CSharpCodeWriter writer,
|
||||
CodeGeneratorContext context)
|
||||
: base(writer, context)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Visit(InjectChunk chunk)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Visit(ModelChunk chunk)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// 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.IO;
|
||||
using System.Linq;
|
||||
|
|
@ -15,7 +16,6 @@ using Microsoft.AspNet.Razor.CodeGenerators;
|
|||
using Microsoft.AspNet.Razor.Parser;
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
using Microsoft.AspNet.Razor.TagHelpers;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -151,9 +151,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
|
||||
return _tagHelperDescriptorResolver;
|
||||
}
|
||||
[param: NotNull]
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
_tagHelperDescriptorResolver = value;
|
||||
}
|
||||
}
|
||||
|
|
@ -231,8 +235,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// </summary>
|
||||
/// <param name="sourceFileName">The path to a Razor file to locate _ViewImports.cshtml for.</param>
|
||||
/// <returns>Inherited <see cref="ChunkTreeResult"/>s.</returns>
|
||||
public IReadOnlyList<ChunkTreeResult> GetInheritedChunkTreeResults([NotNull] string sourceFileName)
|
||||
public IReadOnlyList<ChunkTreeResult> GetInheritedChunkTreeResults(string sourceFileName)
|
||||
{
|
||||
if (sourceFileName == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(sourceFileName));
|
||||
}
|
||||
|
||||
// Need the normalized path to resolve inherited chunks only. Full paths are needed for generated Razor
|
||||
// files checksum and line pragmas to enable DesignTime debugging.
|
||||
var normalizedPath = _pathNormalizer.NormalizePath(sourceFileName);
|
||||
|
|
@ -250,24 +259,44 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override RazorParser DecorateRazorParser([NotNull] RazorParser razorParser, string sourceFileName)
|
||||
public override RazorParser DecorateRazorParser(RazorParser razorParser, string sourceFileName)
|
||||
{
|
||||
if (razorParser == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(razorParser));
|
||||
}
|
||||
|
||||
var inheritedChunkTrees = GetInheritedChunkTrees(sourceFileName);
|
||||
|
||||
return new MvcRazorParser(razorParser, inheritedChunkTrees, DefaultInheritedChunks, ModelExpressionType);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ParserBase DecorateCodeParser([NotNull] ParserBase incomingCodeParser)
|
||||
public override ParserBase DecorateCodeParser(ParserBase incomingCodeParser)
|
||||
{
|
||||
if (incomingCodeParser == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(incomingCodeParser));
|
||||
}
|
||||
|
||||
return new MvcRazorCodeParser(_baseType);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override CodeGenerator DecorateCodeGenerator(
|
||||
[NotNull] CodeGenerator incomingGenerator,
|
||||
[NotNull] CodeGeneratorContext context)
|
||||
CodeGenerator incomingGenerator,
|
||||
CodeGeneratorContext context)
|
||||
{
|
||||
if (incomingGenerator == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(incomingGenerator));
|
||||
}
|
||||
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
var inheritedChunkTrees = GetInheritedChunkTrees(context.SourceFile);
|
||||
|
||||
ChunkInheritanceUtility.MergeInheritedChunkTrees(
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ using Microsoft.AspNet.Razor.Parser;
|
|||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||
using Microsoft.AspNet.Razor.Parser.TagHelpers;
|
||||
using Microsoft.AspNet.Razor.TagHelpers;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -33,12 +32,32 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <param name="defaultInheritedChunks">The <see cref="IReadOnlyList{Chunk}"/> inherited by
|
||||
/// default by all Razor pages in the application.</param>
|
||||
public MvcRazorParser(
|
||||
[NotNull] RazorParser parser,
|
||||
[NotNull] IReadOnlyList<ChunkTree> inheritedChunkTrees,
|
||||
[NotNull] IReadOnlyList<Chunk> defaultInheritedChunks,
|
||||
[NotNull] string modelExpressionTypeName)
|
||||
RazorParser parser,
|
||||
IReadOnlyList<ChunkTree> inheritedChunkTrees,
|
||||
IReadOnlyList<Chunk> defaultInheritedChunks,
|
||||
string modelExpressionTypeName)
|
||||
: base(parser)
|
||||
{
|
||||
if (parser == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(parser));
|
||||
}
|
||||
|
||||
if (inheritedChunkTrees == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(inheritedChunkTrees));
|
||||
}
|
||||
|
||||
if (defaultInheritedChunks == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(defaultInheritedChunks));
|
||||
}
|
||||
|
||||
if (modelExpressionTypeName == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(modelExpressionTypeName));
|
||||
}
|
||||
|
||||
// Construct tag helper descriptors from @addTagHelper, @removeTagHelper and @tagHelperPrefix chunks
|
||||
_viewImportsDirectiveDescriptors = GetTagHelperDirectiveDescriptors(
|
||||
inheritedChunkTrees,
|
||||
|
|
@ -49,9 +68,19 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
|
||||
/// <inheritdoc />
|
||||
protected override IEnumerable<TagHelperDescriptor> GetTagHelperDescriptors(
|
||||
[NotNull] Block documentRoot,
|
||||
[NotNull] ErrorSink errorSink)
|
||||
Block documentRoot,
|
||||
ErrorSink errorSink)
|
||||
{
|
||||
if (documentRoot == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(documentRoot));
|
||||
}
|
||||
|
||||
if (errorSink == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(errorSink));
|
||||
}
|
||||
|
||||
var visitor = new ViewImportsTagHelperDirectiveSpanVisitor(
|
||||
TagHelperDescriptorResolver,
|
||||
_viewImportsDirectiveDescriptors,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
using System;
|
||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.AspNet.Razor.TagHelpers;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -19,8 +18,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// Instantiates a new instance of <see cref="MvcTagHelperAttributeValueCodeRenderer"/>.
|
||||
/// </summary>
|
||||
/// <param name="context">Contains code generation information for rendering attribute values.</param>
|
||||
public MvcTagHelperAttributeValueCodeRenderer([NotNull] GeneratedTagHelperAttributeContext context)
|
||||
public MvcTagHelperAttributeValueCodeRenderer(GeneratedTagHelperAttributeContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
_context = context;
|
||||
}
|
||||
|
||||
|
|
@ -30,12 +34,32 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// created by calling into <see cref="GeneratedTagHelperAttributeContext.CreateModelExpressionMethodName"/>.
|
||||
/// </remarks>
|
||||
public override void RenderAttributeValue(
|
||||
[NotNull] TagHelperAttributeDescriptor attributeDescriptor,
|
||||
[NotNull] CSharpCodeWriter writer,
|
||||
[NotNull] CodeGeneratorContext codeGeneratorContext,
|
||||
[NotNull] Action<CSharpCodeWriter> renderAttributeValue,
|
||||
TagHelperAttributeDescriptor attributeDescriptor,
|
||||
CSharpCodeWriter writer,
|
||||
CodeGeneratorContext codeGeneratorContext,
|
||||
Action<CSharpCodeWriter> renderAttributeValue,
|
||||
bool complexValue)
|
||||
{
|
||||
if (attributeDescriptor == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(attributeDescriptor));
|
||||
}
|
||||
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
|
||||
if (codeGeneratorContext == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(codeGeneratorContext));
|
||||
}
|
||||
|
||||
if (renderAttributeValue == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(renderAttributeValue));
|
||||
}
|
||||
|
||||
if (attributeDescriptor.TypeName.Equals(_context.ModelExpressionTypeName, StringComparison.Ordinal))
|
||||
{
|
||||
writer
|
||||
|
|
|
|||
|
|
@ -12,8 +12,7 @@
|
|||
"Microsoft.AspNet.FileProviders.Physical": "1.0.0-*",
|
||||
"Microsoft.AspNet.Razor.Runtime": "4.0.0-*",
|
||||
"Microsoft.Framework.Caching.Memory": "1.0.0-*",
|
||||
"Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" },
|
||||
"Microsoft.Framework.NotNullAttribute.Sources": { "version": "1.0.0-*", "type": "build" }
|
||||
"Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" }
|
||||
},
|
||||
"frameworks": {
|
||||
"net45": { },
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Dnx.Compilation;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||
{
|
||||
|
|
@ -20,9 +19,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
|||
/// <param name="compilationFailures"><see cref="CompilationFailure"/>s containing
|
||||
/// details of the compilation failure.</param>
|
||||
public CompilationFailedException(
|
||||
[NotNull] IEnumerable<CompilationFailure> compilationFailures)
|
||||
IEnumerable<CompilationFailure> compilationFailures)
|
||||
: base(FormatMessage(compilationFailures))
|
||||
{
|
||||
if (compilationFailures == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(compilationFailures));
|
||||
}
|
||||
|
||||
CompilationFailures = compilationFailures;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.Dnx.Compilation;
|
||||
using Microsoft.Dnx.Compilation.CSharp;
|
||||
using Microsoft.Dnx.Runtime;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||
{
|
||||
|
|
@ -25,9 +25,19 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
|||
/// </param>
|
||||
/// <returns>The <see cref="CompilationSettings"/> for the current application.</returns>
|
||||
public static CompilationSettings GetCompilationSettings(
|
||||
[NotNull] this ICompilerOptionsProvider compilerOptionsProvider,
|
||||
[NotNull] IApplicationEnvironment applicationEnvironment)
|
||||
this ICompilerOptionsProvider compilerOptionsProvider,
|
||||
IApplicationEnvironment applicationEnvironment)
|
||||
{
|
||||
if (compilerOptionsProvider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(compilerOptionsProvider));
|
||||
}
|
||||
|
||||
if (applicationEnvironment == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(applicationEnvironment));
|
||||
}
|
||||
|
||||
return compilerOptionsProvider.GetCompilerOptions(applicationEnvironment.ApplicationName,
|
||||
applicationEnvironment.RuntimeFramework,
|
||||
applicationEnvironment.Configuration)
|
||||
|
|
|
|||
|
|
@ -3,9 +3,6 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Dnx.Runtime;
|
||||
using Microsoft.Dnx.Compilation;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||
|
|
@ -61,8 +58,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
|||
/// <param name="compilationFailures"><see cref="CompilationFailure"/>s produced from parsing or
|
||||
/// compiling the Razor file.</param>
|
||||
/// <returns>A <see cref="CompilationResult"/> instance for a failed compilation.</returns>
|
||||
public static CompilationResult Failed([NotNull] IEnumerable<CompilationFailure> compilationFailures)
|
||||
public static CompilationResult Failed(IEnumerable<CompilationFailure> compilationFailures)
|
||||
{
|
||||
if (compilationFailures == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(compilationFailures));
|
||||
}
|
||||
|
||||
return new CompilationResult
|
||||
{
|
||||
CompilationFailures = compilationFailures
|
||||
|
|
@ -74,8 +76,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
|||
/// </summary>
|
||||
/// <param name="type">The compiled type.</param>
|
||||
/// <returns>A <see cref="CompilationResult"/> instance for a successful compilation.</returns>
|
||||
public static CompilationResult Successful([NotNull] Type type)
|
||||
public static CompilationResult Successful(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(type));
|
||||
}
|
||||
|
||||
return new CompilationResult
|
||||
{
|
||||
CompiledType = type
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ using System.Diagnostics;
|
|||
using System.Text;
|
||||
using Microsoft.AspNet.FileProviders;
|
||||
using Microsoft.Framework.Caching.Memory;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||
{
|
||||
|
|
@ -27,8 +26,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
|||
/// Initializes a new instance of <see cref="CompilerCache"/>.
|
||||
/// </summary>
|
||||
/// <param name="fileProvider"><see cref="IFileProvider"/> used to locate Razor views.</param>
|
||||
public CompilerCache([NotNull] IFileProvider fileProvider)
|
||||
public CompilerCache(IFileProvider fileProvider)
|
||||
{
|
||||
if (fileProvider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileProvider));
|
||||
}
|
||||
|
||||
_fileProvider = fileProvider;
|
||||
_cache = new MemoryCache(new MemoryCacheOptions { CompactOnMemoryPressure = false });
|
||||
}
|
||||
|
|
@ -41,10 +45,20 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
|||
/// <param name="precompiledViews">A mapping of application relative paths of view to the precompiled view
|
||||
/// <see cref="Type"/>s.</param>
|
||||
public CompilerCache(
|
||||
[NotNull] IFileProvider fileProvider,
|
||||
[NotNull] IDictionary<string, Type> precompiledViews)
|
||||
IFileProvider fileProvider,
|
||||
IDictionary<string, Type> precompiledViews)
|
||||
: this(fileProvider)
|
||||
{
|
||||
if (fileProvider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileProvider));
|
||||
}
|
||||
|
||||
if (precompiledViews == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(precompiledViews));
|
||||
}
|
||||
|
||||
foreach (var item in precompiledViews)
|
||||
{
|
||||
var cacheEntry = new CompilerCacheResult(CompilationResult.Successful(item.Value));
|
||||
|
|
@ -54,9 +68,19 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
|||
|
||||
/// <inheritdoc />
|
||||
public CompilerCacheResult GetOrAdd(
|
||||
[NotNull] string relativePath,
|
||||
[NotNull] Func<RelativeFileInfo, CompilationResult> compile)
|
||||
string relativePath,
|
||||
Func<RelativeFileInfo, CompilationResult> compile)
|
||||
{
|
||||
if (relativePath == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(relativePath));
|
||||
}
|
||||
|
||||
if (compile == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(compile));
|
||||
}
|
||||
|
||||
CompilerCacheResult cacheResult;
|
||||
// Attempt to lookup the cache entry using the passed in path. This will succeed if the path is already
|
||||
// normalized and a cache entry exists.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.Framework.Internal;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||
{
|
||||
|
|
@ -21,8 +21,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
|||
/// <see cref="CompilationResult"/>.
|
||||
/// </summary>
|
||||
/// <param name="compilationResult">The <see cref="Compilation.CompilationResult"/> </param>
|
||||
public CompilerCacheResult([NotNull] CompilationResult compilationResult)
|
||||
public CompilerCacheResult(CompilationResult compilationResult)
|
||||
{
|
||||
if (compilationResult == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(compilationResult));
|
||||
}
|
||||
|
||||
CompilationResult = compilationResult;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||
{
|
||||
|
|
@ -18,7 +17,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
|||
/// <param name="relativePath">Application relative path to the file.</param>
|
||||
/// <param name="compile">An delegate that will generate a compilation result.</param>
|
||||
/// <returns>A cached <see cref="CompilationResult"/>.</returns>
|
||||
CompilerCacheResult GetOrAdd([NotNull] string relativePath,
|
||||
[NotNull] Func<RelativeFileInfo, CompilationResult> compile);
|
||||
CompilerCacheResult GetOrAdd(
|
||||
string relativePath,
|
||||
Func<RelativeFileInfo, CompilationResult> compile);
|
||||
}
|
||||
}
|
||||
|
|
@ -10,7 +10,6 @@ using Microsoft.AspNet.Razor;
|
|||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.Dnx.Compilation;
|
||||
using Microsoft.Dnx.Runtime;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||
|
|
@ -43,8 +42,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public CompilationResult Compile([NotNull] RelativeFileInfo file)
|
||||
public CompilationResult Compile(RelativeFileInfo file)
|
||||
{
|
||||
if (file == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(file));
|
||||
}
|
||||
|
||||
GeneratorResults results;
|
||||
using (var inputStream = file.FileInfo.CreateReadStream())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
using System;
|
||||
using Microsoft.AspNet.FileProviders;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||
{
|
||||
|
|
@ -18,8 +17,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
|||
/// </summary>
|
||||
/// <param name="fileInfo"><see cref="IFileInfo"/> for the file.</param>
|
||||
/// <param name="relativePath">Path of the file relative to the application base.</param>
|
||||
public RelativeFileInfo([NotNull] IFileInfo fileInfo, string relativePath)
|
||||
public RelativeFileInfo(IFileInfo fileInfo, string relativePath)
|
||||
{
|
||||
if (fileInfo == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileInfo));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(relativePath))
|
||||
{
|
||||
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(relativePath));
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ using Microsoft.CodeAnalysis.Emit;
|
|||
using Microsoft.Dnx.Compilation;
|
||||
using Microsoft.Dnx.Compilation.CSharp;
|
||||
using Microsoft.Dnx.Runtime;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||
|
|
@ -69,8 +68,18 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public CompilationResult Compile([NotNull] RelativeFileInfo fileInfo, [NotNull] string compilationContent)
|
||||
public CompilationResult Compile(RelativeFileInfo fileInfo, string compilationContent)
|
||||
{
|
||||
if (fileInfo == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileInfo));
|
||||
}
|
||||
|
||||
if (compilationContent == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(compilationContent));
|
||||
}
|
||||
|
||||
var assemblyName = Path.GetRandomFileName();
|
||||
var compilationSettings = _compilerOptionsProvider.GetCompilationSettings(_environment);
|
||||
var syntaxTree = SyntaxTreeGenerator.Generate(compilationContent,
|
||||
|
|
|
|||
|
|
@ -1,21 +1,37 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using Microsoft.Dnx.Compilation.CSharp;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||
{
|
||||
public static class SyntaxTreeGenerator
|
||||
{
|
||||
public static SyntaxTree Generate([NotNull] string text,
|
||||
[NotNull] string path,
|
||||
[NotNull] CompilationSettings compilationSettings)
|
||||
public static SyntaxTree Generate(
|
||||
string text,
|
||||
string path,
|
||||
CompilationSettings compilationSettings)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
|
||||
if (path == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(path));
|
||||
}
|
||||
|
||||
if (compilationSettings == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(compilationSettings));
|
||||
}
|
||||
|
||||
var sourceText = SourceText.From(text, Encoding.UTF8);
|
||||
var syntaxTree = CSharpSyntaxTree.ParseText(sourceText,
|
||||
path: path,
|
||||
|
|
|
|||
|
|
@ -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 Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||
{
|
||||
|
|
@ -24,9 +23,20 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
|||
/// <param name="compiledContent">The generated C# content that was compiled.</param>
|
||||
/// <returns>An <see cref="UncachedCompilationResult"/> instance that indicates a successful
|
||||
/// compilation.</returns>
|
||||
public static UncachedCompilationResult Successful([NotNull] Type type,
|
||||
[NotNull] string compiledContent)
|
||||
public static UncachedCompilationResult Successful(
|
||||
Type type,
|
||||
string compiledContent)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(type));
|
||||
}
|
||||
|
||||
if (compiledContent == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(compiledContent));
|
||||
}
|
||||
|
||||
return new UncachedCompilationResult
|
||||
{
|
||||
CompiledType = type,
|
||||
|
|
|
|||
|
|
@ -28,14 +28,24 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
_getPropertiesToActivate = type =>
|
||||
PropertyActivator<ViewContext>.GetPropertiesToActivate(
|
||||
type,
|
||||
typeof(ViewContextAttribute),
|
||||
typeof(ViewContextAttribute),
|
||||
CreateActivateInfo);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Activate<TTagHelper>([NotNull] TTagHelper tagHelper, [NotNull] ViewContext context)
|
||||
public void Activate<TTagHelper>(TTagHelper tagHelper, ViewContext context)
|
||||
where TTagHelper : ITagHelper
|
||||
{
|
||||
if (tagHelper == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tagHelper));
|
||||
}
|
||||
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
var propertiesToActivate = _injectActions.GetOrAdd(
|
||||
tagHelper.GetType(),
|
||||
_getPropertiesToActivate);
|
||||
|
|
|
|||
|
|
@ -26,8 +26,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ViewLocationCacheResult Get([NotNull] ViewLocationExpanderContext context)
|
||||
public ViewLocationCacheResult Get(ViewLocationExpanderContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
var cacheKey = GenerateKey(context, copyViewExpanderValues: false);
|
||||
ViewLocationCacheResult result;
|
||||
if (_cache.TryGetValue(cacheKey, out result))
|
||||
|
|
@ -40,9 +45,14 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
|
||||
/// <inheritdoc />
|
||||
public void Set(
|
||||
[NotNull] ViewLocationExpanderContext context,
|
||||
[NotNull] ViewLocationCacheResult value)
|
||||
ViewLocationExpanderContext context,
|
||||
ViewLocationCacheResult value)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
var cacheKey = GenerateKey(context, copyViewExpanderValues: true);
|
||||
_cache.TryAdd(cacheKey, value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,13 +4,11 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.Razor;
|
||||
using Microsoft.AspNet.Mvc.Razor.Compilation;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
using Microsoft.Framework.DependencyInjection.Extensions;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.Framework.DependencyInjection
|
||||
{
|
||||
|
|
@ -26,9 +24,19 @@ namespace Microsoft.Framework.DependencyInjection
|
|||
/// <param name="setupAction">An action to configure the <see cref="RazorViewEngineOptions"/>.</param>
|
||||
/// <returns>The <see cref="IMvcBuilder"/>.</returns>
|
||||
public static IMvcBuilder AddRazorOptions(
|
||||
[NotNull] this IMvcBuilder builder,
|
||||
[NotNull] Action<RazorViewEngineOptions> setupAction)
|
||||
this IMvcBuilder builder,
|
||||
Action<RazorViewEngineOptions> setupAction)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
if (setupAction == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(setupAction));
|
||||
}
|
||||
|
||||
builder.Services.Configure(setupAction);
|
||||
return builder;
|
||||
}
|
||||
|
|
@ -45,10 +53,20 @@ namespace Microsoft.Framework.DependencyInjection
|
|||
/// <param name="initialize">An action to initialize the <typeparamref name="TTagHelper"/>.</param>
|
||||
/// <returns>The <see cref="IMvcBuilder"/> instance this method extends.</returns>
|
||||
public static IMvcBuilder InitializeTagHelper<TTagHelper>(
|
||||
[NotNull] this IMvcBuilder builder,
|
||||
[NotNull] Action<TTagHelper, ViewContext> initialize)
|
||||
this IMvcBuilder builder,
|
||||
Action<TTagHelper, ViewContext> initialize)
|
||||
where TTagHelper : ITagHelper
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
if (initialize == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(initialize));
|
||||
}
|
||||
|
||||
var initializer = new TagHelperInitializer<TTagHelper>(initialize);
|
||||
|
||||
builder.Services.AddInstance(typeof(ITagHelperInitializer<TTagHelper>), initializer);
|
||||
|
|
@ -57,9 +75,19 @@ namespace Microsoft.Framework.DependencyInjection
|
|||
}
|
||||
|
||||
public static IMvcBuilder AddPrecompiledRazorViews(
|
||||
[NotNull] this IMvcBuilder builder,
|
||||
[NotNull] params Assembly[] assemblies)
|
||||
this IMvcBuilder builder,
|
||||
params Assembly[] assemblies)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
if (assemblies == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(assemblies));
|
||||
}
|
||||
|
||||
builder.Services.Replace(
|
||||
ServiceDescriptor.Singleton<ICompilerCacheProvider>(serviceProvider =>
|
||||
ActivatorUtilities.CreateInstance<PrecompiledViewsCompilerCacheProvider>(
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
|
@ -13,24 +13,38 @@ using Microsoft.AspNet.Mvc.Rendering;
|
|||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
using Microsoft.Framework.Caching.Memory;
|
||||
using Microsoft.Framework.DependencyInjection.Extensions;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
|
||||
namespace Microsoft.Framework.DependencyInjection
|
||||
{
|
||||
public static class MvcRazorMvcCoreBuilderExtensions
|
||||
{
|
||||
public static IMvcCoreBuilder AddRazorViewEngine([NotNull] this IMvcCoreBuilder builder)
|
||||
public static IMvcCoreBuilder AddRazorViewEngine(this IMvcCoreBuilder builder)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
builder.AddViews();
|
||||
AddRazorViewEngineServices(builder.Services);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static IMvcCoreBuilder AddRazorViewEngine(
|
||||
[NotNull] this IMvcCoreBuilder builder,
|
||||
[NotNull] Action<RazorViewEngineOptions> setupAction)
|
||||
this IMvcCoreBuilder builder,
|
||||
Action<RazorViewEngineOptions> setupAction)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
if (setupAction == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(setupAction));
|
||||
}
|
||||
|
||||
builder.AddViews();
|
||||
AddRazorViewEngineServices(builder.Services);
|
||||
|
||||
|
|
@ -43,9 +57,19 @@ namespace Microsoft.Framework.DependencyInjection
|
|||
}
|
||||
|
||||
public static IMvcCoreBuilder AddPrecompiledRazorViews(
|
||||
[NotNull] this IMvcCoreBuilder builder,
|
||||
[NotNull] params Assembly[] assemblies)
|
||||
this IMvcCoreBuilder builder,
|
||||
params Assembly[] assemblies)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
if (assemblies == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(assemblies));
|
||||
}
|
||||
|
||||
AddRazorViewEngine(builder);
|
||||
|
||||
builder.Services.Replace(
|
||||
|
|
@ -69,10 +93,20 @@ namespace Microsoft.Framework.DependencyInjection
|
|||
/// <param name="initialize">An action to initialize the <typeparamref name="TTagHelper"/>.</param>
|
||||
/// <returns>The <see cref="IMvcCoreBuilder"/> instance this method extends.</returns>
|
||||
public static IMvcCoreBuilder InitializeTagHelper<TTagHelper>(
|
||||
[NotNull] this IMvcCoreBuilder builder,
|
||||
[NotNull] Action<TTagHelper, ViewContext> initialize)
|
||||
this IMvcCoreBuilder builder,
|
||||
Action<TTagHelper, ViewContext> initialize)
|
||||
where TTagHelper : ITagHelper
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
if (initialize == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(initialize));
|
||||
}
|
||||
|
||||
var initializer = new TagHelperInitializer<TTagHelper>(initialize);
|
||||
|
||||
builder.Services.AddInstance(typeof(ITagHelperInitializer<TTagHelper>), initializer);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ using System;
|
|||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Html.Abstractions;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.WebEncoders;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
|
|
@ -24,8 +23,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <see cref="WriteTo(TextWriter, IHtmlEncoder)"/> is called.</param>
|
||||
/// <remarks>Calls to <see cref="WriteTo(TextWriter, IHtmlEncoder)"/> result in a blocking invocation of
|
||||
/// <paramref name="asyncAction"/>.</remarks>
|
||||
public HelperResult([NotNull] Func<TextWriter, Task> asyncAction)
|
||||
public HelperResult(Func<TextWriter, Task> asyncAction)
|
||||
{
|
||||
if (asyncAction == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(asyncAction));
|
||||
}
|
||||
|
||||
_asyncAction = asyncAction;
|
||||
}
|
||||
|
||||
|
|
@ -42,8 +46,18 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter"/> instance to write to.</param>
|
||||
/// <param name="encoder">The <see cref="IHtmlEncoder"/> to encode the content.</param>
|
||||
public virtual void WriteTo([NotNull] TextWriter writer, [NotNull] IHtmlEncoder encoder)
|
||||
public virtual void WriteTo(TextWriter writer, IHtmlEncoder encoder)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
|
||||
if (encoder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(encoder));
|
||||
}
|
||||
|
||||
_asyncAction(writer).GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Mvc.ViewEngines;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -19,6 +18,6 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <param name="page">The <see cref="IRazorPage"/> instance to execute.</param>
|
||||
/// <param name="isPartial">Determines if the view is to be executed as a partial.</param>
|
||||
/// <returns>A <see cref="IView"/> instance that renders the contents of the <paramref name="page"/></returns>
|
||||
IView GetView([NotNull] IRazorViewEngine viewEngine, [NotNull] IRazorPage page, bool isPartial);
|
||||
IView GetView(IRazorViewEngine viewEngine, IRazorPage page, bool isPartial);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -19,6 +18,6 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// </summary>
|
||||
/// <param name="helper">The <typeparamref name="TTagHelper"/> to initialize.</param>
|
||||
/// <param name="context">The <see cref="ViewContext"/> for the executing view.</param>
|
||||
void Initialize([NotNull] TTagHelper helper, [NotNull] ViewContext context);
|
||||
void Initialize(TTagHelper helper, ViewContext context);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Internal
|
||||
|
|
@ -28,9 +27,19 @@ namespace Microsoft.AspNet.Mvc.Razor.Internal
|
|||
/// <param name="serviceProvider">The application's <see cref="IServiceProvider"/>.</param>
|
||||
/// <param name="options">The <see cref="MvcViewOptions"/> to configure.</param>
|
||||
public static void ConfigureMvc(
|
||||
[NotNull] IServiceProvider serviceProvider,
|
||||
[NotNull] MvcViewOptions options)
|
||||
IServiceProvider serviceProvider,
|
||||
MvcViewOptions options)
|
||||
{
|
||||
if (serviceProvider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(serviceProvider));
|
||||
}
|
||||
|
||||
if (options == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
|
||||
var razorViewEngine = serviceProvider.GetRequiredService<IRazorViewEngine>();
|
||||
options.ViewEngines.Add(razorViewEngine);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using Microsoft.AspNet.Mvc.Razor.Precompilation;
|
||||
using Microsoft.Dnx.Runtime;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Internal
|
||||
{
|
||||
|
|
@ -19,8 +19,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Internal
|
|||
/// </summary>
|
||||
/// <param name="fileInfoCollection">The <see cref="RazorFileInfoCollection"/>.</param>
|
||||
/// <returns></returns>
|
||||
public static string GenerateCode([NotNull] RazorFileInfoCollection fileInfoCollection)
|
||||
public static string GenerateCode(RazorFileInfoCollection fileInfoCollection)
|
||||
{
|
||||
if (fileInfoCollection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileInfoCollection));
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.Append(
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -45,8 +43,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void PopulateValues([NotNull] ViewLocationExpanderContext context)
|
||||
public void PopulateValues(ViewLocationExpanderContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
// Using CurrentUICulture so it loads the locale specific resources for the views.
|
||||
#if DNX451
|
||||
context.Values[ValueKey] = Thread.CurrentThread.CurrentUICulture.Name;
|
||||
|
|
@ -57,9 +60,19 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
|
||||
/// <inheritdoc />
|
||||
public virtual IEnumerable<string> ExpandViewLocations(
|
||||
[NotNull] ViewLocationExpanderContext context,
|
||||
[NotNull] IEnumerable<string> viewLocations)
|
||||
ViewLocationExpanderContext context,
|
||||
IEnumerable<string> viewLocations)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (viewLocations == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(viewLocations));
|
||||
}
|
||||
|
||||
string value;
|
||||
context.Values.TryGetValue(ValueKey, out value);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,16 +6,31 @@ using System.Linq;
|
|||
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Precompilation
|
||||
{
|
||||
public static class GeneratorResultExtensions
|
||||
{
|
||||
public static string GetMainClassName([NotNull] this GeneratorResults results,
|
||||
[NotNull] IMvcRazorHost host,
|
||||
[NotNull] SyntaxTree syntaxTree)
|
||||
public static string GetMainClassName(
|
||||
this GeneratorResults results,
|
||||
IMvcRazorHost host,
|
||||
SyntaxTree syntaxTree)
|
||||
{
|
||||
if (results == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(results));
|
||||
}
|
||||
|
||||
if (host == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(host));
|
||||
}
|
||||
|
||||
if (syntaxTree == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(syntaxTree));
|
||||
}
|
||||
|
||||
// The mainClass name should return directly from the generator results.
|
||||
var classes = syntaxTree.GetRoot().DescendantNodes().OfType<ClassDeclarationSyntax>();
|
||||
var mainClass = classes.FirstOrDefault(c =>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// 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 Microsoft.CodeAnalysis;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Precompilation
|
||||
{
|
||||
|
|
@ -17,9 +17,20 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation
|
|||
/// </summary>
|
||||
/// <param name="fileInfo">The <see cref="RazorFileInfo"/> of the file being cached.</param>
|
||||
/// <param name="syntaxTree">The <see cref="CodeAnalysis.SyntaxTree"/> to cache.</param>
|
||||
public PrecompilationCacheEntry([NotNull] RazorFileInfo fileInfo,
|
||||
[NotNull] SyntaxTree syntaxTree)
|
||||
public PrecompilationCacheEntry(
|
||||
RazorFileInfo fileInfo,
|
||||
SyntaxTree syntaxTree)
|
||||
{
|
||||
if (fileInfo == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileInfo));
|
||||
}
|
||||
|
||||
if (syntaxTree == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(syntaxTree));
|
||||
}
|
||||
|
||||
FileInfo = fileInfo;
|
||||
SyntaxTree = syntaxTree;
|
||||
}
|
||||
|
|
@ -30,8 +41,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation
|
|||
/// <param name="diagnostics">The <see cref="IReadOnlyList{Diagnostic}"/> produced from parsing the Razor
|
||||
/// file. This does not contain <see cref="Diagnostic"/>s produced from compiling the parsed
|
||||
/// <see cref="CodeAnalysis.SyntaxTree"/>.</param>
|
||||
public PrecompilationCacheEntry([NotNull] IReadOnlyList<Diagnostic> diagnostics)
|
||||
public PrecompilationCacheEntry(IReadOnlyList<Diagnostic> diagnostics)
|
||||
{
|
||||
if (diagnostics == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(diagnostics));
|
||||
}
|
||||
|
||||
Diagnostics = diagnostics;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,14 +5,23 @@ using System;
|
|||
using Microsoft.AspNet.Razor;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Precompilation
|
||||
{
|
||||
public static class RazorErrorExtensions
|
||||
{
|
||||
public static Diagnostic ToDiagnostics([NotNull] this RazorError error, [NotNull] string filePath)
|
||||
public static Diagnostic ToDiagnostics(this RazorError error, string filePath)
|
||||
{
|
||||
if (error == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(error));
|
||||
}
|
||||
|
||||
if (filePath == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(filePath));
|
||||
}
|
||||
|
||||
var descriptor = new DiagnosticDescriptor(
|
||||
id: "Razor",
|
||||
title: "Razor parsing error",
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ using Microsoft.CodeAnalysis.CSharp;
|
|||
using Microsoft.Dnx.Compilation;
|
||||
using Microsoft.Dnx.Compilation.CSharp;
|
||||
using Microsoft.Framework.Caching.Memory;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor.Precompilation
|
||||
{
|
||||
|
|
@ -28,10 +27,25 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation
|
|||
private const string CacheKeyDirectorySeparator = "/";
|
||||
|
||||
public RazorPreCompiler(
|
||||
[NotNull] BeforeCompileContext compileContext,
|
||||
[NotNull] IFileProvider fileProvider,
|
||||
[NotNull] IMemoryCache precompilationCache)
|
||||
BeforeCompileContext compileContext,
|
||||
IFileProvider fileProvider,
|
||||
IMemoryCache precompilationCache)
|
||||
{
|
||||
if (compileContext == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(compileContext));
|
||||
}
|
||||
|
||||
if (fileProvider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileProvider));
|
||||
}
|
||||
|
||||
if (precompilationCache == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(precompilationCache));
|
||||
}
|
||||
|
||||
CompileContext = compileContext;
|
||||
FileProvider = fileProvider;
|
||||
// There should always be a syntax tree even if there are no files (we generate one)
|
||||
|
|
@ -137,9 +151,19 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation
|
|||
}
|
||||
|
||||
protected virtual RazorFileInfoCollection GeneratePrecompiledAssembly(
|
||||
[NotNull] IEnumerable<SyntaxTree> syntaxTrees,
|
||||
[NotNull] IEnumerable<RazorFileInfo> razorFileInfos)
|
||||
IEnumerable<SyntaxTree> syntaxTrees,
|
||||
IEnumerable<RazorFileInfo> razorFileInfos)
|
||||
{
|
||||
if (syntaxTrees == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(syntaxTrees));
|
||||
}
|
||||
|
||||
if (razorFileInfos == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(razorFileInfos));
|
||||
}
|
||||
|
||||
var resourcePrefix = string.Join(".", CompileContext.Compilation.AssemblyName,
|
||||
nameof(RazorPreCompiler),
|
||||
Path.GetRandomFileName());
|
||||
|
|
@ -241,8 +265,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation
|
|||
}
|
||||
}
|
||||
|
||||
protected virtual PrecompilationCacheEntry GetCacheEntry([NotNull] RelativeFileInfo fileInfo)
|
||||
protected virtual PrecompilationCacheEntry GetCacheEntry(RelativeFileInfo fileInfo)
|
||||
{
|
||||
if (fileInfo == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileInfo));
|
||||
}
|
||||
|
||||
using (var stream = fileInfo.FileInfo.CreateReadStream())
|
||||
{
|
||||
var host = GetRazorHost();
|
||||
|
|
|
|||
|
|
@ -14,12 +14,10 @@ using Microsoft.AspNet.Http;
|
|||
using Microsoft.AspNet.Mvc.Actions;
|
||||
using Microsoft.AspNet.Mvc.Razor.Internal;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.AspNet.Mvc.Routing;
|
||||
using Microsoft.AspNet.Mvc.ViewFeatures;
|
||||
using Microsoft.AspNet.PageExecutionInstrumentation;
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.WebEncoders;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
|
|
@ -227,8 +225,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// All writes to the <see cref="Output"/> or <see cref="ViewContext.Writer"/> after calling this method will
|
||||
/// be buffered until <see cref="EndTagHelperWritingScope"/> is called.
|
||||
/// </remarks>
|
||||
public void StartTagHelperWritingScope([NotNull] TextWriter writer)
|
||||
public void StartTagHelperWritingScope(TextWriter writer)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
|
||||
// If there isn't a base writer take the ViewContext.Writer
|
||||
if (_originalWriter == null)
|
||||
{
|
||||
|
|
@ -297,8 +300,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <returns>
|
||||
/// A <see cref="Task"/> that on completion writes the <paramref name="tagHelperExecutionContext"/> content.
|
||||
/// </returns>
|
||||
public Task WriteTagHelperAsync([NotNull] TagHelperExecutionContext tagHelperExecutionContext)
|
||||
public Task WriteTagHelperAsync(TagHelperExecutionContext tagHelperExecutionContext)
|
||||
{
|
||||
if (tagHelperExecutionContext == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tagHelperExecutionContext));
|
||||
}
|
||||
|
||||
return WriteTagHelperToAsync(Output, tagHelperExecutionContext);
|
||||
}
|
||||
|
||||
|
|
@ -313,9 +321,19 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// to the <paramref name="writer"/>.
|
||||
/// </returns>
|
||||
public async Task WriteTagHelperToAsync(
|
||||
[NotNull] TextWriter writer,
|
||||
[NotNull] TagHelperExecutionContext tagHelperExecutionContext)
|
||||
TextWriter writer,
|
||||
TagHelperExecutionContext tagHelperExecutionContext)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
|
||||
if (tagHelperExecutionContext == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tagHelperExecutionContext));
|
||||
}
|
||||
|
||||
var tagHelperOutput = tagHelperExecutionContext.Output;
|
||||
var isTagNameNullOrWhitespace = string.IsNullOrWhiteSpace(tagHelperOutput.TagName);
|
||||
|
||||
|
|
@ -395,8 +413,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// For all other types, the encoded result of <see cref="object.ToString"/> is written to the
|
||||
/// <paramref name="writer"/>.
|
||||
/// </remarks>
|
||||
public virtual void WriteTo([NotNull] TextWriter writer, object value)
|
||||
public virtual void WriteTo(TextWriter writer, object value)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
|
||||
WriteTo(writer, HtmlEncoder, value, escapeQuotes: false);
|
||||
}
|
||||
|
||||
|
|
@ -417,11 +440,21 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <paramref name="writer"/>.
|
||||
/// </remarks>
|
||||
public static void WriteTo(
|
||||
[NotNull] TextWriter writer,
|
||||
[NotNull] IHtmlEncoder encoder,
|
||||
TextWriter writer,
|
||||
IHtmlEncoder encoder,
|
||||
object value,
|
||||
bool escapeQuotes)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
|
||||
if (encoder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(encoder));
|
||||
}
|
||||
|
||||
if (value == null || value == HtmlString.Empty)
|
||||
{
|
||||
return;
|
||||
|
|
@ -475,8 +508,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter"/> instance to write to.</param>
|
||||
/// <param name="value">The <see cref="string"/> to write.</param>
|
||||
public virtual void WriteTo([NotNull] TextWriter writer, string value)
|
||||
public virtual void WriteTo(TextWriter writer, string value)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
|
||||
WriteTo(writer, HtmlEncoder, value);
|
||||
}
|
||||
|
||||
|
|
@ -502,8 +540,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter"/> instance to write to.</param>
|
||||
/// <param name="value">The <see cref="object"/> to write.</param>
|
||||
public virtual void WriteLiteralTo([NotNull] TextWriter writer, object value)
|
||||
public virtual void WriteLiteralTo(TextWriter writer, object value)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
WriteLiteralTo(writer, value.ToString());
|
||||
|
|
@ -515,8 +558,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// </summary>
|
||||
/// <param name="writer">The <see cref="TextWriter"/> instance to write to.</param>
|
||||
/// <param name="value">The <see cref="string"/> to write.</param>
|
||||
public virtual void WriteLiteralTo([NotNull] TextWriter writer, string value)
|
||||
public virtual void WriteLiteralTo(TextWriter writer, string value)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
writer.Write(value);
|
||||
|
|
@ -525,20 +573,45 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
|
||||
public virtual void WriteAttribute(
|
||||
string name,
|
||||
[NotNull] PositionTagged<string> prefix,
|
||||
[NotNull] PositionTagged<string> suffix,
|
||||
PositionTagged<string> prefix,
|
||||
PositionTagged<string> suffix,
|
||||
params AttributeValue[] values)
|
||||
{
|
||||
if (prefix == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(prefix));
|
||||
}
|
||||
|
||||
if (suffix == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(suffix));
|
||||
}
|
||||
|
||||
WriteAttributeTo(Output, name, prefix, suffix, values);
|
||||
}
|
||||
|
||||
public virtual void WriteAttributeTo(
|
||||
[NotNull] TextWriter writer,
|
||||
TextWriter writer,
|
||||
string name,
|
||||
[NotNull] PositionTagged<string> prefix,
|
||||
[NotNull] PositionTagged<string> suffix,
|
||||
PositionTagged<string> prefix,
|
||||
PositionTagged<string> suffix,
|
||||
params AttributeValue[] values)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(writer));
|
||||
}
|
||||
|
||||
if (prefix == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(prefix));
|
||||
}
|
||||
|
||||
if (suffix == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(suffix));
|
||||
}
|
||||
|
||||
if (values.Length == 0)
|
||||
{
|
||||
// Explicitly empty attribute, so write the prefix
|
||||
|
|
@ -647,8 +720,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
}
|
||||
}
|
||||
|
||||
public virtual string Href([NotNull] string contentPath)
|
||||
public virtual string Href(string contentPath)
|
||||
{
|
||||
if (contentPath == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(contentPath));
|
||||
}
|
||||
|
||||
if (_urlHelper == null)
|
||||
{
|
||||
_urlHelper = Context.RequestServices.GetRequiredService<IUrlHelper>();
|
||||
|
|
@ -725,8 +803,18 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// </summary>
|
||||
/// <param name="name">The name of the section to create.</param>
|
||||
/// <param name="section">The <see cref="RenderAsyncDelegate"/> to execute when rendering the section.</param>
|
||||
public void DefineSection([NotNull] string name, [NotNull] RenderAsyncDelegate section)
|
||||
public void DefineSection(string name, RenderAsyncDelegate section)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
|
||||
if (section == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(section));
|
||||
}
|
||||
|
||||
if (SectionWriters.ContainsKey(name))
|
||||
{
|
||||
throw new InvalidOperationException(Resources.FormatSectionAlreadyDefined(name));
|
||||
|
|
@ -734,8 +822,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
SectionWriters[name] = section;
|
||||
}
|
||||
|
||||
public bool IsSectionDefined([NotNull] string name)
|
||||
public bool IsSectionDefined(string name)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
|
||||
EnsureMethodCanBeInvoked(nameof(IsSectionDefined));
|
||||
return PreviousSectionWriters.ContainsKey(name);
|
||||
}
|
||||
|
|
@ -749,8 +842,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <remarks>The method writes to the <see cref="Output"/> and the value returned is a token
|
||||
/// value that allows the Write (produced due to @RenderSection(..)) to succeed. However the
|
||||
/// value does not represent the rendered content.</remarks>
|
||||
public HtmlString RenderSection([NotNull] string name)
|
||||
public HtmlString RenderSection(string name)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
|
||||
return RenderSection(name, required: true);
|
||||
}
|
||||
|
||||
|
|
@ -764,8 +862,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <remarks>The method writes to the <see cref="Output"/> and the value returned is a token
|
||||
/// value that allows the Write (produced due to @RenderSection(..)) to succeed. However the
|
||||
/// value does not represent the rendered content.</remarks>
|
||||
public HtmlString RenderSection([NotNull] string name, bool required)
|
||||
public HtmlString RenderSection(string name, bool required)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
|
||||
EnsureMethodCanBeInvoked(nameof(RenderSection));
|
||||
|
||||
var task = RenderSectionAsyncCore(name, required);
|
||||
|
|
@ -781,8 +884,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <remarks>The method writes to the <see cref="Output"/> and the value returned is a token
|
||||
/// value that allows the Write (produced due to @RenderSection(..)) to succeed. However the
|
||||
/// value does not represent the rendered content.</remarks>
|
||||
public Task<HtmlString> RenderSectionAsync([NotNull] string name)
|
||||
public Task<HtmlString> RenderSectionAsync(string name)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
|
||||
return RenderSectionAsync(name, required: true);
|
||||
}
|
||||
|
||||
|
|
@ -797,8 +905,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// value does not represent the rendered content.</remarks>
|
||||
/// <exception cref="InvalidOperationException">if <paramref name="required"/> is <c>true</c> and the section
|
||||
/// was not registered using the <c>@section</c> in the Razor page.</exception>
|
||||
public Task<HtmlString> RenderSectionAsync([NotNull] string name, bool required)
|
||||
public Task<HtmlString> RenderSectionAsync(string name, bool required)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
|
||||
EnsureMethodCanBeInvoked(nameof(RenderSectionAsync));
|
||||
return RenderSectionAsyncCore(name, required);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,8 +32,18 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Activate([NotNull] IRazorPage page, [NotNull] ViewContext context)
|
||||
public void Activate(IRazorPage page, ViewContext context)
|
||||
{
|
||||
if (page == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(page));
|
||||
}
|
||||
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
var activationInfo = _activationInfo.GetOrAdd(page.GetType(),
|
||||
CreateViewActivationInfo);
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ using Microsoft.AspNet.Mvc.Razor.Internal;
|
|||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.AspNet.Mvc.ViewFeatures;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -41,8 +40,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <remarks>
|
||||
/// Compiler normally infers <typeparamref name="TValue"/> from the given <paramref name="expression"/>.
|
||||
/// </remarks>
|
||||
public ModelExpression CreateModelExpression<TValue>([NotNull] Expression<Func<TModel, TValue>> expression)
|
||||
public ModelExpression CreateModelExpression<TValue>(Expression<Func<TModel, TValue>> expression)
|
||||
{
|
||||
if (expression == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(expression));
|
||||
}
|
||||
|
||||
if (_provider == null)
|
||||
{
|
||||
_provider = Context.RequestServices.GetRequiredService<IModelMetadataProvider>();
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// 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 Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -16,8 +16,18 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// </summary>
|
||||
/// <param name="name">The name of the page that was located.</param>
|
||||
/// <param name="page">The located <see cref="IRazorPage"/>.</param>
|
||||
public RazorPageResult([NotNull] string name, [NotNull] IRazorPage page)
|
||||
public RazorPageResult(string name, IRazorPage page)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
|
||||
if (page == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(page));
|
||||
}
|
||||
|
||||
Name = name;
|
||||
Page = page;
|
||||
}
|
||||
|
|
@ -27,8 +37,18 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// </summary>
|
||||
/// <param name="name">The name of the page that was located.</param>
|
||||
/// <param name="searchedLocations">The locations that were searched.</param>
|
||||
public RazorPageResult([NotNull] string name, [NotNull] IEnumerable<string> searchedLocations)
|
||||
public RazorPageResult(string name, IEnumerable<string> searchedLocations)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
}
|
||||
|
||||
if (searchedLocations == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(searchedLocations));
|
||||
}
|
||||
|
||||
Name = name;
|
||||
SearchedLocations = searchedLocations;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,7 @@ using System.IO;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Html.Abstractions;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.AspNet.Mvc.ViewFeatures;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.WebEncoders;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
|
|
@ -66,8 +64,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Write([NotNull] char[] buffer, int index, int count)
|
||||
public override void Write(char[] buffer, int index, int count)
|
||||
{
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(buffer));
|
||||
}
|
||||
|
||||
if (index < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
|
@ -110,8 +113,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Task WriteAsync([NotNull] char[] buffer, int index, int count)
|
||||
public override Task WriteAsync(char[] buffer, int index, int count)
|
||||
{
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(buffer));
|
||||
}
|
||||
|
||||
if (index < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ using Microsoft.AspNet.Http.Features;
|
|||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.AspNet.Mvc.ViewEngines;
|
||||
using Microsoft.AspNet.PageExecutionInstrumentation;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.WebEncoders;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
|
|
@ -75,8 +74,18 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual async Task RenderAsync([NotNull] ViewContext context)
|
||||
public virtual async Task RenderAsync(ViewContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
_pageExecutionFeature = context.HttpContext.Features.Get<IPageExecutionListenerFeature>();
|
||||
|
||||
// Partials don't execute _ViewStart pages, but may execute Layout pages if the Layout property
|
||||
|
|
|
|||
|
|
@ -7,9 +7,7 @@ using System.Diagnostics;
|
|||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Mvc.Actions;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.AspNet.Mvc.ViewEngines;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
|
|
@ -101,9 +99,14 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
|
||||
/// <inheritdoc />
|
||||
public ViewEngineResult FindView(
|
||||
[NotNull] ActionContext context,
|
||||
ActionContext context,
|
||||
string viewName)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(viewName))
|
||||
{
|
||||
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(viewName));
|
||||
|
|
@ -115,9 +118,14 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
|
||||
/// <inheritdoc />
|
||||
public ViewEngineResult FindPartialView(
|
||||
[NotNull] ActionContext context,
|
||||
ActionContext context,
|
||||
string partialViewName)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(partialViewName))
|
||||
{
|
||||
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(partialViewName));
|
||||
|
|
@ -129,9 +137,14 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
|
||||
/// <inheritdoc />
|
||||
public RazorPageResult FindPage(
|
||||
[NotNull] ActionContext context,
|
||||
ActionContext context,
|
||||
string pageName)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(pageName))
|
||||
{
|
||||
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(pageName));
|
||||
|
|
@ -154,9 +167,19 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// consistently cased results.
|
||||
/// </remarks>
|
||||
public static string GetNormalizedRouteValue(
|
||||
[NotNull] ActionContext context,
|
||||
[NotNull] string key)
|
||||
ActionContext context,
|
||||
string key)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (key == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
}
|
||||
|
||||
object routeValue;
|
||||
if (!context.RouteData.Values.TryGetValue(key, out routeValue))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.Mvc.ViewEngines;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.WebEncoders;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
|
|
@ -23,9 +23,10 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <param name="pageActivator">The <see cref="IRazorPageActivator"/> used to activate pages.</param>
|
||||
/// <param name="viewStartProvider">The <see cref="IViewStartProvider"/> used for discovery of _ViewStart
|
||||
/// pages</param>
|
||||
public RazorViewFactory(IRazorPageActivator pageActivator,
|
||||
IViewStartProvider viewStartProvider,
|
||||
IHtmlEncoder htmlEncoder)
|
||||
public RazorViewFactory(
|
||||
IRazorPageActivator pageActivator,
|
||||
IViewStartProvider viewStartProvider,
|
||||
IHtmlEncoder htmlEncoder)
|
||||
{
|
||||
_pageActivator = pageActivator;
|
||||
_viewStartProvider = viewStartProvider;
|
||||
|
|
@ -33,10 +34,21 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IView GetView([NotNull] IRazorViewEngine viewEngine,
|
||||
[NotNull] IRazorPage page,
|
||||
bool isPartial)
|
||||
public IView GetView(
|
||||
IRazorViewEngine viewEngine,
|
||||
IRazorPage page,
|
||||
bool isPartial)
|
||||
{
|
||||
if (viewEngine == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(viewEngine));
|
||||
}
|
||||
|
||||
if (page == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(page));
|
||||
}
|
||||
|
||||
var razorView = new RazorView(
|
||||
viewEngine,
|
||||
_pageActivator,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// Initializes a new instance of the <see cref="TagHelperContentWrapperTextWriter"/> class.
|
||||
/// </summary>
|
||||
/// <param name="encoding">The <see cref="Encoding"/> in which output is written.</param>
|
||||
public TagHelperContentWrapperTextWriter([NotNull] Encoding encoding)
|
||||
public TagHelperContentWrapperTextWriter(Encoding encoding)
|
||||
: this(encoding, new DefaultTagHelperContent())
|
||||
{
|
||||
}
|
||||
|
|
@ -27,8 +27,18 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// </summary>
|
||||
/// <param name="encoding">The <see cref="Encoding"/> in which output is written.</param>
|
||||
/// <param name="content">The <see cref="TagHelperContent"/> to write to.</param>
|
||||
public TagHelperContentWrapperTextWriter([NotNull] Encoding encoding, [NotNull] TagHelperContent content)
|
||||
public TagHelperContentWrapperTextWriter(Encoding encoding, TagHelperContent content)
|
||||
{
|
||||
if (encoding == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(encoding));
|
||||
}
|
||||
|
||||
if (content == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(content));
|
||||
}
|
||||
|
||||
Content = content;
|
||||
Encoding = encoding;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
using System;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -18,14 +17,29 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// Creates a <see cref="TagHelperInitializer{TTagHelper}"/>.
|
||||
/// </summary>
|
||||
/// <param name="action">The initialization delegate.</param>
|
||||
public TagHelperInitializer([NotNull] Action<TTagHelper, ViewContext> action)
|
||||
public TagHelperInitializer(Action<TTagHelper, ViewContext> action)
|
||||
{
|
||||
if (action == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(action));
|
||||
}
|
||||
|
||||
_initializeDelegate = action;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Initialize([NotNull] TTagHelper helper, [NotNull] ViewContext context)
|
||||
public void Initialize(TTagHelper helper, ViewContext context)
|
||||
{
|
||||
if (helper == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(helper));
|
||||
}
|
||||
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
_initializeDelegate(helper, context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
|
@ -21,10 +21,20 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <param name="searchedLocations">Locations that were searched
|
||||
/// in addition to <paramref name="foundLocation"/>.</param>
|
||||
public ViewLocationCacheResult(
|
||||
[NotNull] string foundLocation,
|
||||
[NotNull] IEnumerable<string> searchedLocations)
|
||||
: this (searchedLocations)
|
||||
string foundLocation,
|
||||
IEnumerable<string> searchedLocations)
|
||||
: this(searchedLocations)
|
||||
{
|
||||
if (foundLocation == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(foundLocation));
|
||||
}
|
||||
|
||||
if (searchedLocations == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(searchedLocations));
|
||||
}
|
||||
|
||||
ViewLocation = foundLocation;
|
||||
SearchedLocations = searchedLocations;
|
||||
IsFoundResult = true;
|
||||
|
|
@ -35,8 +45,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// failed view lookup.
|
||||
/// </summary>
|
||||
/// <param name="searchedLocations">Locations that were searched.</param>
|
||||
public ViewLocationCacheResult([NotNull] IEnumerable<string> searchedLocations)
|
||||
public ViewLocationCacheResult(IEnumerable<string> searchedLocations)
|
||||
{
|
||||
if (searchedLocations == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(searchedLocations));
|
||||
}
|
||||
|
||||
SearchedLocations = searchedLocations;
|
||||
ViewLocation = null;
|
||||
IsFoundResult = false;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// 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 Microsoft.AspNet.Mvc.Actions;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -18,10 +17,20 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <param name="actionContext">The <see cref="Mvc.ActionContext"/> for the current executing action.</param>
|
||||
/// <param name="viewName">The view name.</param>
|
||||
/// <param name="isPartial">Determines if the view being discovered is a partial.</param>
|
||||
public ViewLocationExpanderContext([NotNull] ActionContext actionContext,
|
||||
[NotNull] string viewName,
|
||||
public ViewLocationExpanderContext(ActionContext actionContext,
|
||||
string viewName,
|
||||
bool isPartial)
|
||||
{
|
||||
if (actionContext == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(actionContext));
|
||||
}
|
||||
|
||||
if (viewName == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(viewName));
|
||||
}
|
||||
|
||||
ActionContext = actionContext;
|
||||
ViewName = viewName;
|
||||
IsPartial = isPartial;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -19,8 +18,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IRazorPage> GetViewStartPages([NotNull] string path)
|
||||
public IEnumerable<IRazorPage> GetViewStartPages(string path)
|
||||
{
|
||||
if (path == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(path));
|
||||
}
|
||||
|
||||
var viewStartLocations = ViewHierarchyUtility.GetViewStartLocations(path);
|
||||
var viewStarts = viewStartLocations.Select(_pageFactory.CreateInstance)
|
||||
.Where(p => p != null)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
using System;
|
||||
using Microsoft.AspNet.Mvc.Razor.Compilation;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -47,8 +46,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IRazorPage CreateInstance([NotNull] string relativePath)
|
||||
public IRazorPage CreateInstance(string relativePath)
|
||||
{
|
||||
if (relativePath == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(relativePath));
|
||||
}
|
||||
|
||||
if (relativePath.StartsWith("~/", StringComparison.Ordinal))
|
||||
{
|
||||
// For tilde slash paths, drop the leading ~ to make it work with the underlying IFileProvider.
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
"Microsoft.AspNet.Razor.Runtime.Precompilation": "4.0.0-*",
|
||||
"Microsoft.AspNet.PageExecutionInstrumentation.Interfaces": "1.0.0-*",
|
||||
"Microsoft.Framework.HashCodeCombiner.Sources": { "version": "1.0.0-*", "type": "build" },
|
||||
"Microsoft.Framework.NotNullAttribute.Sources": { "version": "1.0.0-*", "type": "build" },
|
||||
"Microsoft.Framework.PropertyActivator.Sources": { "version": "1.0.0-*", "type": "build" },
|
||||
"Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" },
|
||||
"Microsoft.Dnx.Compilation.CSharp.Common": "1.0.0-*",
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
|
||||
{
|
||||
|
|
@ -24,9 +22,19 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
|
|||
/// <param name="modeInfos">The modes and their required attributes.</param>
|
||||
/// <returns>The <see cref="ModeMatchResult{TMode}"/>.</returns>
|
||||
public static ModeMatchResult<TMode> DetermineMode<TMode>(
|
||||
[NotNull] TagHelperContext context,
|
||||
[NotNull] IEnumerable<ModeAttributes<TMode>> modeInfos)
|
||||
TagHelperContext context,
|
||||
IEnumerable<ModeAttributes<TMode>> modeInfos)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (modeInfos == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(modeInfos));
|
||||
}
|
||||
|
||||
// true == full match, false == partial match
|
||||
var matchedAttributes = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
|
||||
var result = new ModeMatchResult<TMode>();
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// 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 Microsoft.AspNet.FileProviders;
|
||||
using Microsoft.Framework.FileSystemGlobbing.Abstractions;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
|
||||
{
|
||||
|
|
@ -17,10 +17,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
|
|||
private readonly bool _isRoot;
|
||||
|
||||
public FileProviderGlobbingDirectory(
|
||||
[NotNull] IFileProvider fileProvider,
|
||||
IFileProvider fileProvider,
|
||||
IFileInfo fileInfo,
|
||||
FileProviderGlobbingDirectory parent)
|
||||
{
|
||||
if (fileProvider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileProvider));
|
||||
}
|
||||
|
||||
_fileProvider = fileProvider;
|
||||
_fileInfo = fileInfo;
|
||||
_parent = parent;
|
||||
|
|
@ -54,7 +59,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
|
|||
// We're the root, so just use our name
|
||||
return Name;
|
||||
}
|
||||
|
||||
|
||||
return _parent.FullName + DirectorySeparatorChar + Name;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.FileProviders;
|
||||
using Microsoft.Framework.FileSystemGlobbing.Abstractions;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
|
||||
{
|
||||
|
|
@ -11,8 +11,18 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
|
|||
{
|
||||
private const char DirectorySeparatorChar = '/';
|
||||
|
||||
public FileProviderGlobbingFile([NotNull] IFileInfo fileInfo, [NotNull] DirectoryInfoBase parent)
|
||||
public FileProviderGlobbingFile(IFileInfo fileInfo, DirectoryInfoBase parent)
|
||||
{
|
||||
if (fileInfo == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileInfo));
|
||||
}
|
||||
|
||||
if (parent == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(parent));
|
||||
}
|
||||
|
||||
Name = fileInfo.Name;
|
||||
ParentDirectory = parent;
|
||||
FullName = ParentDirectory.FullName + DirectorySeparatorChar + Name;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ using Microsoft.AspNet.FileProviders;
|
|||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.WebUtilities;
|
||||
using Microsoft.Framework.Caching.Memory;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
|
||||
{
|
||||
|
|
@ -28,10 +27,20 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
|
|||
/// <param name="applicationName">Name of the application.</param>
|
||||
/// <param name="cache"><see cref="IMemoryCache"/> where versioned urls of files are cached.</param>
|
||||
public FileVersionProvider(
|
||||
[NotNull] IFileProvider fileProvider,
|
||||
[NotNull] IMemoryCache cache,
|
||||
[NotNull] PathString requestPathBase)
|
||||
IFileProvider fileProvider,
|
||||
IMemoryCache cache,
|
||||
PathString requestPathBase)
|
||||
{
|
||||
if (fileProvider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileProvider));
|
||||
}
|
||||
|
||||
if (cache == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(cache));
|
||||
}
|
||||
|
||||
_fileProvider = fileProvider;
|
||||
_cache = cache;
|
||||
_requestPathBase = requestPathBase;
|
||||
|
|
@ -45,8 +54,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
|
|||
/// <remarks>
|
||||
/// The version query string is appended as with the key "v".
|
||||
/// </remarks>
|
||||
public string AddFileVersionToPath([NotNull] string path)
|
||||
public string AddFileVersionToPath(string path)
|
||||
{
|
||||
if (path == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(path));
|
||||
}
|
||||
|
||||
var resolvedPath = path;
|
||||
|
||||
var queryStringOrFragmentStartIndex = path.IndexOfAny(new char[] { '?', '#' });
|
||||
|
|
@ -80,7 +94,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
|
|||
}
|
||||
|
||||
string value;
|
||||
if(!_cache.TryGetValue(path, out value))
|
||||
if (!_cache.TryGetValue(path, out value))
|
||||
{
|
||||
value = QueryHelpers.AddQueryString(path, VersionKey, GetHashForFile(fileInfo));
|
||||
_cache.Set(
|
||||
|
|
|
|||
|
|
@ -6,10 +6,8 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Microsoft.AspNet.FileProviders;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
using Microsoft.Framework.Caching.Memory;
|
||||
using Microsoft.Framework.FileSystemGlobbing;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
|
||||
{
|
||||
|
|
@ -37,8 +35,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
|
|||
/// <param name="fileProvider">The file provider.</param>
|
||||
/// <param name="cache">The cache.</param>
|
||||
/// <param name="requestPathBase">The request path base.</param>
|
||||
public GlobbingUrlBuilder([NotNull] IFileProvider fileProvider, IMemoryCache cache, PathString requestPathBase)
|
||||
public GlobbingUrlBuilder(IFileProvider fileProvider, IMemoryCache cache, PathString requestPathBase)
|
||||
{
|
||||
if (fileProvider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileProvider));
|
||||
}
|
||||
|
||||
FileProvider = fileProvider;
|
||||
Cache = cache;
|
||||
RequestPathBase = requestPathBase;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.Logging;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
|
||||
|
|
@ -41,12 +40,22 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
|
|||
/// <param name="uniqueId">The value of <see cref="TagHelperContext.UniqueId"/>.</param>
|
||||
/// <param name="viewPath">The path to the view the <see cref="ITagHelper"/> is on.</param>
|
||||
public void LogDetails<TTagHelper>(
|
||||
[NotNull] ILogger logger,
|
||||
[NotNull] TTagHelper tagHelper,
|
||||
ILogger logger,
|
||||
TTagHelper tagHelper,
|
||||
string uniqueId,
|
||||
string viewPath)
|
||||
where TTagHelper : ITagHelper
|
||||
{
|
||||
if (logger == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
if (tagHelper == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tagHelper));
|
||||
}
|
||||
|
||||
if (logger.IsEnabled(LogLevel.Warning) && PartiallyMatchedAttributes.Any())
|
||||
{
|
||||
// Build the list of partial matches that contain attributes not appearing in at least one full match
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.Logging;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
|
||||
|
|
@ -29,8 +27,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
|
|||
public PartialModeMatchLogValues(
|
||||
string uniqueId,
|
||||
string viewPath,
|
||||
[NotNull] IEnumerable<ModeMatchAttributes<TMode>> partialMatches)
|
||||
IEnumerable<ModeMatchAttributes<TMode>> partialMatches)
|
||||
{
|
||||
if (partialMatches == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(partialMatches));
|
||||
}
|
||||
|
||||
_uniqueId = uniqueId;
|
||||
_viewPath = viewPath;
|
||||
_partialMatches = partialMatches;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
using Microsoft.AspNet.Mvc.Razor;
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.WebEncoders;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||
|
|
@ -29,11 +29,26 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
/// is written to the <paramref name="content"/>.
|
||||
/// </remarks>
|
||||
public static TagHelperContent Append(
|
||||
[NotNull] this TagHelperContent content,
|
||||
[NotNull] IHtmlEncoder encoder,
|
||||
[NotNull] Encoding encoding,
|
||||
this TagHelperContent content,
|
||||
IHtmlEncoder encoder,
|
||||
Encoding encoding,
|
||||
object value)
|
||||
{
|
||||
if (content == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(content));
|
||||
}
|
||||
|
||||
if (encoder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(encoder));
|
||||
}
|
||||
|
||||
if (encoding == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(encoding));
|
||||
}
|
||||
|
||||
using (var writer = new TagHelperContentWrapperTextWriter(encoding, content))
|
||||
{
|
||||
RazorPage.WriteTo(writer, encoder, value, escapeQuotes: true);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||
{
|
||||
|
|
@ -35,10 +34,25 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
/// attribute order not being maintained.
|
||||
/// </para></remarks>
|
||||
public static void CopyHtmlAttribute(
|
||||
[NotNull] this TagHelperOutput tagHelperOutput,
|
||||
[NotNull] string attributeName,
|
||||
[NotNull] TagHelperContext context)
|
||||
this TagHelperOutput tagHelperOutput,
|
||||
string attributeName,
|
||||
TagHelperContext context)
|
||||
{
|
||||
if (tagHelperOutput == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tagHelperOutput));
|
||||
}
|
||||
|
||||
if (attributeName == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(attributeName));
|
||||
}
|
||||
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (!tagHelperOutput.Attributes.ContainsName(attributeName))
|
||||
{
|
||||
var copiedAttribute = false;
|
||||
|
|
@ -77,9 +91,19 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
/// <remarks>Existing <see cref="TagHelperOutput.Attributes"/> on the given <paramref name="tagHelperOutput"/>
|
||||
/// are not overridden; "class" attributes are merged with spaces.</remarks>
|
||||
public static void MergeAttributes(
|
||||
[NotNull] this TagHelperOutput tagHelperOutput,
|
||||
[NotNull] TagBuilder tagBuilder)
|
||||
this TagHelperOutput tagHelperOutput,
|
||||
TagBuilder tagBuilder)
|
||||
{
|
||||
if (tagHelperOutput == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tagHelperOutput));
|
||||
}
|
||||
|
||||
if (tagBuilder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tagBuilder));
|
||||
}
|
||||
|
||||
foreach (var attribute in tagBuilder.Attributes)
|
||||
{
|
||||
if (!tagHelperOutput.Attributes.ContainsName(attribute.Key))
|
||||
|
|
@ -109,9 +133,19 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
/// <param name="tagHelperOutput">The <see cref="TagHelperOutput"/> this method extends.</param>
|
||||
/// <param name="attributes">Attributes to remove.</param>
|
||||
public static void RemoveRange(
|
||||
[NotNull] this TagHelperOutput tagHelperOutput,
|
||||
[NotNull] IEnumerable<TagHelperAttribute> attributes)
|
||||
this TagHelperOutput tagHelperOutput,
|
||||
IEnumerable<TagHelperAttribute> attributes)
|
||||
{
|
||||
if (tagHelperOutput == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tagHelperOutput));
|
||||
}
|
||||
|
||||
if (attributes == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(attributes));
|
||||
}
|
||||
|
||||
foreach (var attribute in attributes.ToArray())
|
||||
{
|
||||
tagHelperOutput.Attributes.Remove(attribute);
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@
|
|||
"Microsoft.Framework.Caching.Memory": "1.0.0-*",
|
||||
"Microsoft.Framework.FileSystemGlobbing": "1.0.0-*",
|
||||
"Microsoft.Framework.Logging.Abstractions": { "version": "1.0.0-*", "type": "build" },
|
||||
"Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" },
|
||||
"Microsoft.Framework.NotNullAttribute.Sources": { "version": "1.0.0-*", "type": "build" }
|
||||
"Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" }
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": { },
|
||||
|
|
|
|||
|
|
@ -55,14 +55,15 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
// Arrange
|
||||
var rootedAppPath = $"{rootPrefix}SomeComputer/Location/Project/";
|
||||
var rootedFilePath = $"{rootPrefix}SomeComputer/Location/Project/src/file.cshtml";
|
||||
var chunkTreeCache = new DefaultChunkTreeCache(new TestFileProvider());
|
||||
var host = new MvcRazorHost(
|
||||
chunkTreeCache: null,
|
||||
chunkTreeCache,
|
||||
pathNormalizer: new DesignTimeRazorPathNormalizer(rootedAppPath));
|
||||
var parser = new RazorParser(
|
||||
host.CodeLanguage.CreateCodeParser(),
|
||||
host.CreateMarkupParser(),
|
||||
tagHelperDescriptorResolver: null);
|
||||
var chunkInheritanceUtility = new PathValidatingChunkInheritanceUtility(host);
|
||||
var chunkInheritanceUtility = new PathValidatingChunkInheritanceUtility(host, chunkTreeCache);
|
||||
host.ChunkInheritanceUtility = chunkInheritanceUtility;
|
||||
|
||||
// Act
|
||||
|
|
@ -80,10 +81,11 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
// Arrange
|
||||
var rootedAppPath = $"{rootPrefix}SomeComputer/Location/Project/";
|
||||
var rootedFilePath = $"{rootPrefix}SomeComputer/Location/Project/src/file.cshtml";
|
||||
var chunkTreeCache = new DefaultChunkTreeCache(new TestFileProvider());
|
||||
var host = new MvcRazorHost(
|
||||
chunkTreeCache: null,
|
||||
chunkTreeCache,
|
||||
pathNormalizer: new DesignTimeRazorPathNormalizer(rootedAppPath));
|
||||
var chunkInheritanceUtility = new PathValidatingChunkInheritanceUtility(host);
|
||||
var chunkInheritanceUtility = new PathValidatingChunkInheritanceUtility(host, chunkTreeCache);
|
||||
var codeGeneratorContext = new CodeGeneratorContext(
|
||||
new ChunkGeneratorContext(
|
||||
host,
|
||||
|
|
@ -371,8 +373,9 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
RunDesignTimeTest(host, "Model", expectedLineMappings);
|
||||
}
|
||||
|
||||
private static void RunRuntimeTest(MvcRazorHost host,
|
||||
string testName)
|
||||
private static void RunRuntimeTest(
|
||||
MvcRazorHost host,
|
||||
string testName)
|
||||
{
|
||||
var inputFile = "TestFiles/Input/" + testName + ".cshtml";
|
||||
var outputFile = "TestFiles/Output/Runtime/" + testName + ".cs";
|
||||
|
|
@ -396,9 +399,10 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
#endif
|
||||
}
|
||||
|
||||
private static void RunDesignTimeTest(MvcRazorHost host,
|
||||
string testName,
|
||||
IEnumerable<LineMapping> expectedLineMappings)
|
||||
private static void RunDesignTimeTest(
|
||||
MvcRazorHost host,
|
||||
string testName,
|
||||
IEnumerable<LineMapping> expectedLineMappings)
|
||||
{
|
||||
var inputFile = "TestFiles/Input/" + testName + ".cshtml";
|
||||
var outputFile = "TestFiles/Output/DesignTime/" + testName + ".cs";
|
||||
|
|
@ -457,13 +461,14 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
#endif
|
||||
}
|
||||
|
||||
private static LineMapping BuildLineMapping(int documentAbsoluteIndex,
|
||||
int documentLineIndex,
|
||||
int documentCharacterIndex,
|
||||
int generatedAbsoluteIndex,
|
||||
int generatedLineIndex,
|
||||
int generatedCharacterIndex,
|
||||
int contentLength)
|
||||
private static LineMapping BuildLineMapping(
|
||||
int documentAbsoluteIndex,
|
||||
int documentLineIndex,
|
||||
int documentCharacterIndex,
|
||||
int generatedAbsoluteIndex,
|
||||
int generatedLineIndex,
|
||||
int generatedCharacterIndex,
|
||||
int contentLength)
|
||||
{
|
||||
var documentLocation = new SourceLocation(documentAbsoluteIndex,
|
||||
documentLineIndex,
|
||||
|
|
@ -479,14 +484,14 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
|
||||
private class PathValidatingChunkInheritanceUtility : ChunkInheritanceUtility
|
||||
{
|
||||
public PathValidatingChunkInheritanceUtility(MvcRazorHost razorHost)
|
||||
: base(razorHost, chunkTreeCache: null, defaultInheritedChunks: new Chunk[0])
|
||||
public PathValidatingChunkInheritanceUtility(MvcRazorHost razorHost, IChunkTreeCache chunkTreeCache)
|
||||
: base(razorHost, chunkTreeCache, defaultInheritedChunks: new Chunk[0])
|
||||
{
|
||||
}
|
||||
|
||||
public string InheritedChunkTreePagePath { get; private set; }
|
||||
|
||||
public override IReadOnlyList<ChunkTreeResult> GetInheritedChunkTreeResults([NotNull] string pagePath)
|
||||
public override IReadOnlyList<ChunkTreeResult> GetInheritedChunkTreeResults(string pagePath)
|
||||
{
|
||||
InheritedChunkTreePagePath = pagePath;
|
||||
|
||||
|
|
@ -522,10 +527,11 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
private readonly GeneratedTagHelperAttributeContext _tagHelperAttributeContext;
|
||||
|
||||
public TestCSharpCodeGenerator(CodeGeneratorContext context,
|
||||
string defaultModel,
|
||||
string activateAttribute,
|
||||
GeneratedTagHelperAttributeContext tagHelperAttributeContext)
|
||||
public TestCSharpCodeGenerator(
|
||||
CodeGeneratorContext context,
|
||||
string defaultModel,
|
||||
string activateAttribute,
|
||||
GeneratedTagHelperAttributeContext tagHelperAttributeContext)
|
||||
: base(context, defaultModel, activateAttribute, tagHelperAttributeContext)
|
||||
{
|
||||
_tagHelperAttributeContext = tagHelperAttributeContext;
|
||||
|
|
|
|||
|
|
@ -23,9 +23,8 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
public class RazorPageTest
|
||||
{
|
||||
#pragma warning disable 1998
|
||||
private readonly RenderAsyncDelegate _nullRenderAsyncDelegate = async writer => { };
|
||||
#pragma warning restore 1998
|
||||
private readonly RenderAsyncDelegate _nullRenderAsyncDelegate = writer => Task.FromResult(0);
|
||||
private readonly Func<TextWriter, Task> NullAsyncWrite = CreateAsyncWriteDelegate(string.Empty);
|
||||
|
||||
[Fact]
|
||||
public async Task WritingScopesRedirectContentWrittenToViewContextWriter()
|
||||
|
|
@ -304,7 +303,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
{ "baz", _nullRenderAsyncDelegate }
|
||||
};
|
||||
page.RenderBodyDelegateAsync = CreateBodyAction("body-content");
|
||||
page.RenderBodyDelegateAsync = CreateAsyncWriteDelegate("body-content");
|
||||
|
||||
// Act
|
||||
await page.ExecuteAsync();
|
||||
|
|
@ -328,7 +327,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
{ "baz", _nullRenderAsyncDelegate }
|
||||
};
|
||||
page.RenderBodyDelegateAsync = CreateBodyAction("body-content");
|
||||
page.RenderBodyDelegateAsync = CreateAsyncWriteDelegate("body-content");
|
||||
|
||||
// Act
|
||||
await page.ExecuteAsync();
|
||||
|
|
@ -341,7 +340,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
public async Task RenderSection_ThrowsIfSectionIsRenderedMoreThanOnce()
|
||||
{
|
||||
// Arrange
|
||||
var expected = new HelperResult(asyncAction: null);
|
||||
var expected = new HelperResult(NullAsyncWrite);
|
||||
var page = CreatePage(v =>
|
||||
{
|
||||
v.Path = "/Views/TestPath/Test.cshtml";
|
||||
|
|
@ -365,7 +364,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
public async Task RenderSectionAsync_ThrowsIfSectionIsRenderedMoreThanOnce()
|
||||
{
|
||||
// Arrange
|
||||
var expected = new HelperResult(asyncAction: null);
|
||||
var expected = new HelperResult(NullAsyncWrite);
|
||||
var page = CreatePage(async v =>
|
||||
{
|
||||
v.Path = "/Views/TestPath/Test.cshtml";
|
||||
|
|
@ -389,7 +388,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
public async Task RenderSectionAsync_ThrowsIfSectionIsRenderedMoreThanOnce_WithSyncMethod()
|
||||
{
|
||||
// Arrange
|
||||
var expected = new HelperResult(asyncAction: null);
|
||||
var expected = new HelperResult(NullAsyncWrite);
|
||||
var page = CreatePage(async v =>
|
||||
{
|
||||
v.Path = "/Views/TestPath/Test.cshtml";
|
||||
|
|
@ -413,7 +412,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
public async Task RenderSectionAsync_ThrowsIfNotInvokedFromLayoutPage()
|
||||
{
|
||||
// Arrange
|
||||
var expected = new HelperResult(asyncAction: null);
|
||||
var expected = new HelperResult(NullAsyncWrite);
|
||||
var page = CreatePage(async v =>
|
||||
{
|
||||
v.Path = "/Views/TestPath/Test.cshtml";
|
||||
|
|
@ -437,7 +436,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
});
|
||||
page.Path = path;
|
||||
page.RenderBodyDelegateAsync = CreateBodyAction("some content");
|
||||
page.RenderBodyDelegateAsync = CreateAsyncWriteDelegate("some content");
|
||||
|
||||
// Act
|
||||
await page.ExecuteAsync();
|
||||
|
|
@ -457,7 +456,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
{
|
||||
});
|
||||
page.Path = path;
|
||||
page.RenderBodyDelegateAsync = CreateBodyAction("some content");
|
||||
page.RenderBodyDelegateAsync = CreateAsyncWriteDelegate("some content");
|
||||
page.PreviousSectionWriters = new Dictionary<string, RenderAsyncDelegate>
|
||||
{
|
||||
{ sectionName, _nullRenderAsyncDelegate }
|
||||
|
|
@ -483,7 +482,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
v.RenderSection(sectionA);
|
||||
v.RenderSection(sectionB);
|
||||
});
|
||||
page.RenderBodyDelegateAsync = CreateBodyAction("some content");
|
||||
page.RenderBodyDelegateAsync = CreateAsyncWriteDelegate("some content");
|
||||
page.PreviousSectionWriters = new Dictionary<string, RenderAsyncDelegate>
|
||||
{
|
||||
{ sectionA, _nullRenderAsyncDelegate },
|
||||
|
|
@ -517,7 +516,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
v.Write(v.RenderSection("footer"));
|
||||
v.WriteLiteral("Layout end");
|
||||
});
|
||||
page.RenderBodyDelegateAsync = CreateBodyAction("body content" + Environment.NewLine);
|
||||
page.RenderBodyDelegateAsync = CreateAsyncWriteDelegate("body content" + Environment.NewLine);
|
||||
page.PreviousSectionWriters = new Dictionary<string, RenderAsyncDelegate>
|
||||
{
|
||||
{
|
||||
|
|
@ -837,7 +836,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
var executionContext = new TagHelperExecutionContext(
|
||||
"p",
|
||||
tagMode: TagMode.StartTagAndEndTag,
|
||||
items: null,
|
||||
items: new Dictionary<object, object>(),
|
||||
uniqueId: string.Empty,
|
||||
executeChildContentAsync: () => Task.FromResult(result: true),
|
||||
startTagHelperWritingScope: () => { },
|
||||
|
|
@ -872,7 +871,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
var executionContext = new TagHelperExecutionContext(
|
||||
"p",
|
||||
tagMode: TagMode.StartTagAndEndTag,
|
||||
items: null,
|
||||
items: new Dictionary<object, object>(),
|
||||
uniqueId: string.Empty,
|
||||
executeChildContentAsync: () => Task.FromResult(result: true),
|
||||
startTagHelperWritingScope: () => { },
|
||||
|
|
@ -904,7 +903,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
var executionContext = new TagHelperExecutionContext(
|
||||
"p",
|
||||
tagMode: TagMode.StartTagAndEndTag,
|
||||
items: null,
|
||||
items: new Dictionary<object, object>(),
|
||||
uniqueId: string.Empty,
|
||||
executeChildContentAsync: () => Task.FromResult(result: true),
|
||||
startTagHelperWritingScope: () => { },
|
||||
|
|
@ -1060,7 +1059,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
},
|
||||
{
|
||||
GetTagHelperOutput(
|
||||
tagName: null,
|
||||
tagName: "",
|
||||
attributes: new TagHelperAttributeList(),
|
||||
tagMode: TagMode.StartTagAndEndTag,
|
||||
preElement: null,
|
||||
|
|
@ -1359,7 +1358,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
},
|
||||
{
|
||||
GetTagHelperOutput(
|
||||
tagName: null,
|
||||
tagName: "",
|
||||
attributes: new TagHelperAttributeList(),
|
||||
tagMode: TagMode.StartTagAndEndTag,
|
||||
preElement: "Before",
|
||||
|
|
@ -1371,7 +1370,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
},
|
||||
{
|
||||
GetTagHelperOutput(
|
||||
tagName: null,
|
||||
tagName: "",
|
||||
attributes: new TagHelperAttributeList { { "test", "testVal" } },
|
||||
tagMode: TagMode.SelfClosing,
|
||||
preElement: "Before",
|
||||
|
|
@ -1407,7 +1406,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
},
|
||||
{
|
||||
GetTagHelperOutput(
|
||||
tagName: null,
|
||||
tagName: "",
|
||||
attributes: new TagHelperAttributeList { { "test", "testVal" } },
|
||||
tagMode: TagMode.StartTagOnly,
|
||||
preElement: "Before",
|
||||
|
|
@ -1455,7 +1454,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
},
|
||||
{
|
||||
GetTagHelperOutput(
|
||||
tagName: null,
|
||||
tagName: "",
|
||||
attributes: new TagHelperAttributeList(),
|
||||
tagMode: TagMode.StartTagAndEndTag,
|
||||
preElement: null,
|
||||
|
|
@ -1467,7 +1466,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
},
|
||||
{
|
||||
GetTagHelperOutput(
|
||||
tagName: null,
|
||||
tagName: "",
|
||||
attributes: new TagHelperAttributeList { { "test", "testVal" } },
|
||||
tagMode: TagMode.SelfClosing,
|
||||
preElement: null,
|
||||
|
|
@ -1503,7 +1502,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
},
|
||||
{
|
||||
GetTagHelperOutput(
|
||||
tagName: null,
|
||||
tagName: "",
|
||||
attributes: new TagHelperAttributeList { { "test", "testVal" } },
|
||||
tagMode: TagMode.StartTagOnly,
|
||||
preElement: null,
|
||||
|
|
@ -1575,7 +1574,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
},
|
||||
{
|
||||
GetTagHelperOutput(
|
||||
tagName: null,
|
||||
tagName: "",
|
||||
attributes: new TagHelperAttributeList(),
|
||||
tagMode: TagMode.SelfClosing,
|
||||
preElement: "Before",
|
||||
|
|
@ -1599,7 +1598,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
},
|
||||
{
|
||||
GetTagHelperOutput(
|
||||
tagName: null,
|
||||
tagName: "",
|
||||
attributes: new TagHelperAttributeList(),
|
||||
tagMode: TagMode.StartTagOnly,
|
||||
preElement: "Before",
|
||||
|
|
@ -1611,7 +1610,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
},
|
||||
{
|
||||
GetTagHelperOutput(
|
||||
tagName: null,
|
||||
tagName: "",
|
||||
attributes: new TagHelperAttributeList(),
|
||||
tagMode: TagMode.StartTagAndEndTag,
|
||||
preElement: "Before",
|
||||
|
|
@ -1623,7 +1622,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
},
|
||||
{
|
||||
GetTagHelperOutput(
|
||||
tagName: null,
|
||||
tagName: "",
|
||||
attributes: new TagHelperAttributeList { { "test", "testVal" } },
|
||||
tagMode: TagMode.StartTagAndEndTag,
|
||||
preElement: "Before",
|
||||
|
|
@ -1790,8 +1789,9 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
return output;
|
||||
}
|
||||
|
||||
private static TestableRazorPage CreatePage(Action<TestableRazorPage> executeAction,
|
||||
ViewContext context = null)
|
||||
private static TestableRazorPage CreatePage(
|
||||
Action<TestableRazorPage> executeAction,
|
||||
ViewContext context = null)
|
||||
{
|
||||
return CreatePage(page =>
|
||||
{
|
||||
|
|
@ -1801,8 +1801,9 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
}
|
||||
|
||||
|
||||
private static TestableRazorPage CreatePage(Func<TestableRazorPage, Task> executeAction,
|
||||
ViewContext context = null)
|
||||
private static TestableRazorPage CreatePage(
|
||||
Func<TestableRazorPage, Task> executeAction,
|
||||
ViewContext context = null)
|
||||
{
|
||||
context = context ?? CreateViewContext();
|
||||
var view = new Mock<TestableRazorPage> { CallBase = true };
|
||||
|
|
@ -1832,13 +1833,18 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
new HtmlHelperOptions());
|
||||
}
|
||||
|
||||
private static Func<TextWriter, Task> CreateBodyAction(string value)
|
||||
private static Func<TextWriter, Task> CreateAsyncWriteDelegate(string value)
|
||||
{
|
||||
return async (writer) => await writer.WriteAsync(value);
|
||||
}
|
||||
|
||||
public abstract class TestableRazorPage : RazorPage
|
||||
{
|
||||
public TestableRazorPage()
|
||||
{
|
||||
HtmlEncoder = new CommonTestEncoder();
|
||||
}
|
||||
|
||||
public string RenderedContent
|
||||
{
|
||||
get
|
||||
|
|
|
|||
|
|
@ -1484,6 +1484,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
public TestableRazorPage(Action<TestableRazorPage> executeAction)
|
||||
{
|
||||
_executeAction = executeAction;
|
||||
HtmlEncoder = new CommonTestEncoder();
|
||||
}
|
||||
|
||||
public void RenderBodyPublic()
|
||||
|
|
|
|||
|
|
@ -279,10 +279,10 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
var generator = new TestableHtmlGenerator(new EmptyModelMetadataProvider());
|
||||
|
||||
var validationSummaryTagHelper = new ValidationSummaryTagHelper(generator);
|
||||
var expectedMessage = string.Format(
|
||||
@"The value of argument 'value' ({0}) is invalid for Enum type 'Microsoft.AspNet.Mvc.ValidationSummary'.
|
||||
Parameter name: value",
|
||||
validationSummary);
|
||||
var validationTypeName = typeof(ValidationSummary).FullName;
|
||||
var expectedMessage =
|
||||
$@"The value of argument 'value' ({validationSummary}) is invalid for Enum type '{validationTypeName}'.
|
||||
Parameter name: value";
|
||||
|
||||
// Act & Assert
|
||||
var ex = Assert.Throws<ArgumentException>(
|
||||
|
|
|
|||
|
|
@ -254,7 +254,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
public async Task ExecuteAsync_Throws_IfNoViewEngineCanBeResolved()
|
||||
{
|
||||
// Arrange
|
||||
var expected = "No service for type 'Microsoft.AspNet.Mvc.Rendering.ICompositeViewEngine'" +
|
||||
var expected = $"No service for type '{typeof(ICompositeViewEngine).FullName}'" +
|
||||
" has been registered.";
|
||||
|
||||
var view = Mock.Of<IView>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue