Example #1
0
        public TImplementationDelegate MapForAttachment([CanBeNull] EventHandler <TAbstraction> handler, [NotNull] Func <EventHandler <TAbstraction>, TImplementationDelegate> convertDelegate)
        {
            if (handler == null)
            {
                return(null);
            }
            if (convertDelegate == null)
            {
                throw new ArgumentNullException(nameof(convertDelegate));
            }

            if (!_lookup.TryGetValue(handler, out var ctx))
            {
                ctx = new AbstractionEventHandlerContext <TImplementationDelegate>(convertDelegate(handler));
                _lookup.Add(handler, ctx);
            }

            ctx.Count++;

            return(ctx.Handler);
        }
Example #2
0
        public EventHandler <TImplementation> MapForAttachment([CanBeNull] EventHandler <TAbstraction> handler, [NotNull] Func <TImplementation, TAbstraction> toInterface)
        {
            if (toInterface == null)
            {
                throw new ArgumentNullException(nameof(toInterface));
            }
            if (handler == null)
            {
                return(null);
            }

            if (!_lookup.TryGetValue(handler, out var ctx))
            {
                ctx = new AbstractionEventHandlerContext <EventHandler <TImplementation> >((sender, args) => handler(sender, toInterface(args)));
                _lookup.Add(handler, ctx);
            }

            ctx.Count++;

            return(ctx.Handler);
        }