为什么要懒惰?强制序列化期间初始化? [英] Why Lazy<T> forces initialization during serialization?
本文介绍了为什么要懒惰?强制序列化期间初始化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我检查Lazy < T>
类的实现时,我看到了以下代码块:
When I checked the implementation of Lazy<T>
class, I saw this block:
[OnSerializing]
private void OnSerializing(StreamingContext context)
{
T obj = this.Value;
}
如您所见,它在序列化过程中强制初始化.有谁知道为什么将这种行为作为默认设置?
As you can see it's forcing initialization during serialization. Does anyone know why this behavior is preferred as default?
推荐答案
如果没有,并且您提供了lambda进行初始化,那么您认为它在哪里反序列化了呢?Lambda无法序列化.
if it doesnt and you provided lambda for initialization, where do you think it retrives the value on deserializing? lambdas are not serializable.
这篇关于为什么要懒惰?强制序列化期间初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文