When using complex collection initializer syntax one should first assign the object to a local variable. When the object is built and assigned to a local variable one is free to use it and assign for example to a field. The error message:
Example: 15 var p = new Dictionary<SolutionProjectLanguageMethod, object>
16 { 17 { 18 new SolutionProjectLanguageMethod 19 { 20 IsProperty = true, 21 Name = "set_Feature", 22 DeclaringType = Type 23 }, 24 new PseudoConstantExpression 25 { 26 Value = "merge" 27 } 28 } 29 }; 30 31 this.Properties = p; To work around this limitation one should refactor the code. Example: 15 var set_Feature = new SolutionProjectLanguageMethod 16 { 17 IsProperty = true, 18 Name = "set_Feature", 19 DeclaringType = Type 20 }; 21 var merge = new PseudoConstantExpression 22 { 23 Value = "merge" 24 }; 25 26 var p = new Dictionary<SolutionProjectLanguageMethod, object> 27 { 28 { set_Feature, merge} 29 }; 30 31 this.Properties = p; |