SharpLibEar/Action.cs
author StephaneLenclud
Tue, 26 Jul 2016 15:05:57 +0200
changeset 220 e5910d7b6a81
parent 212 1a0791daa243
child 223 f6272f65d8fc
permissions -rw-r--r--
Adding support for enumerated action property edition.
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@220
    23
        public virtual string Brief()
StephaneLenclud@220
    24
        {
StephaneLenclud@220
    25
            return Name;
StephaneLenclud@220
    26
        }
StephaneLenclud@220
    27
StephaneLenclud@210
    28
        public int CompareTo(object obj)
StephaneLenclud@210
    29
        {
StephaneLenclud@210
    30
            //Sort by action name
StephaneLenclud@210
    31
            return Utils.Reflection.GetAttribute<AttributeAction>(GetType()).Name.CompareTo(obj.GetType());            
StephaneLenclud@210
    32
        }
Stephane@212
    33
Stephane@212
    34
        private static IEnumerable<Type> DerivedTypes()
Stephane@212
    35
        {
Stephane@212
    36
            return SharpLib.Utils.Reflection.GetDerivedTypes<Action>();
Stephane@212
    37
        }
Stephane@212
    38
StephaneLenclud@210
    39
    }
StephaneLenclud@210
    40
StephaneLenclud@210
    41
StephaneLenclud@210
    42
}