更新时间:2023-01-30 13:13:44
异步/计谋
无非是C#5.0编译器改造。没有异步/计谋
在 IL
的水平。
async/await
is nothing but C# 5.0 compiler transformation. There is no async/await
at IL
level.
一个简单的例子是使用(){}
语句,这也是一个编译器改造。它只是转换了使用
语句尝试/终于
块。然而,在存在的IDisposable
接口的依赖关系是在.NET 1.1中定义。
One simple example would be the using() { }
statement which is also a compiler transformation. It just converts the using
statement to try/finally
block. However, there is a dependency on existence of IDisposable
interface which is defined in .NET 1.1.
同样,异步/计谋
转变依赖于某些类型的如 IAsyncStateMachine
接口,这是在.NET 4.5中定义。该 Microsoft.Bcl.Async
获得这些类型定义到.NET 4.0。
Similarly, the async/await
transformation depends on certain types like IAsyncStateMachine
interface which are defined in .NET 4.5. The Microsoft.Bcl.Async
gets those type definitions to .NET 4.0.
修改
如何在Microsoft.Bcl.Async组件会导致编译器来识别一个新的关键字(异步/等待)?
How does the Microsoft.Bcl.Async assembly cause the compiler to recognize a new keyword (async/await)?
没有事实并非如此。 C#5.0编译器已经知道的关键字和如何处理它们。然而,它不能找到所需的类型作为项目的目标是到.NET 4.0。该 Microsoft.Bcl.Async
包带来了这些类型。
No it does not. C# 5.0 compiler already knows about the keywords and what to do with them. However, it can't find the required types as project is targeted to .NET 4.0. The Microsoft.Bcl.Async
package brings in those types.