NServiceBus.Conventions.IsEventType C# (CSharp) Method

IsEventType() public method

Returns true if the given type is a event type.
public IsEventType ( Type t ) : bool
t System.Type
return bool
        public bool IsEventType(Type t)
        {
            Guard.AgainstNull(nameof(t), t);
            try
            {
                return EventsConventionCache.ApplyConvention(t, typeHandle =>
                {
                    var type = Type.GetTypeFromHandle(typeHandle);
                    if (type.IsFromParticularAssembly())
                    {
                        return false;
                    }
                    return IsEventTypeAction(type);
                });
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to evaluate Event convention. See inner exception for details.", ex);
            }
        }

Usage Example

 public IEnumerable <PublisherTableEntry> GenerateWithBestPracticeEnforcement(Conventions conventions)
 {
     if (!conventions.IsMessageType(messageType))
     {
         throw new Exception($"Cannot configure publisher for type '{messageType.FullName}' because it is not considered a message. Message types have to either implement NServiceBus.IMessage interface or match a defined message convention.");
     }
     if (!conventions.IsEventType(messageType))
     {
         throw new Exception($"Cannot configure publisher for type '{messageType.FullName}' because it is not considered an event. Event types have to either implement NServiceBus.IEvent interface or match a defined event convention.");
     }
     yield return(new PublisherTableEntry(messageType, address));
 }
All Usage Examples Of NServiceBus.Conventions::IsEventType