blah
[mono.git] / mcs / class / System.Core / System.Linq.Expressions / ListInitExpression.cs
index 48de4846f2a2fa29d35280e58d91687851daf109..30915a89dc3b28933cae728236ef027a61509023 100644 (file)
@@ -1,77 +1,63 @@
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-//\r
-// Authors:\r
-//        Antonello Provenzano  <antonello@deveel.com>\r
-//\r
-\r
-using System.Collections.ObjectModel;\r
-using System.Text;\r
-\r
-namespace System.Linq.Expressions\r
-{\r
-    public sealed class ListInitExpression : Expression\r
-    {\r
-        #region .ctor\r
-        internal ListInitExpression(NewExpression newExpression, ReadOnlyCollection<Expression> expressions)\r
-            : base(ExpressionType.ListInit, newExpression.Type)\r
-        {\r
-            this.newExpression = newExpression;\r
-            this.expressions = expressions;\r
-        }\r
-        #endregion\r
-\r
-        #region Fields\r
-        private ReadOnlyCollection<Expression> expressions;\r
-        private NewExpression newExpression;\r
-        #endregion\r
-\r
-        #region Properties\r
-        public ReadOnlyCollection<Expression> Expressions\r
-        {\r
-            get { return expressions; }\r
-        }\r
-\r
-        public NewExpression NewExpression\r
-        {\r
-            get { return newExpression; }\r
-        }\r
-        #endregion\r
-\r
-        #region Internal Methods\r
-        internal override void BuildString(StringBuilder builder)\r
-        {\r
-            // we need to build the "new" expression before...\r
-            newExpression.BuildString(builder);\r
-\r
-            //... and the elements of the list ...\r
-            builder.Append("{");\r
-\r
-            int exprc = expressions.Count;\r
-            for (int i = 0; i < exprc; i++)\r
-            {\r
-                expressions[i].BuildString(builder);\r
-                if (i < expressions.Count - 1)\r
-                    builder.Append(", ");\r
-            }\r
-\r
-            builder.Append("}");\r
-        }\r
-        #endregion\r
-    }\r
-}
\ No newline at end of file
+//
+// ListInitExpression.cs
+//
+// Author:
+//   Jb Evain (jbevain@novell.com)
+//
+// (C) 2008 Novell, Inc. (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Text;
+
+namespace System.Linq.Expressions {
+
+       public sealed class ListInitExpression : Expression {
+
+               NewExpression new_expression;
+               ReadOnlyCollection<ElementInit> initializers;
+
+               public NewExpression NewExpression {
+                       get { return new_expression; }
+               }
+
+               public ReadOnlyCollection<ElementInit> Initializers {
+                       get { return initializers; }
+               }
+
+               internal ListInitExpression (NewExpression new_expression, ReadOnlyCollection<ElementInit> initializers)
+                       : base (ExpressionType.ListInit, new_expression.Type)
+               {
+                       this.new_expression = new_expression;
+                       this.initializers = initializers;
+               }
+
+               internal override void Emit (EmitContext ec)
+               {
+                       var local = ec.EmitStored (new_expression);
+                       ec.EmitCollection (initializers, local);
+                       ec.EmitLoad (local);
+               }
+       }
+}