0
|
1 using System;
|
|
2
|
|
3 namespace IBBoard.WarFoundry.API.Objects
|
|
4 {
|
|
5 /// <summary>
|
|
6 /// Summary description for WarFoundryObject.
|
|
7 /// </summary>
|
|
8 public abstract class WarFoundryObject : IWarFoundryObject
|
|
9 {
|
|
10 protected string name, id;
|
|
11 public event StringValChangedDelegate NameChanged;
|
|
12
|
|
13 protected WarFoundryObject(){}
|
|
14
|
|
15 protected WarFoundryObject(string objName) : this()
|
|
16 {
|
|
17 Name = objName;
|
|
18 }
|
|
19
|
|
20 protected WarFoundryObject(string objId, string objName) : this(objName)
|
|
21 {
|
|
22 ID = objId;
|
|
23 }
|
|
24
|
|
25 public virtual string ID
|
|
26 {
|
|
27 get
|
|
28 {
|
|
29 if (id == null)
|
|
30 {
|
|
31 id = GenerateID();
|
|
32 }
|
|
33
|
|
34 return id;
|
|
35 }
|
|
36
|
|
37 set { id = (value == null ? GenerateID() : value.Trim()); }
|
|
38 }
|
|
39
|
|
40 public virtual string Name
|
|
41 {
|
|
42 get
|
|
43 {
|
|
44 if (HasDefaultName())
|
|
45 {
|
|
46 return DefaultName();
|
|
47 }
|
|
48 else
|
|
49 {
|
|
50 return name;
|
|
51 }
|
|
52 }
|
|
53 set
|
|
54 {
|
|
55 string oldValue = name;
|
|
56 name = value;
|
|
57
|
|
58 if (name!=oldValue)
|
|
59 {
|
|
60 OnNameChanged(oldValue, name);
|
|
61 }
|
|
62 }
|
|
63 }
|
|
64
|
|
65 protected bool HasDefaultName()
|
|
66 {
|
|
67 return (name == null || name == "");
|
|
68 }
|
|
69
|
|
70 protected void OnNameChanged(string oldValue, string newValue)
|
|
71 {
|
|
72 if (NameChanged!=null)
|
|
73 {
|
|
74 NameChanged(this, oldValue, newValue);
|
|
75 }
|
|
76 }
|
|
77
|
|
78 protected virtual string DefaultName()
|
|
79 {
|
|
80 return "-";
|
|
81 }
|
|
82
|
|
83 protected string GenerateID()
|
|
84 {
|
|
85 return "ID" + UnixTimestamp.GetTimestamp(DateTime.Now) + "." + DateTime.Now.Millisecond;
|
|
86 }
|
|
87 }
|
|
88 }
|