This commit is contained in:
parent
cd9899363f
commit
7b53ba1f6b
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
|||
ClassDeclarationIRNode @class,
|
||||
RazorMethodDeclarationIRNode method)
|
||||
{
|
||||
var filePath = codeDocument.GetRelativePath() ?? codeDocument.Source.Filename;
|
||||
var filePath = codeDocument.GetRelativePath() ?? codeDocument.Source.FileName;
|
||||
|
||||
base.OnDocumentStructureCreated(codeDocument, @namespace, @class, method);
|
||||
@class.Name = ClassName.GetClassNameFromPath(filePath);
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
|||
ClassDeclarationIRNode @class,
|
||||
RazorMethodDeclarationIRNode method)
|
||||
{
|
||||
var filePath = codeDocument.GetRelativePath() ?? codeDocument.Source.Filename;
|
||||
var filePath = codeDocument.GetRelativePath() ?? codeDocument.Source.FileName;
|
||||
|
||||
base.OnDocumentStructureCreated(codeDocument, @namespace, @class, method);
|
||||
@class.BaseType = "global::Microsoft.AspNetCore.Mvc.RazorPages.Page";
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
|||
throw new ArgumentNullException(nameof(codeDocument));
|
||||
}
|
||||
|
||||
_logger.GeneratedCodeToAssemblyCompilationStart(codeDocument.Source.Filename);
|
||||
_logger.GeneratedCodeToAssemblyCompilationStart(codeDocument.Source.FileName);
|
||||
|
||||
var startTimestamp = _logger.IsEnabled(LogLevel.Debug) ? Stopwatch.GetTimestamp() : 0;
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
|||
var assembly = LoadAssembly(assemblyStream, pdbStream);
|
||||
var type = assembly.GetExportedTypes().FirstOrDefault(a => !a.IsNested);
|
||||
|
||||
_logger.GeneratedCodeToAssemblyCompilationEnd(codeDocument.Source.Filename, startTimestamp);
|
||||
_logger.GeneratedCodeToAssemblyCompilationEnd(codeDocument.Source.FileName, startTimestamp);
|
||||
|
||||
return new CompilationResult(type);
|
||||
}
|
||||
|
|
@ -172,7 +172,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
|||
{
|
||||
if (diagnostic.Location == Location.None)
|
||||
{
|
||||
return codeDocument.Source.Filename;
|
||||
return codeDocument.Source.FileName;
|
||||
}
|
||||
|
||||
return diagnostic.Location.GetMappedLineSpan().Path;
|
||||
|
|
@ -196,7 +196,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
|||
|
||||
private static string GetContent(RazorCodeDocument codeDocument, string filePath)
|
||||
{
|
||||
if (filePath == codeDocument.Source.Filename)
|
||||
if (filePath == codeDocument.Source.FileName)
|
||||
{
|
||||
var chars = new char[codeDocument.Source.Length];
|
||||
codeDocument.Source.CopyTo(0, chars, 0, chars.Length);
|
||||
|
|
@ -206,7 +206,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
|||
for (var i = 0; i < codeDocument.Imports.Count; i++)
|
||||
{
|
||||
var import = codeDocument.Imports[i];
|
||||
if (filePath == import.Filename)
|
||||
if (filePath == import.FileName)
|
||||
{
|
||||
var chars = new char[codeDocument.Source.Length];
|
||||
codeDocument.Source.CopyTo(0, chars, 0, chars.Length);
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
|||
writer.Flush();
|
||||
|
||||
stream.Seek(0L, SeekOrigin.Begin);
|
||||
GlobalImports = RazorSourceDocument.ReadFrom(stream, filename: null, encoding: Encoding.UTF8);
|
||||
GlobalImports = RazorSourceDocument.ReadFrom(stream, fileName: null, encoding: Encoding.UTF8);
|
||||
}
|
||||
|
||||
public RazorSourceDocument GlobalImports { get; }
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
|||
{
|
||||
foreach (var item in _project.EnumerateItems(_pagesOptions.RootDirectory))
|
||||
{
|
||||
if (item.Filename.StartsWith("_"))
|
||||
if (item.FileName.StartsWith("_"))
|
||||
{
|
||||
// Pages like _PageImports should not be routable.
|
||||
continue;
|
||||
|
|
@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
|||
var routePrefix = item.PathWithoutExtension;
|
||||
model.Selectors.Add(CreateSelectorModel(routePrefix, template));
|
||||
|
||||
if (string.Equals(IndexFileName, item.Filename, StringComparison.OrdinalIgnoreCase))
|
||||
if (string.Equals(IndexFileName, item.FileName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var parentDirectoryPath = item.Path;
|
||||
var index = parentDirectoryPath.LastIndexOf('/');
|
||||
|
|
|
|||
|
|
@ -161,15 +161,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
|||
|
||||
private RazorCodeDocument CreateDocument(string content)
|
||||
{
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(content);
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
stream.Seek(0L, SeekOrigin.Begin);
|
||||
|
||||
var source = RazorSourceDocument.ReadFrom(stream, "test.cshtml");
|
||||
return RazorCodeDocument.Create(source);
|
||||
}
|
||||
var source = RazorSourceDocument.Create(content, "test.cshtml");
|
||||
return RazorCodeDocument.Create(source);
|
||||
}
|
||||
|
||||
private ClassDeclarationIRNode FindClassNode(RazorIRNode node)
|
||||
|
|
|
|||
|
|
@ -156,15 +156,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
|||
|
||||
private RazorCodeDocument CreateDocument(string content)
|
||||
{
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(content);
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
stream.Seek(0L, SeekOrigin.Begin);
|
||||
|
||||
var source = RazorSourceDocument.ReadFrom(stream, "test.cshtml");
|
||||
return RazorCodeDocument.Create(source);
|
||||
}
|
||||
var source = RazorSourceDocument.Create(content, "test.cshtml");
|
||||
return RazorCodeDocument.Create(source);
|
||||
}
|
||||
|
||||
private ClassDeclarationIRNode FindClassNode(RazorIRNode node)
|
||||
|
|
|
|||
|
|
@ -167,15 +167,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
|||
|
||||
private RazorCodeDocument CreateDocument(string content)
|
||||
{
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(content);
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
stream.Seek(0L, SeekOrigin.Begin);
|
||||
|
||||
var source = RazorSourceDocument.ReadFrom(stream, "test.cshtml");
|
||||
return RazorCodeDocument.Create(source);
|
||||
}
|
||||
var source = RazorSourceDocument.Create(content, "test.cshtml");
|
||||
return RazorCodeDocument.Create(source);
|
||||
}
|
||||
|
||||
private RazorEngine CreateEngine(params TagHelperDescriptor[] tagHelpers)
|
||||
|
|
|
|||
|
|
@ -195,12 +195,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
|||
{
|
||||
filePath = filePath ?? Path.Combine(Directory.GetCurrentDirectory(), "Test.cshtml");
|
||||
|
||||
var bytes = Encoding.UTF8.GetBytes(content);
|
||||
using (var stream = new MemoryStream(bytes))
|
||||
{
|
||||
var source = RazorSourceDocument.ReadFrom(stream, filePath);
|
||||
return RazorCodeDocument.Create(source);
|
||||
}
|
||||
var source = RazorSourceDocument.Create(content, filePath);
|
||||
return RazorCodeDocument.Create(source);
|
||||
}
|
||||
|
||||
private static RazorEngine CreateEngine() => RazorEngine.Create();
|
||||
|
|
|
|||
|
|
@ -215,12 +215,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
|||
{
|
||||
filePath = filePath ?? Path.Combine(Directory.GetCurrentDirectory(), "Test.cshtml");
|
||||
|
||||
var bytes = Encoding.UTF8.GetBytes(content);
|
||||
using (var stream = new MemoryStream(bytes))
|
||||
{
|
||||
var source = RazorSourceDocument.ReadFrom(stream, filePath);
|
||||
return RazorCodeDocument.Create(source);
|
||||
}
|
||||
var source = RazorSourceDocument.Create(content, filePath);
|
||||
return RazorCodeDocument.Create(source);
|
||||
}
|
||||
|
||||
private static RazorEngine CreateEngine()
|
||||
|
|
|
|||
|
|
@ -319,15 +319,8 @@ public class __Generated__TagCloudViewComponentTagHelper : Microsoft.AspNetCore.
|
|||
|
||||
private RazorCodeDocument CreateDocument(string content)
|
||||
{
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(content);
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
stream.Seek(0L, SeekOrigin.Begin);
|
||||
|
||||
var source = RazorSourceDocument.ReadFrom(stream, "test.cshtml");
|
||||
return RazorCodeDocument.Create(source);
|
||||
}
|
||||
var source = RazorSourceDocument.Create(content, "test.cshtml");
|
||||
return RazorCodeDocument.Create(source);
|
||||
}
|
||||
|
||||
private RazorEngine CreateEngine(params TagHelperDescriptor[] tagHelpers)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class MyTestType {}";
|
|||
|
||||
var compilationService = GetRoslynCompilationService();
|
||||
|
||||
var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.ReadFrom(CreateStreamContent(), "test.cshtml"));
|
||||
var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("Hello world", "test.cshtml"));
|
||||
|
||||
var csharpDocument = new RazorCSharpDocument()
|
||||
{
|
||||
|
|
@ -53,7 +53,7 @@ public class MyTestType {}";
|
|||
this should fail";
|
||||
|
||||
var compilationService = GetRoslynCompilationService();
|
||||
var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.ReadFrom(CreateStreamContent(fileContent), viewPath));
|
||||
var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create(fileContent, viewPath));
|
||||
|
||||
var csharpDocument = new RazorCSharpDocument()
|
||||
{
|
||||
|
|
@ -80,7 +80,7 @@ this should fail";
|
|||
var content = "this should fail";
|
||||
|
||||
var compilationService = GetRoslynCompilationService();
|
||||
var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.ReadFrom(CreateStreamContent(fileContent), viewPath));
|
||||
var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create(fileContent, viewPath));
|
||||
|
||||
var csharpDocument = new RazorCSharpDocument()
|
||||
{
|
||||
|
|
@ -114,7 +114,7 @@ public class MyNonCustomDefinedClass {}
|
|||
var options = GetOptions();
|
||||
options.ParseOptions = options.ParseOptions.WithPreprocessorSymbols("MY_CUSTOM_DEFINE");
|
||||
var compilationService = GetRoslynCompilationService(options: options);
|
||||
var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.ReadFrom(CreateStreamContent(), viewPath));
|
||||
var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("Hello world", viewPath));
|
||||
|
||||
var csharpDocument = new RazorCSharpDocument()
|
||||
{
|
||||
|
|
@ -136,7 +136,7 @@ public class MyNonCustomDefinedClass {}
|
|||
var viewPath = "Views/Home/Index";
|
||||
var generatedCodeFileName = "Generated Code";
|
||||
var compilationService = GetRoslynCompilationService();
|
||||
var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.ReadFrom(CreateStreamContent("view-content"), viewPath));
|
||||
var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("view-content", viewPath));
|
||||
var assemblyName = "random-assembly-name";
|
||||
|
||||
var diagnostics = new[]
|
||||
|
|
@ -220,7 +220,7 @@ public class MyNonCustomDefinedClass {}
|
|||
var options = GetOptions(c => usedCompilation = c);
|
||||
var compilationService = GetRoslynCompilationService(options: options);
|
||||
|
||||
var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.ReadFrom(CreateStreamContent(), "some-relative-path"));
|
||||
var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("Hello world", "some-relative-path"));
|
||||
|
||||
var csharpDocument = new RazorCSharpDocument()
|
||||
{
|
||||
|
|
@ -244,7 +244,7 @@ public class MyNonCustomDefinedClass {}
|
|||
});
|
||||
var content = "public class MyTestType {}";
|
||||
var compilationService = GetRoslynCompilationService(options: options);
|
||||
var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.ReadFrom(CreateStreamContent(), "some-relative-path.cshtml"));
|
||||
var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("Hello world", "some-relative-path.cshtml"));
|
||||
|
||||
var csharpDocument = new RazorCSharpDocument()
|
||||
{
|
||||
|
|
@ -274,7 +274,7 @@ public class MyNonCustomDefinedClass {}
|
|||
var applicationPartManager = new ApplicationPartManager();
|
||||
var compilationService = GetRoslynCompilationService(applicationPartManager, options);
|
||||
|
||||
var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.ReadFrom(CreateStreamContent(), "some-relative-path.cshtml"));
|
||||
var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("Hello world", "some-relative-path.cshtml"));
|
||||
|
||||
var csharpDocument = new RazorCSharpDocument()
|
||||
{
|
||||
|
|
@ -340,19 +340,5 @@ public class MyNonCustomDefinedClass {}
|
|||
optionsAccessor,
|
||||
NullLoggerFactory.Instance);
|
||||
}
|
||||
|
||||
private static MemoryStream CreateStreamContent(string content = "Hello, World!", Encoding encoding = null)
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
encoding = encoding ?? Encoding.UTF8;
|
||||
using (var writer = new StreamWriter(stream, encoding, bufferSize: 1024, leaveOpen: true))
|
||||
{
|
||||
writer.Write(content);
|
||||
}
|
||||
|
||||
stream.Seek(0L, SeekOrigin.Begin);
|
||||
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
|||
Diagnostics = new List<RazorDiagnostic>()
|
||||
});
|
||||
|
||||
Assert.Equal(viewPath, document.Source.Filename); // Assert if source file name is the root relative path
|
||||
Assert.Equal(viewPath, document.Source.FileName); // Assert if source file name is the root relative path
|
||||
}).Verifiable();
|
||||
|
||||
var razorService = new RazorCompilationService(
|
||||
|
|
|
|||
Loading…
Reference in New Issue