forked from octokit/octokit.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParameterCountMismatchException.cs
31 lines (26 loc) · 1.34 KB
/
ParameterCountMismatchException.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Octokit.Tests.Conventions
{
public class ParameterCountMismatchException : Exception
{
public ParameterCountMismatchException(MethodInfo method, IEnumerable<ParameterInfo> expected, IEnumerable<ParameterInfo> actual)
: base(CreateMessage(method, expected, actual))
{ }
public ParameterCountMismatchException(MethodInfo method, IEnumerable<ParameterInfo> expected, IEnumerable<ParameterInfo> actual, Exception innerException)
: base(CreateMessage(method, expected, actual), innerException)
{ }
static string CreateMethodSignature(IEnumerable<ParameterInfo> parameters)
{
return string.Join(",", parameters.Select(p => string.Format("{0} {1}", p.ParameterType.Name, p.Name)));
}
static string CreateMessage(MethodInfo method, IEnumerable<ParameterInfo> expected, IEnumerable<ParameterInfo> actual)
{
var expectedMethodSignature = CreateMethodSignature(expected);
var actualMethodSignature = CreateMethodSignature(actual);
return string.Format("Method signature for {0}.{1} must be \"({2})\" but is \"({3})\"", method.DeclaringType.Name, method.Name, expectedMethodSignature, actualMethodSignature);
}
}
}