forked from sagifogel/NCop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMethodMapper.cs
59 lines (49 loc) · 2.05 KB
/
MethodMapper.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using NCop.Core.Extensions;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace NCop.Core
{
public class MethodMapper : IMethodMapper
{
private readonly List<IMethodMap> mappedMethods = null;
public MethodMapper(ITypeMapCollection typeMap) {
Func<MethodInfo, bool> methodPredicate = methodInfo => !methodInfo.IsSpecialName;
var mapped = typeMap.Select(map => new {
ContractType = map.ServiceType,
ImplementationType = map.ConcreteType,
ContractMethods = map.ServiceType.GetPublicMethods().Where(methodPredicate),
MethodsImpl = map.ConcreteType.GetPublicMethods().ToSet(methodPredicate),
});
var mappedMethodsEnumerable = mapped.SelectMany(map => {
var methods = map.ContractMethods;
return methods.Select(method => {
var match = method.SelectFirst(map.MethodsImpl,
(c, impl) => c.IsMatchedTo(impl),
(c, impl) => new {
MethodImpl = impl,
ContractMethod = c
});
return new MethodMap(map.ContractType,
map.ImplementationType,
match.ContractMethod,
match.MethodImpl);
});
});
mappedMethods = mappedMethodsEnumerable.ToListOf<IMethodMap>();
}
public IEnumerator<IMethodMap> GetEnumerator() {
return mappedMethods.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() {
return GetEnumerator();
}
public int Count {
get {
return mappedMethods.Count;
}
}
}
}