"one-to-one correspondence with files in a file system"

"one-to-one correspondence with files in a file system"

我已阅读 c# language specification :

Source files typically have a one-to-one correspondence with files in a file system, but this correspondence is not required

这到底是什么意思?

如前一行所述:

A source file is an ordered sequence of Unicode characters

这意味着 "source file" 不一定是文件系统上的文件。它可以是表示 UTF-16 字符的任何旧字节流。它可能来自内存流、网络或任何旧地方。但是通常它是文件系统上的一个文件。

我认为它的字面意思是每个源文件都由系统上的单个文件表示。

例如,假设我有一些源代码:

Using System;

namespace Test 
{
    public class Program 
    {
        private static void Main (string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

这可以作为 Program.cs 保存到文件系统。我们现在有一些源代码,它由系统上的单个文件表示。

but this correspondence is not required

表明源文件并不总是存在于系统中。例如,源可以作为 "sequence of Unicode characters" 而存在,它可以存储在内存中的某个位置。

使用 visual studio,您可以 "link" 项目中的源文件。 如果您将一个源文件放在一个项目中,并且 link 将相同的源文件放在不同的项目中(即在 2 个不同的项目中共享相同的源代码),您最终会得到 2 个源文件 linked单个文件。

我通常在具有多个项目的解决方案中使用此功能:共享源代码是这样的:

[assembly: AssemblyVersion("1.2.3.0")]
[assembly: AssemblyFileVersion("1.2.3.0")]

所以当符合时,我的解决方案中的每个程序集都有相同的版本号。