SharpLibEar/Action.cs
author StephaneLenclud
Fri, 12 Aug 2016 20:25:05 +0200
changeset 231 4c706feaf706
parent 229 7c631055b94b
child 238 c92587ddabcd
permissions -rw-r--r--
Events can now be instantiated.
Action editor is now a generic object editor.
     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         /// <summary>
    18         /// Allows testing from generic edit dialog.
    19         /// </summary>
    20         public void Test()
    21         {
    22             Console.WriteLine("Action test");
    23             Execute();
    24         }
    25 
    26         public void Execute()
    27         {
    28             Console.WriteLine("Action executing: " + Brief());
    29             DoExecute();
    30         }
    31 
    32         public string Name {
    33             //Get the name of this object action attribute
    34             get { return Utils.Reflection.GetAttribute<AttributeObject>(GetType()).Name; }
    35             private set { }
    36         }
    37 
    38         public virtual string Brief()
    39         {
    40             return Name;
    41         }
    42 
    43         public int CompareTo(object obj)
    44         {
    45             //Sort by action name
    46             return Utils.Reflection.GetAttribute<AttributeObject>(GetType()).Name.CompareTo(obj.GetType());            
    47         }
    48 
    49         private static IEnumerable<Type> DerivedTypes()
    50         {
    51             return SharpLib.Utils.Reflection.GetDerivedTypes<Action>();
    52         }
    53 
    54     }
    55 
    56 
    57 }