コード例 #1
0
ファイル: Platform.cs プロジェクト: CheckTech/Eto
        internal HandlerInfo FindHandler(Type type)
        {
            HandlerInfo info;

            if (handlerMap.TryGetValue(type, out info))
            {
                return(info);
            }

            var           handler = type.GetCustomAttribute <HandlerAttribute>(true);
            Func <object> activator;

            if (handler != null && instantiatorMap.TryGetValue(handler.Type, out activator))
            {
                var autoInit = handler.Type.GetCustomAttribute <AutoInitializeAttribute>(true);
                info = new HandlerInfo(autoInit == null || autoInit.Initialize, activator);
                handlerMap.Add(type, info);
                return(info);
            }
            return(null);
        }
コード例 #2
0
        internal HandlerInfo FindHandler(Type type)
        {
            HandlerInfo info;

            if (handlerMap.TryGetValue(type, out info))
            {
                return(info);
            }

            var handler = type.GetCustomAttribute <HandlerAttribute>(true);

            if (handler != null)
            {
                if (instantiatorMap.TryGetValue(handler.Type, out var activator))
                {
                    var autoInit = handler.Type.GetCustomAttribute <AutoInitializeAttribute>(true);
                    info = new HandlerInfo(autoInit == null || autoInit.Initialize, activator);
                    handlerMap.Add(type, info);
                    return(info);
                }
                // load the assembly of the handler type (needed when type is a subclass)
                if (!loadedAssemblies.Contains(handler.Type.GetAssembly()))
                {
                    LoadAssembly(handler.Type.GetAssembly());
                    return(FindHandler(type));
                }
            }

            // load the assembly of the target type (can be a subclass)
            if (!loadedAssemblies.Contains(type.GetAssembly()))
            {
                LoadAssembly(type.GetAssembly());
                return(FindHandler(type));
            }
            return(null);
        }