Clean up Project|SolutionExtensions

This commit is contained in:
Dustin Campbell 2024-07-23 16:55:42 -07:00
Родитель 5e72b6d3d9
Коммит 684af14712
2 изменённых файлов: 12 добавлений и 22 удалений

Просмотреть файл

@ -1,31 +1,18 @@
// 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;
namespace Microsoft.CodeAnalysis.Razor.Workspaces;
namespace Microsoft.CodeAnalysis;
internal static class ProjectExtensions
{
internal static Document GetRequiredDocument(this Project project, DocumentId documentId)
{
if (project is null)
{
throw new ArgumentNullException(nameof(project));
}
ArgHelper.ThrowIfNull(project);
ArgHelper.ThrowIfNull(documentId);
if (documentId is null)
{
throw new ArgumentNullException(nameof(documentId));
}
var document = project.GetDocument(documentId);
if (document is null)
{
throw new InvalidOperationException($"The document {documentId} did not exist in {project.Name}");
}
return document;
return project.GetDocument(documentId)
?? ThrowHelper.ThrowInvalidOperationException<Document>($"The document {documentId} did not exist in {project.Name}");
}
}

Просмотреть файл

@ -1,15 +1,18 @@
// 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;
namespace Microsoft.CodeAnalysis.Razor.Workspaces;
namespace Microsoft.CodeAnalysis;
internal static class SolutionExtensions
{
internal static Project GetRequiredProject(this Solution solution, ProjectId projectId)
{
ArgHelper.ThrowIfNull(solution);
ArgHelper.ThrowIfNull(projectId);
return solution.GetProject(projectId)
?? throw new InvalidOperationException($"The projectId {projectId} did not exist in {solution}.");
?? ThrowHelper.ThrowInvalidOperationException<Project>($"The projectId {projectId} did not exist in {solution}.");
}
}