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 * dlr@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 Microsoft.Scripting.Ast;
19 using System.Linq.Expressions;
25 using System.Collections.Generic;
26 using System.Collections.ObjectModel;
27 using System.Dynamic.Utils;
29 namespace System.Dynamic {
32 /// Describes arguments in the dynamic binding process.
35 /// ArgumentCount - all inclusive number of arguments.
36 /// ArgumentNames - names for those arguments that are named.
38 /// Argument names match to the argument values in left to right order
39 /// and last name corresponds to the last argument.
42 /// Foo(arg1, arg2, arg3, name1 = arg4, name2 = arg5, name3 = arg6)
44 /// will correspond to:
46 /// ArgumentNames: {"name1", "name2", "name3"}
48 public sealed class CallInfo {
49 private readonly int _argCount;
50 private readonly ReadOnlyCollection<string> _argNames;
53 /// Creates a new PositionalArgumentInfo.
55 /// <param name="argCount">The number of arguments.</param>
56 /// <param name="argNames">The argument names.</param>
57 /// <returns>The new CallInfo</returns>
58 public CallInfo(int argCount, params string[] argNames)
59 : this(argCount, (IEnumerable<string>)argNames) {
63 /// Creates a new CallInfo that represents arguments in the dynamic binding process.
65 /// <param name="argCount">The number of arguments.</param>
66 /// <param name="argNames">The argument names.</param>
67 /// <returns>The new CallInfo</returns>
68 public CallInfo(int argCount, IEnumerable<string> argNames) {
69 ContractUtils.RequiresNotNull(argNames, "argNames");
71 var argNameCol = argNames.ToReadOnly();
73 if (argCount < argNameCol.Count) throw Error.ArgCntMustBeGreaterThanNameCnt();
74 ContractUtils.RequiresNotNullItems(argNameCol, "argNames");
77 _argNames = argNameCol;
81 /// The number of arguments.
83 public int ArgumentCount {
84 get { return _argCount; }
88 /// The argument names.
90 public ReadOnlyCollection<string> ArgumentNames {
91 get { return _argNames; }
95 /// Serves as a hash function for the current CallInfo.
97 /// <returns>A hash code for the current CallInfo.</returns>
98 public override int GetHashCode() {
99 return _argCount ^ _argNames.ListHashCode();
103 /// Determines whether the specified CallInfo instance is considered equal to the current.
105 /// <param name="obj">The instance of CallInfo to compare with the current instance.</param>
106 /// <returns>true if the specified instance is equal to the current one otherwise, false.</returns>
107 public override bool Equals(object obj) {
108 var other = obj as CallInfo;
109 return _argCount == other._argCount && _argNames.ListEquals(other._argNames);