Event trigger by name now won't trigger disabled events.
2 using System.Collections.Generic;
5 using System.Threading.Tasks;
6 using System.Runtime.Serialization;
7 using System.ComponentModel;
13 /// EAR object provides serialization support.
14 /// It assumes most derived class is decorated with AttributeObject.
17 [KnownType("DerivedTypes")]
18 public abstract class Object: IComparable, INotifyPropertyChanged
20 private bool iConstructed = false;
23 public List<Object> Objects = new List<Object>();
28 [AttributeObjectProperty
32 Description = "Given object name."
35 public string Name { get; set; } = "";
44 /// Needed as our constructor is not called following internalization.
46 public void Construct()
48 //Construct ourselves first
55 //Then construct our children
56 foreach (Object o in Objects)
65 protected virtual void DoConstruct()
67 //Make sure our name is not null
73 // Makes sure our objects are not null
76 Objects = new List<Object>();
86 State iCurrentState = State.Rest;
87 public State CurrentState { get { return iCurrentState; } set { OnStateLeave(); iCurrentState = value; OnStateEnter(); } }
92 protected virtual void OnStateLeave()
100 protected virtual void OnStateEnter()
106 /// Static object name.
108 public string AttributeName
110 //Get the name of this object attribute
111 get { return Utils.Reflection.GetAttribute<AttributeObject>(GetType()).Name; }
116 /// Static object description.
118 public string AttributeDescription
120 //Get the description of this object attribute
121 get { return Utils.Reflection.GetAttribute<AttributeObject>(GetType()).Description; }
126 /// Dynamic object description.
128 /// <returns></returns>
129 public virtual string Brief()
131 return AttributeName;
135 /// Needed to make sure our sorting makes sense
137 /// <param name="obj"></param>
138 /// <returns></returns>
139 public int CompareTo(object obj)
141 //Sort by object name
142 return Utils.Reflection.GetAttribute<AttributeObject>(GetType()).Name.CompareTo(obj.GetType());
146 /// Tells whether the current object configuration is valid.
148 /// <returns></returns>
149 public virtual bool IsValid()
155 /// So that data contract knows all our types.
157 /// <returns></returns>
158 private static IEnumerable<Type> DerivedTypes()
160 return SharpLib.Utils.Reflection.GetDerivedTypes<Object>();
166 public event PropertyChangedEventHandler PropertyChanged;
170 /// Invoke our event.
172 /// <param name="name"></param>
173 protected void OnPropertyChanged(string name)
175 PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));