PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/mocks/MethodSignature.cs

#
C# | 56 lines | 39 code | 9 blank | 8 comment | 9 complexity | f10294eda26ce4775638e73dd05ff8e5 MD5 | raw file
Possible License(s): GPL-2.0
  1. // ****************************************************************
  2. // Copyright 2007, Charlie Poole
  3. // This is free software licensed under the NUnit license. You may
  4. // obtain a copy of the license at http://nunit.org
  5. // ****************************************************************
  6. using System;
  7. namespace NUnit.Mocks
  8. {
  9. /// <summary>
  10. /// Summary description for MockSignature.
  11. /// </summary>
  12. public class MethodSignature
  13. {
  14. public readonly string typeName;
  15. public readonly string methodName;
  16. public readonly Type[] argTypes;
  17. public MethodSignature( string typeName, string methodName, Type[] argTypes )
  18. {
  19. this.typeName = typeName;
  20. this.methodName = methodName;
  21. this.argTypes = argTypes;
  22. }
  23. public bool IsCompatibleWith( object[] args )
  24. {
  25. if ( args.Length != argTypes.Length )
  26. return false;
  27. for( int i = 0; i < args.Length; i++ )
  28. if ( !argTypes[i].IsAssignableFrom( args[i].GetType() ) )
  29. return false;
  30. return true;
  31. }
  32. public static Type[] GetArgTypes( object[] args )
  33. {
  34. if ( args == null )
  35. return new Type[0];
  36. Type[] argTypes = new Type[args.Length];
  37. for (int i = 0; i < argTypes.Length; ++i)
  38. {
  39. if (args[i] == null)
  40. argTypes[i] = typeof(object);
  41. else
  42. argTypes[i] = args[i].GetType();
  43. }
  44. return argTypes;
  45. }
  46. }
  47. }