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