SharpLibEar/Action.cs
author StephaneLenclud
Wed, 27 Jul 2016 15:05:58 +0200
changeset 223 f6272f65d8fc
parent 220 e5910d7b6a81
child 228 6a84d8282226
permissions -rw-r--r--
Adding action move and test buttons.
     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         public abstract void DoExecute();
    16 
    17         public void Execute()
    18         {
    19             Console.WriteLine("Executing action: " + 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 }