Last change
on this file since 1247 was
1247,
checked in by epitzer, 15 years ago
|
Created AutoStorable attribute and static reflection helper to determine serializible components. (#506)
|
File size:
951 bytes
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Text;
|
---|
4 |
|
---|
5 | namespace 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.