Resharper has just suggested the following refactoring to me:
// 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() }
};
I've never seen this kind of object initialization before. In particular I don't see how
InitializedProperty = { UninitializedSubproperty = new MyOtherClass() }
makes any sense - it's not assigning anything to InitializedProperty
.
Is this behaviour specified anywhere?