PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

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

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