MetadataSymbolReferenceCodeAction.cs 1.3 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 6 7

using System.Linq;
using Roslyn.Utilities;

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

            protected override Project UpdateProject(Project project)
            {
22
                var projectWithReference = project.Solution.GetProject(FixData.PortableExecutableReferenceProjectId);
23 24
                var reference = projectWithReference.MetadataReferences
                                                    .OfType<PortableExecutableReference>()
25
                                                    .First(pe => pe.FilePath == FixData.PortableExecutableReferenceFilePathToAdd);
26 27 28 29 30

                return project.AddMetadataReference(reference);
            }
        }
    }
S
Sam Harwell 已提交
31
}