1 /* ****************************************************************************
3 * Copyright (c) Microsoft Corporation.
5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
6 * copy of the license can be found in the License.html file at the root of this distribution. If
7 * you cannot locate the Apache License, Version 2.0, please send an email to
8 * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
9 * by the terms of the Apache License, Version 2.0.
11 * You must not remove this notice, or any other, from this software.
14 * ***************************************************************************/
17 using System.Linq.Expressions;
19 using Microsoft.Scripting.Ast;
24 using System.Reflection;
25 using Microsoft.Scripting.Utils;
27 namespace Microsoft.Scripting.Runtime {
28 using AstUtils = Microsoft.Scripting.Ast.Utils;
31 /// Wraps all arguments passed to a dynamic site with more arguments than can be accepted by a Func/Action delegate.
32 /// The binder generating a rule for such a site should unwrap the arguments first and then perform a binding to them.
34 public sealed class ArgumentArray {
35 private readonly object[] _arguments;
37 // the index of the first item _arguments that represents an argument:
38 private readonly int _first;
40 // the number of items in _arguments that represent the arguments:
41 private readonly int _count;
43 internal ArgumentArray(object[] arguments, int first, int count) {
44 _arguments = arguments;
50 get { return _count; }
53 public object GetArgument(int index) {
54 ContractUtils.RequiresArrayIndex(_arguments, index, "index");
55 return _arguments[_first + index];
58 public DynamicMetaObject GetMetaObject(Expression parameter, int index) {
59 return DynamicMetaObject.Create(
63 AstUtils.Convert(parameter, typeof(ArgumentArray)),
64 AstUtils.Constant(index)
70 public static object GetArg(ArgumentArray array, int index) {
71 return array._arguments[array._first + index];
74 private static readonly MethodInfo _GetArgMethod = new Func<ArgumentArray, int, object>(GetArg).GetMethodInfo();