System.Drawing: added email to icon and test file headers
[mono.git] / mcs / class / dlr / Runtime / Microsoft.Scripting.Core / Actions / CallInfo.cs
1 /* ****************************************************************************
2  *
3  * Copyright (c) Microsoft Corporation. 
4  *
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.
10  *
11  * You must not remove this notice, or any other, from this software.
12  *
13  *
14  * ***************************************************************************/
15
16 #if CLR2
17 using Microsoft.Scripting.Ast;
18 #else
19 using System.Linq.Expressions;
20 #endif
21 #if SILVERLIGHT
22 using System.Core;
23 #endif
24
25 using System.Collections.Generic;
26 using System.Collections.ObjectModel;
27 using System.Dynamic.Utils;
28
29 namespace System.Dynamic {
30
31     /// <summary>
32     /// Describes arguments in the dynamic binding process.
33     /// </summary>
34     /// <remarks>
35     /// ArgumentCount - all inclusive number of arguments.
36     /// ArgumentNames - names for those arguments that are named.
37     ///
38     /// Argument names match to the argument values in left to right order 
39     /// and last name corresponds to the last argument.
40     /// 
41     /// Example:
42     ///   Foo(arg1, arg2, arg3, name1 = arg4, name2 = arg5, name3 = arg6)
43     ///
44     ///   will correspond to:
45     ///    ArgumentCount: 6
46     ///    ArgumentNames: {"name1", "name2", "name3"}
47     /// </remarks>
48     public sealed class CallInfo {
49         private readonly int _argCount;
50         private readonly ReadOnlyCollection<string> _argNames;
51
52         /// <summary>
53         /// Creates a new PositionalArgumentInfo.
54         /// </summary>
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) {
60         }
61
62         /// <summary>
63         /// Creates a new CallInfo that represents arguments in the dynamic binding process.
64         /// </summary>
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");
70
71             var argNameCol = argNames.ToReadOnly();
72
73             if (argCount < argNameCol.Count) throw Error.ArgCntMustBeGreaterThanNameCnt();
74             ContractUtils.RequiresNotNullItems(argNameCol, "argNames");
75
76             _argCount = argCount;
77             _argNames = argNameCol;
78         }
79
80         /// <summary>
81         /// The number of arguments.
82         /// </summary>
83         public int ArgumentCount {
84             get { return _argCount; }
85         }
86
87         /// <summary>
88         /// The argument names.
89         /// </summary>
90         public ReadOnlyCollection<string> ArgumentNames {
91             get { return _argNames; }
92         }
93
94         /// <summary>
95         /// Serves as a hash function for the current CallInfo.
96         /// </summary>
97         /// <returns>A hash code for the current CallInfo.</returns>
98         public override int GetHashCode() {
99             return _argCount ^ _argNames.ListHashCode();
100         }
101
102         /// <summary>
103         /// Determines whether the specified CallInfo instance is considered equal to the current.
104         /// </summary>
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);
110         }
111     }
112 }