如何在C#中编译System.Console

时间:2015-02-07 04:52:03

标签: c# .net

所以我看一下System.Console here的源代码。

我认为看看它是如何实现并且可能自己进行一些更改会很有趣。

因此,我直接从Microsoft的示例中复制了源代码,并将其粘贴到Visual Studio中。

它无法编译。

Win32Native.Beep(frequency, duration);

有这样的几行。所有这些都有相同的错误消息。

Error   32  The type or namespace name 'Win32Native' could not be found (are you missing a using directive or an assembly reference?)   

大约有一百条错误消息,但只有4条独特的消息。包括上面的主要内容。

Error   85  The name '__Error' does not exist in the current context    

Error   89  Cannot take the address of, get the size of, or declare a pointer to a managed type ('Win32Native.CHAR_INFO')

Error   18  The property or indexer 'System.Console.InternalSyncObject' cannot be used in this context because it lacks the get accessor

我强烈怀疑我缺少一些汇编引用。如果你知道它们是什么让我知道,这样我就可以编译它。

1 个答案:

答案 0 :(得分:2)

您不知道Microsoft在GitHub上发布了可编译的源代码吗?

https://github.com/dotnet/corefx/tree/master/src/System.Console/src

要进行编译,请按this guide

背后的理性就是这样,

  • 以前,在非OSI兼容许可下,参考源已经可用。由于缺少文件,您无法编译它们。现在,Microsoft将它们置于符合OSI的许可证下。
  • Microsoft正在将参考源和一些其他私有源文件一起发布,以在GitHub上形成新的开源.NET Core堆栈。

您现在可以找到https://github.com/dotnet/corefxhttps://github.com/dotnet/coreclr。更多的事情即将到来,所以你可以关注http://dotnet.github.io/