[3742] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
[1823] | 22 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[1614] | 23 |
|
---|
[2951] | 24 | namespace HeuristicLab.Persistence_33.Tests {
|
---|
[1614] | 25 |
|
---|
[4068] | 26 | [StorableClass]
|
---|
[1614] | 27 | class DemoClass {
|
---|
| 28 |
|
---|
| 29 | [Storable(Name = "TestProperty", DefaultValue = 12)]
|
---|
[3057] | 30 | public object o = null;
|
---|
[1614] | 31 |
|
---|
| 32 | [Storable]
|
---|
| 33 | public int x = 2;
|
---|
| 34 |
|
---|
[3057] | 35 | public int y = 0;
|
---|
[1614] | 36 | }
|
---|
| 37 |
|
---|
[3017] | 38 | [StorableClass]
|
---|
[1938] | 39 | class Base {
|
---|
| 40 | public string baseName;
|
---|
| 41 | [Storable]
|
---|
| 42 | public virtual string Name {
|
---|
| 43 | get { return "Base"; }
|
---|
| 44 | set { baseName = value; }
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[3017] | 48 | [StorableClass]
|
---|
[1938] | 49 | class Override : Base {
|
---|
| 50 | [Storable]
|
---|
| 51 | public override string Name {
|
---|
| 52 | get { return "Override"; }
|
---|
| 53 | set { base.Name = value; }
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 |
|
---|
[3017] | 57 | [StorableClass]
|
---|
[1938] | 58 | class Intermediate : Override {
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[3017] | 61 | [StorableClass]
|
---|
[1938] | 62 | class New : Intermediate {
|
---|
| 63 | public string newName;
|
---|
| 64 | [Storable]
|
---|
| 65 | public new string Name {
|
---|
| 66 | get { return "New"; }
|
---|
| 67 | set { newName = value; }
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[4068] | 71 | /* [TestClass]
|
---|
| 72 | public class AttributeTest {
|
---|
[1614] | 73 |
|
---|
[4068] | 74 | [TestMethod]
|
---|
| 75 | public void SimpleStorableAttributeTest() {
|
---|
| 76 | DemoClass t = new DemoClass();
|
---|
| 77 | IEnumerable<DataMemberAccessor> accessorList = StorableAttribute.GetStorableAccessors(t);
|
---|
| 78 | Dictionary<string, DataMemberAccessor> accessors = new Dictionary<string, DataMemberAccessor>();
|
---|
| 79 | foreach (var a in accessorList)
|
---|
| 80 | accessors.Add(a.Name, a);
|
---|
| 81 | Assert.IsTrue(accessors.ContainsKey("TestProperty"));
|
---|
| 82 | Assert.IsTrue(accessors.ContainsKey("x"));
|
---|
| 83 | Assert.IsFalse(accessors.ContainsKey("y"));
|
---|
| 84 | object o = new object();
|
---|
| 85 | t.o = o;
|
---|
| 86 | Assert.AreSame(accessors["TestProperty"].Get(), o);
|
---|
| 87 | t.x = 12;
|
---|
| 88 | Assert.AreEqual(accessors["x"].Get(), 12);
|
---|
| 89 | t.y = 312890;
|
---|
| 90 | accessors["TestProperty"].Set(null);
|
---|
| 91 | Assert.IsNull(t.o);
|
---|
| 92 | accessors["x"].Set(123);
|
---|
| 93 | Assert.AreEqual(t.x, 123);
|
---|
| 94 | }
|
---|
[1614] | 95 |
|
---|
[4068] | 96 | [TestMethod]
|
---|
| 97 | public void TestInheritance() {
|
---|
| 98 | New n = new New();
|
---|
| 99 | var accessors = StorableAttribute.GetStorableAccessors(n);
|
---|
| 100 | var accessDict = new Dictionary<string, DataMemberAccessor>();
|
---|
| 101 | foreach (var accessor in accessors) // assert uniqueness
|
---|
| 102 | accessDict.Add(accessor.Name, accessor);
|
---|
| 103 | Assert.IsTrue(accessDict.ContainsKey(typeof(New).FullName + ".Name"));
|
---|
| 104 | Assert.IsTrue(accessDict.ContainsKey(typeof(Override).FullName + ".Name"));
|
---|
| 105 | Assert.AreEqual("New", accessDict[typeof(New).FullName + ".Name"].Get());
|
---|
| 106 | Assert.AreEqual("Override", accessDict[typeof(Override).FullName + ".Name"].Get());
|
---|
| 107 | }
|
---|
[1938] | 108 |
|
---|
[4068] | 109 | }*/
|
---|
[1614] | 110 |
|
---|
| 111 | }
|
---|