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;
22 using System.Collections.Generic;
23 using System.Collections.ObjectModel;
24 using System.Dynamic.Utils;
26 namespace System.Dynamic {
29 /// Describes arguments in the dynamic binding process.
32 /// ArgumentCount - all inclusive number of arguments.
33 /// ArgumentNames - names for those arguments that are named.
35 /// Argument names match to the argument values in left to right order
36 /// and last name corresponds to the last argument.
39 /// Foo(arg1, arg2, arg3, name1 = arg4, name2 = arg5, name3 = arg6)
41 /// will correspond to:
43 /// ArgumentNames: {"name1", "name2", "name3"}
45 public sealed class CallInfo {
46 private readonly int _argCount;
47 private readonly ReadOnlyCollection<string> _argNames;
50 /// Creates a new PositionalArgumentInfo.
52 /// <param name="argCount">The number of arguments.</param>
53 /// <param name="argNames">The argument names.</param>
54 /// <returns>The new CallInfo</returns>
55 public CallInfo(int argCount, params string[] argNames)
56 : this(argCount, (IEnumerable<string>)argNames) {
60 /// Creates a new CallInfo that represents arguments in the dynamic binding process.
62 /// <param name="argCount">The number of arguments.</param>
63 /// <param name="argNames">The argument names.</param>
64 /// <returns>The new CallInfo</returns>
65 public CallInfo(int argCount, IEnumerable<string> argNames) {
66 ContractUtils.RequiresNotNull(argNames, "argNames");
68 var argNameCol = argNames.ToReadOnly();
70 if (argCount < argNameCol.Count) throw Error.ArgCntMustBeGreaterThanNameCnt();
71 ContractUtils.RequiresNotNullItems(argNameCol, "argNames");
74 _argNames = argNameCol;
78 /// The number of arguments.
80 public int ArgumentCount {
81 get { return _argCount; }
85 /// The argument names.
87 public ReadOnlyCollection<string> ArgumentNames {
88 get { return _argNames; }
92 /// Serves as a hash function for the current CallInfo.
94 /// <returns>A hash code for the current CallInfo.</returns>
95 public override int GetHashCode() {
96 return _argCount ^ _argNames.ListHashCode();
100 /// Determines whether the specified CallInfo instance is considered equal to the current.
102 /// <param name="obj">The instance of CallInfo to compare with the current instance.</param>
103 /// <returns>true if the specified instance is equal to the current one otherwise, false.</returns>
104 public override bool Equals(object obj) {
105 var other = obj as CallInfo;
106 return _argCount == other._argCount && _argNames.ListEquals(other._argNames);