public static IEvent ToEvent(this EventGridEvent @event) { if (@event == null) { throw new ArgumentNullException(nameof(@event)); } return(@event.EventType switch { EventTypes.IntegrationCreated => @event.ReadAs <IntegrationCreatedEvent, IntegrationEventData>(), EventTypes.IntegrationDeleted => @event.ReadAs <IntegrationDeletedEvent, IntegrationEventData>(), EventTypes.IntegrationUpdated => @event.ReadAs <IntegrationUpdatedEvent, IntegrationEventData>(), EventTypes.IntegrationProviderUpdate => @event.ReadAs <IntegrationProviderUpdateEvent, IntegrationProviderEventData>(), _ => throw new NotSupportedException($"Unsupported event type '{@event.EventType}'"), });
/// <summary> /// Converts the EventGridEvent into TEvent. For conversion to succeed e.EventType must match TEvent.EventType and e.Data must be an instance of EventData. /// </summary> /// <typeparam name="TEvent">The type to convert into.</typeparam> /// <param name="e">The event to convert.</param> /// <returns>The converted TEvent or default(TEvent) if conversion failed.</returns> public static TEvent ReadAs <TEvent>(this EventGridEvent e) where TEvent : IEvent { return(e.ReadAs <TEvent, EventData>()); }