Line data Source code
1 : using System;
2 :
3 : namespace Cqrs.Events
4 : {
5 : /// <summary>
6 : /// A set of extension method for <see cref="IEvent{TAuthenticationToken}"/>.
7 : /// </summary>
8 : public static class EventExtensions
9 1 : {
10 : /// <summary>
11 : /// The identity of the target object of the provided <paramref name="event"/>.
12 : /// </summary>
13 : /// <param name="event">The <see cref="IEvent{TAuthenticationToken}"/> to locate the identify from.</param>
14 : /// <typeparam name="TAuthenticationToken">The <see cref="Type"/> of the authentication token.</typeparam>
15 : /// <returns><see cref="IEventWithIdentity{TAuthenticationToken}.Rsn"/> or <see cref="IEvent{TAuthenticationToken}.Id"/>.</returns>
16 1 : public static Guid GetIdentity<TAuthenticationToken>(this IEvent<TAuthenticationToken> @event)
17 : {
18 : var eventWithIdentity = @event as IEventWithIdentity<TAuthenticationToken>;
19 : Guid rsn = eventWithIdentity == null ? @event.Id : eventWithIdentity.Rsn;
20 : return rsn;
21 : }
22 : }
23 : }
|