SharpLibEar/Object.cs
author StephaneLenclud
Thu, 18 Aug 2016 14:35:50 +0200
changeset 238 c92587ddabcd
child 239 dd7770b97916
permissions -rw-r--r--
Support for launch action and WMC HID events.
StephaneLenclud@238
     1
using System;
StephaneLenclud@238
     2
using System.Collections.Generic;
StephaneLenclud@238
     3
using System.Linq;
StephaneLenclud@238
     4
using System.Text;
StephaneLenclud@238
     5
using System.Threading.Tasks;
StephaneLenclud@238
     6
StephaneLenclud@238
     7
StephaneLenclud@238
     8
using System;
StephaneLenclud@238
     9
using System.Collections.Generic;
StephaneLenclud@238
    10
using System.Runtime.Serialization;
StephaneLenclud@238
    11
StephaneLenclud@238
    12
StephaneLenclud@238
    13
namespace SharpLib.Ear
StephaneLenclud@238
    14
{
StephaneLenclud@238
    15
StephaneLenclud@238
    16
    /// <summary>
StephaneLenclud@238
    17
    /// EAR object provides serialization support.
StephaneLenclud@238
    18
    /// It assumes most derived class is decorated with AttributeObject.
StephaneLenclud@238
    19
    /// </summary>
StephaneLenclud@238
    20
    [DataContract]
StephaneLenclud@238
    21
    [KnownType("DerivedTypes")]
StephaneLenclud@238
    22
    public abstract class Object: IComparable
StephaneLenclud@238
    23
    {
StephaneLenclud@238
    24
StephaneLenclud@238
    25
        public string Name
StephaneLenclud@238
    26
        {
StephaneLenclud@238
    27
            //Get the name of this object attribute
StephaneLenclud@238
    28
            get { return Utils.Reflection.GetAttribute<AttributeObject>(GetType()).Name; }
StephaneLenclud@238
    29
            private set { }
StephaneLenclud@238
    30
        }
StephaneLenclud@238
    31
StephaneLenclud@238
    32
        public string Description
StephaneLenclud@238
    33
        {
StephaneLenclud@238
    34
            //Get the description of this object attribute
StephaneLenclud@238
    35
            get { return Utils.Reflection.GetAttribute<AttributeObject>(GetType()).Description; }
StephaneLenclud@238
    36
            private set { }
StephaneLenclud@238
    37
        }
StephaneLenclud@238
    38
StephaneLenclud@238
    39
        public virtual string Brief()
StephaneLenclud@238
    40
        {
StephaneLenclud@238
    41
            return Name;
StephaneLenclud@238
    42
        }
StephaneLenclud@238
    43
StephaneLenclud@238
    44
        public int CompareTo(object obj)
StephaneLenclud@238
    45
        {
StephaneLenclud@238
    46
            //Sort by object name
StephaneLenclud@238
    47
            return Utils.Reflection.GetAttribute<AttributeObject>(GetType()).Name.CompareTo(obj.GetType());
StephaneLenclud@238
    48
        }
StephaneLenclud@238
    49
StephaneLenclud@238
    50
        /// <summary>
StephaneLenclud@238
    51
        /// So that data contract knows all our types.
StephaneLenclud@238
    52
        /// </summary>
StephaneLenclud@238
    53
        /// <returns></returns>
StephaneLenclud@238
    54
        private static IEnumerable<Type> DerivedTypes()
StephaneLenclud@238
    55
        {
StephaneLenclud@238
    56
            return SharpLib.Utils.Reflection.GetDerivedTypes<Object>();
StephaneLenclud@238
    57
        }
StephaneLenclud@238
    58
StephaneLenclud@238
    59
    }
StephaneLenclud@238
    60
}