static INHContributor GetEventListenerContributor(IEnumerable <Type> exportedtypes) { var contributor = new EventListenerContributor(); foreach (var type in exportedtypes) { var eventListenerAttributes = type.GetCustomAttributes(typeof(EventListenerAttribute), false); if (eventListenerAttributes.Length == 1) { var attribute = (EventListenerAttribute)eventListenerAttributes[0]; var config = new EventListenerConfig(type) { ReplaceExisting = attribute.ReplaceExisting, SkipEvent = attribute.SkipEvent, Singleton = attribute.Singleton }; contributor.Add(config); } } return(contributor); }
static INHContributor GetEventListenerContributor(IEnumerable<Type> exportedtypes) { var contributor = new EventListenerContributor(); foreach (var type in exportedtypes) { var eventListenerAttributes = type.GetCustomAttributes(typeof(EventListenerAttribute), false); if (eventListenerAttributes.Length == 1) { var attribute = (EventListenerAttribute)eventListenerAttributes[0]; var config = new EventListenerConfig(type) { ReplaceExisting = attribute.ReplaceExisting, SkipEvent = attribute.SkipEvent, Singleton = attribute.Singleton }; contributor.Add(config); } } return contributor; }
private static void RegisterEventListeners(IEnumerable<Type> types) { var contributor = new EventListenerContributor(); foreach (var type in types) { var eventListenerAttributes = type.GetCustomAttributes(typeof(EventListenerAttribute), false); if (eventListenerAttributes.Length == 1) { var attribute = (EventListenerAttribute) eventListenerAttributes[0]; var config = new EventListenerConfig(type) { ReplaceExisting = attribute.ReplaceExisting, Ignore=attribute.Ignore, SkipEvent=attribute.SkipEvent, Singleton = attribute.Singleton, Include = attribute.Include, Exclude = attribute.Exclude }; contributor.Add(config); } } if (EventListenerComponentRegistrationHook != null) { EventListenerComponentRegistrationHook(contributor); } var addEventListenerAttributes = new List<EventListenerAssemblyAttribute>(); var ignoreEventListenerAttributes = new List<EventListenerAssemblyAttribute>(); foreach (var assembly in registeredAssemblies) { addEventListenerAttributes.AddRange( (AddEventListenerAttribute[]) assembly.GetCustomAttributes(typeof (AddEventListenerAttribute), false)); ignoreEventListenerAttributes.AddRange((IgnoreEventListenerAttribute[]) assembly.GetCustomAttributes(typeof(IgnoreEventListenerAttribute), false)); } ProcessEventListenerAssemblyAttributes(contributor, ignoreEventListenerAttributes); ProcessEventListenerAssemblyAttributes(contributor, addEventListenerAttributes); if (EventListenerFacilityConfigurationHook != null) { EventListenerFacilityConfigurationHook(contributor); } AddContributor(contributor); }
private static void ProcessEventListenerAssemblyAttributes(EventListenerContributor contributor, IEnumerable<EventListenerAssemblyAttribute> attributes) { foreach (var attribute in attributes) { if (attribute.Assembly != null) { foreach (var type in GetExportedTypesFromAssembly(attribute.Assembly)) { if (EventListenerContributor.GetEventTypes(type).Length > 0) { var config = contributor.Get(type) ?? contributor.Add(new EventListenerConfig(type)); ConfigureEventListener(attribute, config); } } } if (attribute.Type != null) { var config = contributor.Get(attribute.Type) ?? contributor.Add(new EventListenerConfig(attribute.Type)); ConfigureEventListener(attribute, config); } } }