annotate Source/Mapping/MemberMapperAttribute.cs @ 9:1e85f66cf767 default tip

update bltoolkit
author nickolay
date Thu, 05 Apr 2018 20:53:26 +0300
parents f990fcb411a9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
1 using System;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
2
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
3 namespace BLToolkit.Mapping
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
4 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
5 [AttributeUsage(
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
6 AttributeTargets.Class | AttributeTargets.Interface |
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
7 AttributeTargets.Property | AttributeTargets.Field,
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
8 AllowMultiple=true)]
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
9 public class MemberMapperAttribute : MapImplicitAttribute
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
10 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
11 public MemberMapperAttribute(Type memberMapperType)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
12 : this(null, memberMapperType)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
13 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
14 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
15
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
16 public MemberMapperAttribute(Type memberType, Type memberMapperType)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
17 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
18 if (memberMapperType == null) throw new ArgumentNullException("memberMapperType");
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
19
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
20 _memberType = memberType;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
21 _memberMapperType = memberMapperType;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
22 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
23
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
24 private readonly Type _memberType;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
25 public Type MemberType
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
26 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
27 get { return _memberType; }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
28 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
29
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
30 private readonly Type _memberMapperType;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
31 public Type MemberMapperType
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
32 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
33 get { return _memberMapperType; }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
34 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
35
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
36 public virtual MemberMapper MemberMapper
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
37 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
38 get
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
39 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
40 var mm = Activator.CreateInstance(_memberMapperType) as MemberMapper;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
41
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
42 if (mm == null)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
43 throw new ArgumentException(
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
44 string.Format("Type '{0}' is not MemberMapper.", _memberMapperType));
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
45
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
46 mm.IsExplicit = true;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
47
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
48 return mm;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
49 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
50 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
51 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
52 }