Castle.ActiveRecord.EventListenerContributor.Add C# (CSharp) Метод

Add() публичный Метод

Adds an event listener configuration
When the configuration is null When the configuration is already present.
public Add ( EventListenerConfig config ) : EventListenerConfig
config EventListenerConfig the configuration to add
Результат EventListenerConfig
        public EventListenerConfig Add(EventListenerConfig config)
        {
            if (config == null) throw new ArgumentNullException("config");
            if (listeners.ContainsKey(config.ListenerType))
                throw new ArgumentException(string.Format("Configuration for Listener Type {0} is already present.", config.ListenerType.FullName), "config");
            var events = GetEventTypes(config.ListenerType);
            if (events.Length == 0)
                throw new ArgumentException(string.Format("The Listener of type {0} does not implement any known NHibernate event listener interfaces.", config.ListenerType.FullName), "config");

            listeners.Add(config.ListenerType, config);
            foreach (var eventType in events)
            {
                if (!listenersPerEvent.ContainsKey(eventType))
                    listenersPerEvent.Add(eventType, new HashedSet<Type>());
                listenersPerEvent[eventType].Add(config.ListenerType);
            }
            return config;
        }

Usage Example

Пример #1
0
 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);
         }
     }
 }
All Usage Examples Of Castle.ActiveRecord.EventListenerContributor::Add