forked from sagifogel/NCop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PropertyMapper.cs
55 lines (46 loc) · 1.57 KB
/
PropertyMapper.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
using NCop.Core.Extensions;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace NCop.Core
{
public class PropertyMapper : IPropertyMapper
{
private readonly List<IPropertyMap> mappedProperties = null;
public PropertyMapper(ITypeMapCollection mixinsMap) {
var mapped = mixinsMap.Select(mixin => new {
ServiceType = mixin.ServiceType,
ConcreteType = mixin.ConcreteType,
ContractProperties = mixin.ServiceType.GetProperties(),
PropertiesImpl = mixin.ConcreteType.GetProperties().ToSet()
});
var mappedPropertiesEnumerable = mapped.SelectMany(map => {
var properties = map.ContractProperties;
return properties.Select(property => {
var match = property.SelectFirst(map.PropertiesImpl,
(c, impl) => c.IsMatchedTo(impl),
(c, impl) => new {
ServiceProperty = c,
ConcreteProperty = impl
});
return new PropertyMap(map.ServiceType,
map.ConcreteType,
match.ServiceProperty,
match.ConcreteProperty);
});
});
mappedProperties = mappedPropertiesEnumerable.ToListOf<IPropertyMap>();
}
public IEnumerator<IPropertyMap> GetEnumerator() {
return mappedProperties.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() {
return GetEnumerator();
}
public int Count {
get {
return mappedProperties.Count;
}
}
}
}