SharpLibEar/Action.cs
author Stephane Lenclud
Sun, 24 Jul 2016 13:30:08 +0200
changeset 212 1a0791daa243
parent 211 96f8b4dc4300
child 220 e5910d7b6a81
permissions -rw-r--r--
Actions persistence working.
StephaneLenclud@210
     1
//
StephaneLenclud@210
     2
StephaneLenclud@210
     3
StephaneLenclud@210
     4
using System;
Stephane@212
     5
using System.Collections.Generic;
StephaneLenclud@210
     6
using System.Runtime.Serialization;
StephaneLenclud@210
     7
using System.Threading;
StephaneLenclud@210
     8
StephaneLenclud@210
     9
namespace SharpLib.Ear
StephaneLenclud@210
    10
{
StephaneLenclud@210
    11
    [DataContract]
Stephane@212
    12
    [KnownType("DerivedTypes")]
StephaneLenclud@210
    13
    public abstract class Action: IComparable
StephaneLenclud@210
    14
    {
StephaneLenclud@210
    15
        public abstract void Execute();
StephaneLenclud@210
    16
StephaneLenclud@211
    17
        public string Name {
StephaneLenclud@211
    18
            //Get the name of this object action attribute
StephaneLenclud@211
    19
            get { return Utils.Reflection.GetAttribute<AttributeAction>(GetType()).Name; }
StephaneLenclud@211
    20
            private set { }
StephaneLenclud@211
    21
        }
StephaneLenclud@211
    22
StephaneLenclud@210
    23
        public int CompareTo(object obj)
StephaneLenclud@210
    24
        {
StephaneLenclud@210
    25
            //Sort by action name
StephaneLenclud@210
    26
            return Utils.Reflection.GetAttribute<AttributeAction>(GetType()).Name.CompareTo(obj.GetType());            
StephaneLenclud@210
    27
        }
Stephane@212
    28
Stephane@212
    29
        private static IEnumerable<Type> DerivedTypes()
Stephane@212
    30
        {
Stephane@212
    31
            return SharpLib.Utils.Reflection.GetDerivedTypes<Action>();
Stephane@212
    32
        }
Stephane@212
    33
StephaneLenclud@210
    34
    }
StephaneLenclud@210
    35
StephaneLenclud@210
    36
StephaneLenclud@210
    37
}