MetadataSymbolReferenceCodeAction.cs 1.4 KB
Newer Older
J
Jonathon Marolf 已提交
1 2 3
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
4 5

using System.Linq;
6 7
using System.Threading;
using System.Threading.Tasks;
8 9
using Roslyn.Utilities;

10
namespace Microsoft.CodeAnalysis.AddImport
11
{
12
    internal abstract partial class AbstractAddImportFeatureService<TSimpleNameSyntax>
13 14 15
    {
        private class MetadataSymbolReferenceCodeAction : SymbolReferenceCodeAction
        {
16 17
            public MetadataSymbolReferenceCodeAction(Document originalDocument, AddImportFixData fixData)
                : base(originalDocument, fixData)
18
            {
19
                Contract.ThrowIfFalse(fixData.Kind == AddImportFixKind.MetadataSymbol);
20 21
            }

22
            protected override Task<Project> UpdateProjectAsync(Project project, bool isPreview, CancellationToken cancellationToken)
23
            {
24
                var projectWithReference = project.Solution.GetProject(FixData.PortableExecutableReferenceProjectId);
25 26
                var reference = projectWithReference.MetadataReferences
                                                    .OfType<PortableExecutableReference>()
27
                                                    .First(pe => pe.FilePath == FixData.PortableExecutableReferenceFilePathToAdd);
28

29
                return Task.FromResult(project.AddMetadataReference(reference));
30 31 32
            }
        }
    }
S
Sam Harwell 已提交
33
}