如何在 C# 中编译 System.Console
How to compile System.Console in C#
所以我查看了 System.Console here 的源代码。
我认为看看它是如何实现的并可能自己进行一些更改会很有趣。
所以我直接从微软的example中复制源码粘贴在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
我强烈怀疑我缺少一些程序集参考。如果你知道它们是什么,请告诉我,以便我编译。
您不知道 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/corefx and https://github.com/dotnet/coreclr . More things are coming, so you can keep an eye on http://dotnet.github.io/
所以我查看了 System.Console here 的源代码。
我认为看看它是如何实现的并可能自己进行一些更改会很有趣。
所以我直接从微软的example中复制源码粘贴在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
我强烈怀疑我缺少一些程序集参考。如果你知道它们是什么,请告诉我,以便我编译。
您不知道 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/corefx and https://github.com/dotnet/coreclr . More things are coming, so you can keep an eye on http://dotnet.github.io/