Inheritance: PrologGenericDelegate
Example #1
0
        static public bool cliAddEventHandler(PlTerm clazzOrInstance, PlTerm memberSpec, PlTerm prologPred)
        {
            object getInstance;
            Type c;
            if (!GetInstanceAndType(clazzOrInstance, out getInstance, out c)) return false; 
            Type[] paramz = null;
            if (!CheckBound(memberSpec, prologPred)) return false;
            EventInfo fi = findEventInfo(memberSpec, c, ref paramz, BindingFlagsALL);
            if (fi == null)
            {
                return Error("Cant find event {0} on {1}", memberSpec, c);
            }
            var Key = new EventHandlerInPrologKey
            {
                Name = PredicateName(prologPred),
                Module = PredicateModule(prologPred),
                Arity = PredicateArity(prologPred),
                Origin = getInstance,
                Event = fi
            };

            lock (PrologEventHandlers)
            {
                EventHandlerInProlog handlerInProlog;
                if (PrologEventHandlers.TryGetValue(Key, out handlerInProlog))
                {
                    fi.RemoveEventHandler(getInstance, handlerInProlog.Delegate);
                    PrologEventHandlers.Remove(Key);
                }
                handlerInProlog = new EventHandlerInProlog(Key);
                PrologEventHandlers.Add(Key, handlerInProlog);
                fi.AddEventHandler(getInstance, handlerInProlog.Delegate);
            }
            return true;
        }
Example #2
0
        static public bool cliAddEventHandler(PlTerm clazzOrInstance, PlTerm memberSpec, PlTerm prologPred)
        {
            object getInstance;
            Type   c;

            if (!GetInstanceAndType(clazzOrInstance, out getInstance, out c))
            {
                return(false);
            }
            Type[] paramz = null;
            if (!CheckBound(memberSpec, prologPred))
            {
                return(false);
            }
            EventInfo fi = findEventInfo(memberSpec, c, ref paramz, BindingFlagsALL);

            if (fi == null)
            {
                return(Error("Cant find event {0} on {1}", memberSpec, c));
            }
            var Key = new EventHandlerInPrologKey
            {
                Name   = PredicateName(prologPred),
                Module = PredicateModule(prologPred),
                Arity  = PredicateArity(prologPred),
                Origin = getInstance,
                Event  = fi
            };

            lock (PrologEventHandlers)
            {
                EventHandlerInProlog handlerInProlog;
                if (PrologEventHandlers.TryGetValue(Key, out handlerInProlog))
                {
                    fi.RemoveEventHandler(getInstance, handlerInProlog.Delegate);
                    PrologEventHandlers.Remove(Key);
                }
                handlerInProlog = new EventHandlerInProlog(Key);
                PrologEventHandlers.Add(Key, handlerInProlog);
                fi.AddEventHandler(getInstance, handlerInProlog.Delegate);
            }
            return(true);
        }