예제 #1
0
        internal static EventDict GenerateLookup()
        {
            var lookup = new EventDict();

            foreach (Type type in Assembly.GetAssembly(typeof(BaseEvent)).GetTypes())
            {
                if (!type.IsClass || type.IsAbstract || !type.IsSubclassOf(typeof(BaseEvent)) ||
                    type.IsEquivalentTo(typeof(UnknownEvent)))
                {
                    continue;
                }
                var tmp = (BaseEvent)Activator.CreateInstance(type);
                var id  = tmp.ID;
                if (lookup.ContainsKey(id))
                {
                    throw new Exception("ID already in lookup map");
                }
                var lambda = Expression.Lambda <Func <BaseEvent> >(
                    Expression.New(type),
                    Array.Empty <ParameterExpression>()
                    ).Compile();
                lookup.Add(id, lambda);
            }
            return(lookup);
        }
예제 #2
0
        private static IEvent CreateEvent(byte rawID)
        {
            var id = (EventID)rawID;

            if (!Lookup.ContainsKey(id))
            {
                throw new IOException("Unknow event ID!");
            }
            return(Lookup[id]());
        }
예제 #3
0
        private static EventDict GenerateLookup()
        {
            var lookup = new EventDict();

            foreach (Type type in Assembly.GetAssembly(typeof(IEvent)).GetTypes())
            {
                if (!type.IsClass || type.IsAbstract || type.IsInterface || !typeof(IEvent).IsAssignableFrom(type))
                {
                    continue;
                }
                var tmp = (IEvent)Activator.CreateInstance(type);
                var id  = tmp.ID;
                if (lookup.ContainsKey(id))
                {
                    throw new Exception("ID already in lookup map");
                }
                var lambda = Expression.Lambda <Func <IEvent> >(
                    Expression.New(type),
                    Array.Empty <ParameterExpression>()
                    ).Compile();
                lookup.Add(id, lambda);
            }
            return(lookup);
        }