Mercurial > pub > bltoolkit
comparison HowTo/Mapping/MapValueAttribute1.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 NUnit.Framework; | |
4 | |
5 using BLToolkit.Mapping; | |
6 | |
7 namespace HowTo.Mapping | |
8 { | |
9 [TestFixture] | |
10 public class MapValue1 | |
11 { | |
12 public class SourceObject | |
13 { | |
14 public string Value = "Y"; | |
15 } | |
16 | |
17 public class TestObject1 | |
18 { | |
19 // The attribute is applied to a field/property. | |
20 // | |
21 [/*[a]*/MapValue(true, "Y")/*[/a]*/] | |
22 [/*[a]*/MapValue(false, "N")/*[/a]*/] | |
23 public bool Value; | |
24 } | |
25 | |
26 [Test] | |
27 public void Test1() | |
28 { | |
29 SourceObject so = new SourceObject(); | |
30 TestObject1 to = Map.ObjectToObject<TestObject1>(so); | |
31 | |
32 Assert.AreEqual(true, to.Value); | |
33 } | |
34 | |
35 // The attribute is applied to a class. | |
36 // | |
37 [/*[a]*/MapValue(true, "Y")/*[/a]*/] | |
38 [/*[a]*/MapValue(false, "N")/*[/a]*/] | |
39 public class TestObject2 | |
40 { | |
41 public bool Value; | |
42 } | |
43 | |
44 [Test] | |
45 public void Test2() | |
46 { | |
47 SourceObject so = new SourceObject(); | |
48 TestObject2 to = Map.ObjectToObject<TestObject2>(so); | |
49 | |
50 Assert.AreEqual(true, to.Value); | |
51 } | |
52 | |
53 // The attribute is applied to a base class and affects all child classes. | |
54 // | |
55 [/*[a]*/MapValue(typeof(bool), true, "Y")/*[/a]*/] | |
56 [/*[a]*/MapValue(typeof(bool), false, "N")/*[/a]*/] | |
57 public class ObjectBase | |
58 { | |
59 } | |
60 | |
61 public class TestObject3 : /*[a]*/ObjectBase/*[/a]*/ | |
62 { | |
63 public bool Value; | |
64 } | |
65 | |
66 [Test] | |
67 public void Test3() | |
68 { | |
69 SourceObject so = new SourceObject(); | |
70 TestObject3 to = Map.ObjectToObject<TestObject3>(so); | |
71 | |
72 Assert.AreEqual(true, to.Value); | |
73 } | |
74 } | |
75 } |