source: branches/New Persistence Exploration/Persistence/Persistence/AutoStorableAttributeTests.cs @ 1247

Last change on this file since 1247 was 1247, checked in by epitzer, 11 years ago

Created AutoStorable attribute and static reflection helper to determine serializible components. (#506)

File size: 951 bytes
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Persistence {
6
7  class TestClass {
8
9    [AutoStorable(Name="TestProperty", DefaultValue=12)]
10    public object o;
11
12    [AutoStorable]
13    public int x = 2;
14
15    public int y;
16
17  }
18
19  class AttributeTest {
20
21    static void Main() {
22      TestClass t = new TestClass();
23      Dictionary<string, DataMemberAccessor> accessors = AutoStorableAttribute.GetAutostorableAccessors(t);
24      foreach ( KeyValuePair<string, DataMemberAccessor> pair in accessors ) {
25        Console.WriteLine(pair.Key + ": " + pair.Value.ToString());
26      }
27      t.o = new Object();
28      t.x = 12;
29      t.y = 312890;
30      accessors["o"].Set(null);
31      accessors["x"].Set(123);
32      try {
33        accessors["y"].Set(0);
34        throw new InvalidOperationException();
35      } catch ( KeyNotFoundException ) { }
36      Console.ReadLine();
37    }
38
39  }
40
41}
Note: See TracBrowser for help on using the repository browser.