PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/src/NUnit/mocks/MethodSignature.cs

#
C# | 56 lines | 39 code | 9 blank | 8 comment | 9 complexity | f10294eda26ce4775638e73dd05ff8e5 MD5 | raw file
 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
 7using System;
 8
 9namespace NUnit.Mocks
10{
11	/// <summary>
12	/// Summary description for MockSignature.
13	/// </summary>
14	public class MethodSignature
15	{
16		public readonly string typeName;
17		public readonly string methodName;
18		public readonly Type[] argTypes;
19
20		public MethodSignature( string typeName, string methodName, Type[] argTypes )
21		{
22			this.typeName = typeName;
23			this.methodName = methodName;
24			this.argTypes = argTypes; 
25		}
26
27		public bool IsCompatibleWith( object[] args )
28		{
29			if ( args.Length != argTypes.Length )
30				return false;
31
32			for( int i = 0; i < args.Length; i++ )
33				if ( !argTypes[i].IsAssignableFrom( args[i].GetType() ) )
34					return false;
35
36			return true;
37		}
38
39		public static Type[] GetArgTypes( object[] args )
40		{
41			if ( args == null )
42				return new Type[0];
43
44			Type[] argTypes = new Type[args.Length];
45			for (int i = 0; i < argTypes.Length; ++i)
46			{
47				if (args[i] == null)
48					argTypes[i] = typeof(object);
49				else
50					argTypes[i] = args[i].GetType();
51			}
52
53			return argTypes;
54		}
55	}
56}