整个解决方案中使用的 C# 字符串常量集合,HOW?

C# Collection of string constants used in the entire solution, HOW?

我目前正在制作一个 windows phone 应用程序,我只是在查看 Microsoft 提供的 WinRT 背景音频示例。 该解决方案有三个项目,我们称它们为 P1、P2 和 P3 在 P1 中有一个名为常量的单独 class 文件,其中包含一组字符串,如下面的剪辑所示

 namespace BackgroundAudioPlayerCS
   {
    /// <summary>
    /// Collection of string constants used in the entire solution. 
    /// This file is shared for all projects
    /// </summary>
class Constants
{
    public const string CurrentTrack = "trackname";
    public const string BackgroundTaskStarted = "BackgroundTaskStarted";
}

在 P2 和 P3 中还有一个名为 constants 的文件,除了我不同的图标,它说 C++ 带有一个蓝色的小箭头,但是如果你打开 P2 或 P3 常量文件,它会打开 P1 文件。

我试图在我的项目中重复这个 在他们的应用程序中,当您调用字符串时,即 CurrentTrack,您不需要在任何项目中编写 Constants.CurrentTrack,因为我的项目只能从它所在的项目访问并使用 Constants.string。

此外,P1 未引用任何其他项目。

怎么做到的?

编辑**

Link : https://code.msdn.microsoft.com/windowsapps/BackgroundAudio-63bbc319

这可以分两部分解决。

对于第一部分,我不明白如何在不通过 Constants class 的情况下检索任何这些常量的值.通常,您总是需要通过 ex.: Constants.CurrentTrack 来检索值,除非您在 Constants class 内,否则您永远不能直接调用 CurrentTrack

对于第二部分,这很容易。在 first 项目中创建 Constants 文件,然后,您只需将文件添加到 secondthird 个项目使用 Add-->Add Existing Item-->Add as Link 如图所示 here