Exemplo n.º 1
0
        public Events(
            TType declaringType,
            IEventFactory <TEvent, TEventProperty, TType> eventFactory)
        {
            List <TEvent> events = new List <TEvent>();
            List <ExplicitInterfaceEventWithMonoCecil> explicitInterfaceEvents = new List <ExplicitInterfaceEventWithMonoCecil>();
            List <TEventProperty>             eventProperties = new List <TEventProperty>();
            List <AbstractEventWithMonoCecil> abstractEvents  = new List <AbstractEventWithMonoCecil>();

            foreach (EventDefinition eventDefinition in declaringType.TypeDefinition.Events)
            {
                if (eventDefinition.AddMethod.IsDefined(declaringType.Assembly, typeof(CompilerGeneratedAttribute)))
                {
                    events.Add(eventFactory.CreateEvent(declaringType, eventDefinition));
                }
                else if (eventDefinition.Name.Contains("."))
                {
                    explicitInterfaceEvents.Add(new ExplicitInterfaceEventWithMonoCecil(declaringType, eventDefinition));
                }
                else if (eventDefinition.AddMethod.IsAbstract)
                {
                    abstractEvents.Add(new AbstractEventWithMonoCecil(declaringType, eventDefinition));
                }
                else
                {
                    eventProperties.Add(eventFactory.CreateEventProperty(declaringType, eventDefinition));
                }
            }

            EventsWithMonoCecil                 = events;
            EventPropertiesWithMonoCecil        = eventProperties;
            ExplictInterfaceEventsWithMonoCecil = explicitInterfaceEvents;
            AbstractEventsWithMonoCecil         = abstractEvents;
        }
Exemplo n.º 2
0
        public Events(
            TType declaringType,
            IEventFactory <TEvent, TEventProperty, TType> eventFactory,
            IDictionary <MethodInfo, Type> interfaceMethods)
        {
            List <TEvent> events = new List <TEvent>();
            List <ExplicitInterfaceEventWithReflection> explicitInterfaceEvents = new List <ExplicitInterfaceEventWithReflection>();
            List <TEventProperty> eventProperties             = new List <TEventProperty>();
            List <AbstractEventWithReflection> abstractEvents = new List <AbstractEventWithReflection>();

            foreach (EventInfo eventInfo in declaringType.Type.GetAllEvents())
            {
                Type interfaceType;
                if (eventInfo.AddMethod.IsDefined(typeof(CompilerGeneratedAttribute), false))
                {
                    events.Add(eventFactory.CreateEvent(declaringType, eventInfo));
                }
                else if (interfaceMethods.TryGetValue(eventInfo.AddMethod, out interfaceType))
                {
                    explicitInterfaceEvents.Add(new ExplicitInterfaceEventWithReflection(declaringType, interfaceType, eventInfo));
                }
                else if (eventInfo.AddMethod.IsAbstract)
                {
                    abstractEvents.Add(new AbstractEventWithReflection(declaringType, eventInfo));
                }
                else
                {
                    eventProperties.Add(eventFactory.CreateEventProperty(declaringType, eventInfo));
                }
            }

            EventsWithReflection                 = events;
            EventPropertiesWithReflection        = eventProperties;
            ExplictInterfaceEventsWithReflection = explicitInterfaceEvents;
            AbstractEventsWithReflection         = abstractEvents;
        }