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