зеркало из https://github.com/dotnet/razor.git
Convert HostDocument to a record
This commit is contained in:
Родитель
6f378ca07d
Коммит
74641d049e
|
@ -1,38 +1,20 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT license. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
|
||||
namespace Microsoft.CodeAnalysis.Razor.ProjectSystem;
|
||||
|
||||
internal class HostDocument
|
||||
internal sealed record class HostDocument
|
||||
{
|
||||
public string FileKind { get; }
|
||||
public string FilePath { get; }
|
||||
public string TargetPath { get; }
|
||||
public string FileKind { get; init; }
|
||||
public string FilePath { get; init; }
|
||||
public string TargetPath { get; init; }
|
||||
|
||||
public HostDocument(HostDocument other)
|
||||
public HostDocument(string filePath, string targetPath, string? fileKind = null)
|
||||
{
|
||||
if (other is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(other));
|
||||
}
|
||||
|
||||
FileKind = other.FileKind;
|
||||
FilePath = other.FilePath;
|
||||
TargetPath = other.TargetPath;
|
||||
}
|
||||
|
||||
public HostDocument(string filePath, string targetPath)
|
||||
: this(filePath, targetPath, fileKind: null)
|
||||
{
|
||||
}
|
||||
|
||||
public HostDocument(string filePath, string targetPath, string? fileKind)
|
||||
{
|
||||
FilePath = filePath ?? throw new ArgumentNullException(nameof(filePath));
|
||||
TargetPath = targetPath ?? throw new ArgumentNullException(nameof(targetPath));
|
||||
FilePath = filePath;
|
||||
TargetPath = targetPath;
|
||||
FileKind = fileKind ?? FileKinds.GetFileKindFromFilePath(filePath);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,15 +15,16 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem;
|
|||
|
||||
public class DefaultDocumentSnapshotTest : WorkspaceTestBase
|
||||
{
|
||||
private static readonly HostDocument s_componentHostDocument = TestProjectData.SomeProjectComponentFile1;
|
||||
private static readonly HostDocument s_componentCshtmlHostDocument = TestProjectData.SomeProjectCshtmlComponentFile5;
|
||||
private static readonly HostDocument s_legacyHostDocument = TestProjectData.SomeProjectFile1;
|
||||
private static readonly HostDocument s_nestedComponentHostDocument = TestProjectData.SomeProjectNestedComponentFile3;
|
||||
|
||||
private readonly SourceText _sourceText;
|
||||
private readonly VersionStamp _version;
|
||||
private readonly HostDocument _componentHostDocument;
|
||||
private readonly HostDocument _componentCshtmlHostDocument;
|
||||
private readonly HostDocument _legacyHostDocument;
|
||||
private readonly DocumentSnapshot _componentDocument;
|
||||
private readonly DocumentSnapshot _componentCshtmlDocument;
|
||||
private readonly DocumentSnapshot _legacyDocument;
|
||||
private readonly HostDocument _nestedComponentHostDocument;
|
||||
private readonly DocumentSnapshot _nestedComponentDocument;
|
||||
|
||||
public DefaultDocumentSnapshotTest(ITestOutputHelper testOutput)
|
||||
|
@ -32,27 +33,21 @@ public class DefaultDocumentSnapshotTest : WorkspaceTestBase
|
|||
_sourceText = SourceText.From("<p>Hello World</p>");
|
||||
_version = VersionStamp.Create();
|
||||
|
||||
// Create a new HostDocument to avoid mutating the code container
|
||||
_componentCshtmlHostDocument = new HostDocument(TestProjectData.SomeProjectCshtmlComponentFile5);
|
||||
_componentHostDocument = new HostDocument(TestProjectData.SomeProjectComponentFile1);
|
||||
_legacyHostDocument = new HostDocument(TestProjectData.SomeProjectFile1);
|
||||
_nestedComponentHostDocument = new HostDocument(TestProjectData.SomeProjectNestedComponentFile3);
|
||||
|
||||
var projectState = ProjectState.Create(ProjectEngineFactoryProvider, TestProjectData.SomeProject, ProjectWorkspaceState.Default);
|
||||
var project = new ProjectSnapshot(projectState);
|
||||
|
||||
var textAndVersion = TextAndVersion.Create(_sourceText, _version);
|
||||
|
||||
var documentState = DocumentState.Create(_legacyHostDocument, () => Task.FromResult(textAndVersion));
|
||||
var documentState = DocumentState.Create(s_legacyHostDocument, () => Task.FromResult(textAndVersion));
|
||||
_legacyDocument = new DocumentSnapshot(project, documentState);
|
||||
|
||||
documentState = DocumentState.Create(_componentHostDocument, () => Task.FromResult(textAndVersion));
|
||||
documentState = DocumentState.Create(s_componentHostDocument, () => Task.FromResult(textAndVersion));
|
||||
_componentDocument = new DocumentSnapshot(project, documentState);
|
||||
|
||||
documentState = DocumentState.Create(_componentCshtmlHostDocument, () => Task.FromResult(textAndVersion));
|
||||
documentState = DocumentState.Create(s_componentCshtmlHostDocument, () => Task.FromResult(textAndVersion));
|
||||
_componentCshtmlDocument = new DocumentSnapshot(project, documentState);
|
||||
|
||||
documentState = DocumentState.Create(_nestedComponentHostDocument, () => Task.FromResult(textAndVersion));
|
||||
documentState = DocumentState.Create(s_nestedComponentHostDocument, () => Task.FromResult(textAndVersion));
|
||||
_nestedComponentDocument = new DocumentSnapshot(project, documentState);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче