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