CodeAnalysisResources.cs 1.7 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.
B
Brett Forsgren 已提交
4 5

using System.Resources;
6 7 8 9 10 11 12 13

namespace Microsoft.CodeAnalysis
{
    // This class exists as a way to load resources from the Microsoft.CodeAnalysis.CodeAnalysisResources class from
    // the Microsoft.CodeAnalysis assembly.  Microsoft.CodeAnalysis.CodeAnalysisResources is internal but we can't add
    // InternalsVisibleTo(this-assembly) because there are numerous shared (linked) files common to both
    // Microsoft.CodeAnalysis and Microsoft.CodeAnalysis.Workspaces and that gives us major issues with duplicate 
    // internal types that suddenly become visible (e.g., SpecializedCollections) and that leads down a rabbit hole
14
    // of requiring assembly aliasing that would make many tests in this project unreadable.  The decision was made to
15 16 17 18 19 20
    // manually load the few resources we need from the CodeAnalysis assembly at the cost of Find All References and
    // Rename not working as expected.
    internal static class CodeAnalysisResources
    {
        public static string InMemoryAssembly => GetString("InMemoryAssembly");

J
Jared Parsons 已提交
21
        private static ResourceManager s_codeAnalysisResourceManager;
22 23 24

        private static string GetString(string resourceName)
        {
J
Jared Parsons 已提交
25
            if (s_codeAnalysisResourceManager == null)
26
            {
27
                s_codeAnalysisResourceManager = new ResourceManager(typeof(CodeAnalysisResources).FullName, typeof(Compilation).Assembly);
28 29
            }

J
Jared Parsons 已提交
30
            return s_codeAnalysisResourceManager.GetString(resourceName);
31 32 33
        }
    }
}