Resharper 刚刚向我建议了以下重构:
// Constructor initializes InitializedProperty but
// the UninitializedSubproperty is uninitialized.
var myInstance = new MyClass();
myInstance.InitializedProperty.UninitializedSubproperty = new MyOtherClass();
// becomes
var myInstance = new MyClass
{
InitializedProperty = { UninitializedSubproperty = new MyOtherClass() }
};
我以前从未见过这种对象初始化。特别是我不明白如何
InitializedProperty = { UninitializedSubproperty = new MyOtherClass() }
有任何意义 - 它没有分配任何东西给InitializedProperty
.
这种行为是否在任何地方指定?