예제 #1
0
        protected override ILConstruct EmitCreateNewArrayExpression(TContext context, Type elementType, int length)
        {
            var array =
                ILConstruct.Variable(
                    elementType.MakeArrayType(),
                    "array"
                    );

            return
                (ILConstruct.Composite(
                     ILConstruct.Sequence(
                         array.ContextType,
                         new[]
            {
                array,
                ILConstruct.Instruction(
                    "NewArray",
                    array.ContextType,
                    false,
                    il =>
                {
                    il.EmitNewarr(elementType, length);
                    array.StoreValue(il);
                }
                    )
            }
                         ),
                     array
                     ));
        }
        protected override ILConstruct EmitCreateNewArrayExpression(TContext context, Type elementType, int length, IEnumerable <ILConstruct> initialElements)
        {
            var array =
                ILConstruct.Variable(
                    elementType.MakeArrayType(),
                    "array"
                    );

            return
                (ILConstruct.Composite(
                     ILConstruct.Sequence(
                         array.ContextType,
                         new[]
            {
                array,
                ILConstruct.Instruction(
                    "CreateArray",
                    array.ContextType,
                    false,
                    il =>
                {
                    il.EmitNewarr(elementType, length);
                    array.StoreValue(il);
                    var index = 0;
                    foreach (var initialElement in initialElements)
                    {
                        array.LoadValue(il, false);
                        this.MakeInt32Literal(context, index).LoadValue(il, false);
                        initialElement.LoadValue(il, false);
                        il.EmitStelem(elementType);
                        index++;
                    }
                }
                    )
            }
                         ),
                     array
                     ));
        }