parent
053121e0b7
commit
14abd88648
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
|
|||
}
|
||||
|
||||
// Don't add MVC imports for a component - this shouldn't happen for v1, but just in case.
|
||||
if (string.Equals(projectItem.FileKind, FileKinds.Component, StringComparison.OrdinalIgnoreCase))
|
||||
if (FileKinds.IsComponent(projectItem.FileKind))
|
||||
{
|
||||
return Array.Empty<RazorProjectItem>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X
|
|||
}
|
||||
|
||||
// Don't add MVC imports for a component - this shouldn't happen for v2, but just in case.
|
||||
if (string.Equals(projectItem.FileKind, FileKinds.Component, StringComparison.OrdinalIgnoreCase))
|
||||
if (FileKinds.IsComponent(projectItem.FileKind))
|
||||
{
|
||||
return Array.Empty<RazorProjectItem>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
}
|
||||
|
||||
// Don't add MVC imports for a component
|
||||
if (string.Equals(projectItem.FileKind, FileKinds.Component, StringComparison.OrdinalIgnoreCase))
|
||||
if (FileKinds.IsComponent(projectItem.FileKind))
|
||||
{
|
||||
return Array.Empty<RazorProjectItem>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
|||
|
||||
protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
|
||||
{
|
||||
return string.Equals(codeDocument.GetFileKind(), FileKinds.Component);
|
||||
return FileKinds.IsComponent(codeDocument.GetFileKind());
|
||||
}
|
||||
|
||||
protected override CodeTarget CreateTarget(RazorCodeDocument codeDocument, RazorCodeGenerationOptions options)
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
|
|||
}
|
||||
|
||||
// Don't add Component imports for a non-component.
|
||||
if (!string.Equals(projectItem.FileKind, FileKinds.Component, StringComparison.OrdinalIgnoreCase))
|
||||
if (!FileKinds.IsComponent(projectItem.FileKind))
|
||||
{
|
||||
return Array.Empty<RazorProjectItem>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// We need to decide up front if this document is a "component" file. This will affect how
|
||||
// lowering behaves.
|
||||
LoweringVisitor visitor;
|
||||
if (string.Equals(FileKinds.Component, codeDocument.GetFileKind(), StringComparison.OrdinalIgnoreCase) &&
|
||||
if (FileKinds.IsComponent(codeDocument.GetFileKind()) &&
|
||||
syntaxTree.Options.FeatureFlags.AllowComponentFileKind)
|
||||
{
|
||||
visitor = new ComponentFileKindVisitor(document, builder, syntaxTree.Options.FeatureFlags)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Microsoft.AspNetCore.Razor.Language
|
||||
{
|
||||
public static class FileKinds
|
||||
|
|
@ -8,5 +11,28 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
public static readonly string Component = "component";
|
||||
|
||||
public static readonly string Legacy = "mvc";
|
||||
|
||||
public static bool IsComponent(string fileKind)
|
||||
{
|
||||
// fileKind might be null.
|
||||
return string.Equals(fileKind, FileKinds.Component, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public static string GetFileKindFromFilePath(string filePath)
|
||||
{
|
||||
if (filePath == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(filePath));
|
||||
}
|
||||
|
||||
if (string.Equals(".razor", Path.GetExtension(filePath), StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return FileKinds.Component;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FileKinds.Legacy;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Razor.Language.Components;
|
||||
using Microsoft.AspNetCore.Razor.Language.Intermediate;
|
||||
|
||||
namespace Microsoft.AspNetCore.Razor.Language
|
||||
{
|
||||
|
|
@ -45,18 +42,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
get
|
||||
{
|
||||
if (FilePath == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (string.Equals(".razor", Path.GetExtension(FilePath), StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return FileKinds.Component;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FileKinds.Legacy;
|
||||
}
|
||||
return FilePath == null ? null : FileKinds.GetFileKindFromFilePath(FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue