Exemplo n.º 1
0
        private NativeEventAttribute LoadEventInfo(Type type)
        {
            NativeEventAttribute attribute = type.GetCustomAttribute <NativeEventAttribute>();

            if (attribute != null)
            {
                return(attribute);
            }

            throw new InvalidOperationException($"Event Type {type.GetFullName()} does not define an event info attribute!");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Subscribes to the specified event on the given object.
        /// </summary>
        /// <param name="nwObject">The subscribe target for this event.</param>
        /// <param name="callback">The callback function/handler for this event.</param>
        /// <typeparam name="TObject">The type of nwObject.</typeparam>
        /// <typeparam name="TEvent">The event to subscribe to.</typeparam>
        public void Subscribe <TObject, TEvent>(TObject nwObject, Action <TEvent> callback)
            where TEvent : NativeEvent <TObject, TEvent>, new()
            where TObject : NwObject
        {
            EventHandler eventHandler = GetOrCreateHandler <TObject, TEvent>();

            NativeEventAttribute eventInfo = GetEventInfo(typeof(TEvent));

            InitObjectHook <TObject, TEvent>(eventHandler, nwObject, eventInfo.EventScriptType);

            eventHandler.Subscribe(nwObject, callback);
        }