Server/Slions/Ear/Manager.cs
author StephaneLenclud
Fri, 22 Jul 2016 18:19:49 +0200
changeset 209 fef4ca058087
permissions -rw-r--r--
Prototype for event and action framework.
StephaneLenclud@209
     1
//
StephaneLenclud@209
     2
StephaneLenclud@209
     3
StephaneLenclud@209
     4
using System;
StephaneLenclud@209
     5
using System.Collections.Generic;
StephaneLenclud@209
     6
using System.Linq;
StephaneLenclud@209
     7
using System.Reflection;
StephaneLenclud@209
     8
using System.Runtime.Serialization;
StephaneLenclud@209
     9
StephaneLenclud@209
    10
namespace Slions.Ear
StephaneLenclud@209
    11
{
StephaneLenclud@209
    12
    public static class ReflectiveEnumerator
StephaneLenclud@209
    13
    {
StephaneLenclud@209
    14
        static ReflectiveEnumerator() { }
StephaneLenclud@209
    15
StephaneLenclud@209
    16
        public static IEnumerable<T> GetEnumerableOfType<T>() where T : class
StephaneLenclud@209
    17
        {
StephaneLenclud@209
    18
            List<T> objects = new List<T>();
StephaneLenclud@209
    19
            foreach (Type type in
StephaneLenclud@209
    20
                Assembly.GetAssembly(typeof(T)).GetTypes()
StephaneLenclud@209
    21
                .Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(T))))
StephaneLenclud@209
    22
            {
StephaneLenclud@209
    23
                objects.Add((T)Activator.CreateInstance(type));
StephaneLenclud@209
    24
            }
StephaneLenclud@209
    25
            //objects.Sort();
StephaneLenclud@209
    26
            return objects;
StephaneLenclud@209
    27
        }
StephaneLenclud@209
    28
    }
StephaneLenclud@209
    29
StephaneLenclud@209
    30
StephaneLenclud@209
    31
    [DataContract]
StephaneLenclud@209
    32
    class Manager
StephaneLenclud@209
    33
    {
StephaneLenclud@209
    34
        private IEnumerable<Action> Actions;
StephaneLenclud@209
    35
        private IEnumerable<Event> Events;
StephaneLenclud@209
    36
StephaneLenclud@209
    37
        public Manager()
StephaneLenclud@209
    38
        {
StephaneLenclud@209
    39
            Actions = ReflectiveEnumerator.GetEnumerableOfType<Action>();
StephaneLenclud@209
    40
            Events = ReflectiveEnumerator.GetEnumerableOfType<Event>();
StephaneLenclud@209
    41
StephaneLenclud@209
    42
            //CollectActions();
StephaneLenclud@209
    43
            //CollectEvents();
StephaneLenclud@209
    44
        }
StephaneLenclud@209
    45
StephaneLenclud@209
    46
StephaneLenclud@209
    47
StephaneLenclud@209
    48
    }
StephaneLenclud@209
    49
}