wiki‎ > ‎Documentation‎ > ‎Knowledge Base‎ > ‎

Collection Initializer

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:
"a load instruction was selected as prestatement. this is a bug within jsc. type: ScriptCoreLib.Ultra.Studio.StockAttributes.StockAttributeObfuscation offset: 0x002d  method:Void .ctor() [0x002d] ldloc.3    +1 -0"

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;


The example above is still too complex for jsc due to the object member initializers nested in a collection initializer.

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;


This limitation will be removed in the future versions of the compiler.