Skip to content

Commit

Permalink
Remove implicit unsafe cast in foreach
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Aug 13, 2024
1 parent a8a4d8c commit f414bd2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,11 @@ public static ProjectUpdateState AddProjectOutputPath_NoLock(
}

/// <summary>
/// Attempts to convert all metadata references to <paramref name="outputPath"/> to a project reference to <paramref name="projectIdToReference"/>.
/// Attempts to convert all metadata references to <paramref name="outputPath"/> to a project reference to <paramref
/// name="projectIdToReference"/>.
/// </summary>
/// <param name="projectIdToReference">The <see cref="ProjectId"/> of the project that could be referenced in place of the output path.</param>
/// <param name="projectIdToReference">The <see cref="ProjectId"/> of the project that could be referenced in place
/// of the output path.</param>
/// <param name="outputPath">The output path to replace.</param>
[PerformanceSensitive("https://github.com/dotnet/roslyn/issues/31306",
Constraint = "Avoid calling " + nameof(CodeAnalysis.Solution.GetProject) + " to avoid realizing all projects.")]
Expand All @@ -542,9 +544,10 @@ private static ProjectUpdateState ConvertMetadataReferencesToProjectReferences_N
{
if (CanConvertMetadataReferenceToProjectReference(solutionChanges.Solution, projectIdToRetarget, referencedProjectId: projectIdToReference))
{
// PERF: call GetProjectState instead of GetProject, otherwise creating a new project might force all
// Project instances to get created.
foreach (PortableExecutableReference reference in solutionChanges.Solution.GetProjectState(projectIdToRetarget)!.MetadataReferences)
// PERF: call GetRequiredProjectState instead of GetRequiredProject, otherwise creating a new project
// might force all Project instances to get created.
var projectState = solutionChanges.Solution.GetRequiredProjectState(projectIdToRetarget);
foreach (var reference in projectState.MetadataReferences.OfType<PortableExecutableReference>())
{
if (string.Equals(reference.FilePath, outputPath, StringComparison.OrdinalIgnoreCase))
{
Expand All @@ -560,8 +563,8 @@ private static ProjectUpdateState ConvertMetadataReferencesToProjectReferences_N
projectUpdateState = projectUpdateState.WithProjectReferenceInfo(projectIdToRetarget,
projectInfo.WithConvertedProjectReference(reference.FilePath!, projectReference));

// We have converted one, but you could have more than one reference with different aliases
// that we need to convert, so we'll keep going
// We have converted one, but you could have more than one reference with different aliases that
// we need to convert, so we'll keep going
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ private DocumentInfo CreateDocumentInfo(DocumentId documentId, string name, Sour
filePath: filePath);
}

private ProjectState GetRequiredProjectState(ProjectId projectId)
internal ProjectState GetRequiredProjectState(ProjectId projectId)
=> this.SolutionState.GetProjectState(projectId) ?? throw new InvalidOperationException(string.Format(WorkspacesResources._0_is_not_part_of_the_workspace, projectId));

/// <summary>
Expand Down

0 comments on commit f414bd2

Please sign in to comment.