Mercurial > pub > bltoolkit
comparison Source/Mapping/RelationAttribute.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 using System.Collections.Generic; | |
| 3 | |
| 4 namespace BLToolkit.Mapping | |
| 5 { | |
| 6 | |
| 7 [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true, AllowMultiple = false)] | |
| 8 public sealed class RelationAttribute : Attribute | |
| 9 { | |
| 10 #region Constructors | |
| 11 | |
| 12 public RelationAttribute() | |
| 13 { | |
| 14 } | |
| 15 | |
| 16 public RelationAttribute(Type destination) | |
| 17 { | |
| 18 _destination = destination; | |
| 19 } | |
| 20 | |
| 21 public RelationAttribute(string slaveIndex) | |
| 22 { | |
| 23 SlaveIndex1 = slaveIndex; | |
| 24 } | |
| 25 | |
| 26 public RelationAttribute(string slaveIndex, string masterIndex) | |
| 27 : this(slaveIndex) | |
| 28 { | |
| 29 MasterIndex1 = masterIndex; | |
| 30 } | |
| 31 | |
| 32 public RelationAttribute(Type destination, string slaveIndex) | |
| 33 : this(destination) | |
| 34 { | |
| 35 SlaveIndex1 = slaveIndex; | |
| 36 } | |
| 37 | |
| 38 public RelationAttribute(Type destination, string slaveIndex, string masterIndex) | |
| 39 : this(destination) | |
| 40 { | |
| 41 SlaveIndex1 = slaveIndex; | |
| 42 MasterIndex1 = masterIndex; | |
| 43 } | |
| 44 | |
| 45 #endregion | |
| 46 | |
| 47 private Type _destination; | |
| 48 public Type Destination { get { return _destination; } } | |
| 49 | |
| 50 private string _masterIndex1; | |
| 51 public string MasterIndex1 { get { return _masterIndex1; } set { _masterIndex1 = value; } } | |
| 52 | |
| 53 private string _masterIndex2; | |
| 54 public string MasterIndex2 { get { return _masterIndex2; } set { _masterIndex2 = value; } } | |
| 55 | |
| 56 private string _masterIndex3; | |
| 57 public string MasterIndex3 { get { return _masterIndex3; } set { _masterIndex3 = value; } } | |
| 58 | |
| 59 private string _slaveIndex1; | |
| 60 public string SlaveIndex1 { get { return _slaveIndex1; } set { _slaveIndex1 = value; } } | |
| 61 | |
| 62 private string _slaveIndex2; | |
| 63 public string SlaveIndex2 { get { return _slaveIndex2; } set { _slaveIndex2 = value; } } | |
| 64 | |
| 65 private string _slaveIndex3; | |
| 66 public string SlaveIndex3 { get { return _slaveIndex3; } set { _slaveIndex3 = value; } } | |
| 67 | |
| 68 public MapIndex MasterIndex | |
| 69 { | |
| 70 get | |
| 71 { | |
| 72 List<String> index = new List<string>(); | |
| 73 | |
| 74 AddIndex(index, MasterIndex1); | |
| 75 AddIndex(index, MasterIndex2); | |
| 76 AddIndex(index, MasterIndex3); | |
| 77 | |
| 78 if (index.Count == 0) | |
| 79 return null; | |
| 80 | |
| 81 return new MapIndex(index.ToArray()); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 public MapIndex SlaveIndex | |
| 86 { | |
| 87 get | |
| 88 { | |
| 89 List<String> index = new List<string>(); | |
| 90 | |
| 91 AddIndex(index, SlaveIndex1); | |
| 92 AddIndex(index, SlaveIndex2); | |
| 93 AddIndex(index, SlaveIndex3); | |
| 94 | |
| 95 if (index.Count == 0) | |
| 96 return null; | |
| 97 | |
| 98 return new MapIndex(index.ToArray()); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 private void AddIndex(List<string> index, string field) | |
| 103 { | |
| 104 if (!string.IsNullOrEmpty(field)) | |
| 105 index.Add(field); | |
| 106 } | |
| 107 } | |
| 108 } |
