SharpLibEar/Action.cs
author Stephane Lenclud
Sun, 31 Jul 2016 12:03:52 +0200
changeset 230 8c5cf2228e9a
parent 228 6a84d8282226
child 231 4c706feaf706
permissions -rw-r--r--
Published v0.10.2.0.
     1 //
     2 
     3 
     4 using System;
     5 using System.Collections.Generic;
     6 using System.Runtime.Serialization;
     7 using System.Threading;
     8 
     9 namespace SharpLib.Ear
    10 {
    11     [DataContract]
    12     [KnownType("DerivedTypes")]
    13     public abstract class Action: IComparable
    14     {
    15         protected abstract void DoExecute();
    16 
    17         public void Execute()
    18         {
    19             Console.WriteLine("Action executing: " + Brief());
    20             DoExecute();
    21         }
    22 
    23         public string Name {
    24             //Get the name of this object action attribute
    25             get { return Utils.Reflection.GetAttribute<AttributeAction>(GetType()).Name; }
    26             private set { }
    27         }
    28 
    29         public virtual string Brief()
    30         {
    31             return Name;
    32         }
    33 
    34         public int CompareTo(object obj)
    35         {
    36             //Sort by action name
    37             return Utils.Reflection.GetAttribute<AttributeAction>(GetType()).Name.CompareTo(obj.GetType());            
    38         }
    39 
    40         private static IEnumerable<Type> DerivedTypes()
    41         {
    42             return SharpLib.Utils.Reflection.GetDerivedTypes<Action>();
    43         }
    44 
    45     }
    46 
    47 
    48 }