Пример #1
0
        void registerEventsForHandler <T>(EventHandler <T> handler)
            where T : class, IEventTarget
        {
            Event <T>[] events =
                TypeUtils2.GetSubTypes(typeof(Event <T>))
                .Where(x => !x.IsAbstract)
                .Select <System.Type, System.Object>(TypeUtils2.CreateInstance)
                .Cast <Event <T> >()
                .ToArray();

            foreach (Event <T> ev in events)
            {
                handler.Register(ev.GetType());
                RegisterPacketHandler(handler, ev.EventId);
            }
        }
Пример #2
0
        void initReceivers()
        {
            List <MethodInfo> methods = TypeUtils2.GetMethodsWithAttributes(typeof(RPCAttribute));

            foreach (MethodInfo method in methods)
            {
                if (!method.IsStatic)
                {
                    log.Error("The method '{0}' is not static, and can't be used as an RPC", method.GetPrettyName());
                    continue;
                }

                initReceiver(null, method);
            }

            log.Info("Found {0} RPC receivers", receivers.Count);
        }
Пример #3
0
        internal protected ContextPlugin CreateContextPlugin(Type attributeType)
        {
            Type contextPluginType =
                TypeUtils2.GetSubTypesWithAttribute(
                    typeof(ContextPlugin),
                    true,
                    attributeType
                    ).FirstOrDefault();

            if (contextPluginType == null)
            {
                log.Warn("Found no ContextPlugin class with the {0} attribute, using DefaultContextPlugin", attributeType.Name);
                contextPluginType = typeof(DefaultContextPlugin);
            }

            return((ContextPlugin)TypeUtils2.CreateInstance(contextPluginType));
        }