Why does Type.IsGenericType return TRUE for Task without return type obtained by reflection from method but typeof(Task).IsGenericTyp returns FALSE

China☆狼群 提交于 2019-12-06 12:57:57

In some situations, the framework returns a Task<VoidTaskResult> disguised as a Task. Imagine you have some logic relying on TaskCompletionSource<T>. If you don't actually intend to return a result, you still have to fill the T generic parameter. You could use TaskCompletionSource<object>, but you would be wasting a pointer worth of memory (4 bytes in 32 bit, 8 bytes in 64 bit). To avoid that, the framework uses an empty struct: VoidTaskResult.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!