comparison Source/Mapping/Association.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2
3 using JNotNull = JetBrains.Annotations.NotNullAttribute;
4
5 namespace BLToolkit.Mapping
6 {
7 using Common;
8 using Reflection;
9
10 public class Association
11 {
12 public Association(
13 [JNotNull] MemberAccessor memberAccessor,
14 [JNotNull] string[] thisKey,
15 [JNotNull] string[] otherKey,
16 string storage,
17 bool canBeNull)
18 {
19 if (memberAccessor == null) throw new ArgumentNullException("memberAccessor");
20 if (thisKey == null) throw new ArgumentNullException("thisKey");
21 if (otherKey == null) throw new ArgumentNullException("otherKey");
22
23 if (thisKey.Length == 0)
24 throw new ArgumentOutOfRangeException(
25 "thisKey",
26 string.Format("Association '{0}.{1}' does not define keys.", memberAccessor.TypeAccessor.Type.Name, memberAccessor.Name));
27
28 if (thisKey.Length != otherKey.Length)
29 throw new ArgumentException(
30 string.Format(
31 "Association '{0}.{1}' has different number of keys for parent and child objects.",
32 memberAccessor.TypeAccessor.Type.Name, memberAccessor.Name));
33
34 MemberAccessor = memberAccessor;
35 ThisKey = thisKey;
36 OtherKey = otherKey;
37 Storage = storage;
38 CanBeNull = canBeNull;
39 }
40
41 public MemberAccessor MemberAccessor { get; set; }
42 public string[] ThisKey { get; set; }
43 public string[] OtherKey { get; set; }
44 public string Storage { get; set; }
45 public bool CanBeNull { get; set; }
46
47 public static string[] ParseKeys(string keys)
48 {
49 return keys == null ? Array<string>.Empty : keys.Replace(" ", "").Split(',');
50 }
51 }
52 }