PageRenderTime 17ms CodeModel.GetById 9ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/IronPython_Main/Runtime/Microsoft.Dynamic/Generation/MethodSignatureInfo.cs

#
C# | 68 lines | 40 code | 10 blank | 18 comment | 11 complexity | 7ece7409d191dd294066176767dad4f9 MD5 | raw file
 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
16using System.Reflection;
17using Microsoft.Contracts; 
18
19namespace Microsoft.Scripting.Generation {
20    /// <summary>
21    /// Helper class to remove methods w/ identical signatures.  Used for GetDefaultMembers
22    /// which returns members from all types in the hierarchy.
23    /// </summary>
24    public class MethodSignatureInfo {
25        private readonly ParameterInfo[] _pis;
26        private readonly bool _isStatic;
27        private readonly int _genericArity;
28
29        public MethodSignatureInfo(MethodInfo info) 
30            : this(info.IsStatic, info.GetParameters(), info.IsGenericMethodDefinition ? info.GetGenericArguments().Length : 0){
31        }
32
33        public MethodSignatureInfo(bool isStatic, ParameterInfo[] pis, int genericArity) {
34            _isStatic = isStatic;
35            _pis = pis;
36            _genericArity = genericArity;
37        }
38
39        [Confined]
40        public override bool Equals(object obj) {
41            MethodSignatureInfo args = obj as MethodSignatureInfo;
42            if (args == null) return false;
43
44            if (args._isStatic != _isStatic || args._pis.Length != _pis.Length || args._genericArity != _genericArity) {
45                return false;
46            }
47
48            for (int i = 0; i < _pis.Length; i++) {
49                ParameterInfo self = _pis[i];
50                ParameterInfo other = args._pis[i];
51
52                if (self.ParameterType != other.ParameterType)
53                    return false;
54            }
55
56            return true;
57        }
58
59        [Confined]
60        public override int GetHashCode() {
61            int hash = 6551 ^ (_isStatic ? 79234 : 3123) ^ _genericArity;
62            foreach (ParameterInfo pi in _pis) {
63                hash ^= pi.ParameterType.GetHashCode();
64            }
65            return hash;
66        }
67    }
68}