/* **************************************************************************** * * Copyright (c) Microsoft Corporation. * * This source code is subject to terms and conditions of the Microsoft Public License. A * copy of the license can be found in the License.html file at the root of this distribution. If * you cannot locate the Microsoft Public License, please send an email to * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound * by the terms of the Microsoft Public License. * * You must not remove this notice, or any other, from this software. * * * ***************************************************************************/ using System; using Microsoft; using System.Collections.Generic; using System.Collections.ObjectModel; #if CODEPLEX_40 using System.Dynamic.Utils; using System.Linq.Expressions; #else using Microsoft.Scripting.Utils; using Microsoft.Linq.Expressions; #endif #if SILVERLIGHT using System.Core; #endif //SILVERLIGHT #if CODEPLEX_40 namespace System.Dynamic { #else namespace Microsoft.Scripting { #endif /// /// Describes arguments in the dynamic binding process. /// /// /// ArgumentCount - all inclusive number of arguments. /// ArgumentNames - names for those arguments that are named. /// /// Argument names match to the argument values in left to right order /// and last name corresponds to the last argument. /// /// Example: /// Foo(arg1, arg2, arg3, name1 = arg4, name2 = arg5, name3 = arg6) /// /// will correspond to: /// ArgumentCount: 6 /// ArgumentNames: {"name1", "name2", "name3"} /// public sealed class CallInfo { private readonly int _argCount; private readonly ReadOnlyCollection _argNames; /// /// Creates a new PositionalArgumentInfo. /// /// The number of arguments. /// The argument names. /// The new CallInfo public CallInfo(int argCount, params string[] argNames) : this(argCount, (IEnumerable)argNames) { } /// /// Creates a new CallInfo that represents arguments in the dynamic binding process. /// /// The number of arguments. /// The argument names. /// The new CallInfo public CallInfo(int argCount, IEnumerable argNames) { ContractUtils.RequiresNotNull(argNames, "argNames"); var argNameCol = argNames.ToReadOnly(); ContractUtils.Requires(argCount >= argNameCol.Count, "argCount", Strings.ArgCntMustBeGreaterThanNameCnt); ContractUtils.RequiresNotNullItems(argNameCol, "argNames"); _argCount = argCount; _argNames = argNameCol; } /// /// The number of arguments. /// public int ArgumentCount { get { return _argCount; } } /// /// The argument names. /// public ReadOnlyCollection ArgumentNames { get { return _argNames; } } /// /// Serves as a hash function for the current CallInfo. /// /// A hash code for the current CallInfo. public override int GetHashCode() { return _argCount ^ _argNames.ListHashCode(); } /// /// Determines whether the specified CallInfo instance is considered equal to the current. /// /// The instance of CallInfo to compare with the current instance. /// true if the specified instance is equal to the current one otherwise, false. public override bool Equals(object obj) { var other = obj as CallInfo; return _argCount == other._argCount && _argNames.ListEquals(other._argNames); } } }