Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate api/Objects/WarFoundryObject.cs @ 82:3ea0ab04352b
* Fix line terminators
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 27 Jun 2009 18:59:49 +0000 |
parents | 306558904c2a |
children | 571d8ddc7d9a |
rev | line source |
---|---|
15 | 1 // This file (WarFoundryObject.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard. |
2 // | |
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. | |
4 | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
5 using System; |
82 | 6 using IBBoard.WarFoundry.API.Factories; |
7 | |
8 namespace IBBoard.WarFoundry.API.Objects | |
9 { | |
10 /// <summary> | |
11 /// Summary description for WarFoundryObject. | |
12 /// </summary> | |
13 public abstract class WarFoundryObject : IWarFoundryObject | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
14 { |
82 | 15 protected string id; |
16 protected string name; | |
0 | 17 public event StringValChangedDelegate NameChanged; |
18 | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
19 protected WarFoundryObject() |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
20 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
21 } |
0 | 22 |
23 protected WarFoundryObject(string objName) : this() | |
24 { | |
25 Name = objName; | |
26 } | |
27 | |
28 protected WarFoundryObject(string objId, string objName) : this(objName) | |
29 { | |
30 ID = objId; | |
82 | 31 } |
32 | |
33 public virtual string ID | |
34 { | |
0 | 35 get |
36 { | |
37 if (id == null) | |
38 { | |
39 id = GenerateID(); | |
40 } | |
41 | |
42 return id; | |
43 } | |
82 | 44 |
45 set { id = (value == null ? GenerateID() : value.Trim()); } | |
46 } | |
47 | |
48 public virtual string Name | |
49 { | |
50 get | |
51 { | |
52 if (HasDefaultName()) | |
53 { | |
54 return DefaultName(); | |
55 } | |
56 else | |
57 { | |
58 return name; | |
59 } | |
60 } | |
61 set | |
62 { | |
63 string oldValue = name; | |
64 name = value; | |
65 | |
66 if (name!=oldValue) | |
67 { | |
68 OnNameChanged(oldValue, name); | |
69 } | |
70 } | |
71 } | |
72 | |
73 protected bool HasDefaultName() | |
74 { | |
75 return (name == null || name == ""); | |
76 } | |
77 | |
78 protected void OnNameChanged(string oldValue, string newValue) | |
79 { | |
80 if (NameChanged!=null) | |
81 { | |
82 NameChanged(this, oldValue, newValue); | |
83 } | |
84 } | |
85 | |
86 protected virtual string DefaultName() | |
87 { | |
88 return "-"; | |
89 } | |
90 | |
91 protected string GenerateID() | |
92 { | |
93 return "ID" + UnixTimestamp.GetTimestamp(DateTime.Now) + "." + DateTime.Now.Millisecond; | |
94 } | |
95 } | |
96 } |