示例#1
0
        internal object Invoke(object evt)
        {
            var eventArgs = new HtmlEventArgs();

            if (evt != null)
            {
                var dict = (IDictionary <string, object>)((object[])evt)[0];
                ScriptObjectHelper.DictionaryToScriptableType(dict, eventArgs);
            }

            EventHandlers?.Invoke(this.Source, eventArgs);

            if (EventHandlers == null)
            {
                try
                {
                    var eventDelegate = (MulticastDelegate)Source.GetType().GetTypeInfo().GetField(EventName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(Source);
                    eventDelegate.DynamicInvoke(new object[] { Source, EventArgs.Empty });
                }
                catch (Exception exc)
                {
                    // We get an exception if there is nothing to invoke
                    Console.WriteLine($"exception {exc.Message}");
                }
            }
            return(null);
        }
示例#2
0
        internal object Invoke(object evt)
        {
            var eventArgs = new HtmlEventArgs();

            defaultPrevented = false;
            cancelBubble     = false;
            eventArgs.PreventDefaultAction  = () => { defaultPrevented = true; };
            eventArgs.StopPropagationAction = () => { cancelBubble = true; };

            if (evt != null)
            {
                try
                {
                    var dict = (IDictionary <string, object>)((object[])evt)[0];
                    ScriptObjectHelper.DictionaryToScriptableType(dict, eventArgs);
                    if (eventArgs.DataTransfer != null)
                    {
                        dropEffect = eventArgs.DataTransfer.DropEffectValue;
                        eventArgs.DataTransfer.DropEffectAction = (eff) => { dropEffect = eff; };
                    }
                }
                catch (Exception evtExc)
                {
                    Console.WriteLine($"Error parsing HtmlEventArgs: {evtExc.Message}");
                }
            }

            EventHandlers?.Invoke(this.Source, eventArgs);

            if (EventHandlers == null)
            {
                try
                {
                    var eventDelegate = (MulticastDelegate)Source.GetType().GetTypeInfo().GetField(EventName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(Source);
                    eventDelegate.DynamicInvoke(new object[] { Source, EventArgs.Empty });
                }
                catch (Exception exc)
                {
                    // We get an exception if there is nothing to invoke
                    Console.WriteLine($"WebSharpHtmlEvent Invoke Exception {exc.Message}");
                }
            }
            return(null);
        }