1 /* ****************************************************************************
3 * Copyright (c) Microsoft Corporation.
5 * This source code is subject to terms and conditions of the Microsoft Public License. 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 Microsoft Public License, 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 Microsoft Public License.
11 * You must not remove this notice, or any other, from this software.
14 * ***************************************************************************/
15 using System; using Microsoft;
18 using System.Collections.Generic;
19 using System.Collections.ObjectModel;
21 using System.Dynamic.Utils;
22 using System.Linq.Expressions;
24 using Microsoft.Scripting.Utils;
25 using Microsoft.Linq.Expressions;
29 namespace System.Dynamic {
31 namespace Microsoft.Scripting {
35 /// Describes arguments in the dynamic binding process.
38 /// ArgumentCount - all inclusive number of arguments.
39 /// ArgumentNames - names for those arguments that are named.
41 /// Argument names match to the argument values in left to right order
42 /// and last name corresponds to the last argument.
45 /// Foo(arg1, arg2, arg3, name1 = arg4, name2 = arg5, name3 = arg6)
47 /// will correspond to:
49 /// ArgumentNames: {"name1", "name2", "name3"}
51 public sealed class CallInfo {
52 private readonly int _argCount;
53 private readonly ReadOnlyCollection<string> _argNames;
56 /// Creates a new PositionalArgumentInfo.
58 /// <param name="argCount">The number of arguments.</param>
59 /// <param name="argNames">The argument names.</param>
60 /// <returns>The new CallInfo</returns>
61 public CallInfo(int argCount, params string[] argNames)
62 : this(argCount, (IEnumerable<string>)argNames) {
66 /// Creates a new CallInfo that represents arguments in the dynamic binding process.
68 /// <param name="argCount">The number of arguments.</param>
69 /// <param name="argNames">The argument names.</param>
70 /// <returns>The new CallInfo</returns>
71 public CallInfo(int argCount, IEnumerable<string> argNames) {
72 ContractUtils.RequiresNotNull(argNames, "argNames");
74 var argNameCol = argNames.ToReadOnly();
76 ContractUtils.Requires(argCount >= argNameCol.Count, "argCount", Strings.ArgCntMustBeGreaterThanNameCnt);
77 ContractUtils.RequiresNotNullItems(argNameCol, "argNames");
80 _argNames = argNameCol;
84 /// The number of arguments.
86 public int ArgumentCount {
87 get { return _argCount; }
91 /// The argument names.
93 public ReadOnlyCollection<string> ArgumentNames {
94 get { return _argNames; }
98 /// Serves as a hash function for the current CallInfo.
100 /// <returns>A hash code for the current CallInfo.</returns>
101 public override int GetHashCode() {
102 return _argCount ^ _argNames.ListHashCode();
106 /// Determines whether the specified CallInfo instance is considered equal to the current.
108 /// <param name="obj">The instance of CallInfo to compare with the current instance.</param>
109 /// <returns>true if the specified instance is equal to the current one otherwise, false.</returns>
110 public override bool Equals(object obj) {
111 var other = obj as CallInfo;
112 return _argCount == other._argCount && _argNames.ListEquals(other._argNames);