| | | 1 | | using Elsa.Workflows; |
| | | 2 | | using Elsa.Workflows.Helpers; |
| | | 3 | | using Elsa.Workflows.Models; |
| | | 4 | | |
| | | 5 | | // ReSharper disable once CheckNamespace |
| | | 6 | | namespace Elsa.Extensions; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Adds extensions to <c>Bookmark</c> and sets thereof. |
| | | 10 | | /// </summary> |
| | | 11 | | public static class BookmarkExtensions |
| | | 12 | | { |
| | | 13 | | /// <param name="bookmarks">The set of bookmarks to filter.</param> |
| | | 14 | | extension(IEnumerable<Bookmark> bookmarks) |
| | | 15 | | { |
| | | 16 | | /// <summary> |
| | | 17 | | /// Filters the specified set of bookmarks by the specified activity type. |
| | | 18 | | /// </summary> |
| | | 19 | | /// <typeparam name="T">The activity type to filter by.</typeparam> |
| | | 20 | | /// <returns>The filtered set of bookmarks.</returns> |
| | | 21 | | public IEnumerable<Bookmark> Filter<T>() where T : IActivity |
| | | 22 | | { |
| | 0 | 23 | | var bookmarkName = ActivityTypeNameHelper.GenerateTypeName<T>(); |
| | 0 | 24 | | return bookmarks.Filter(bookmarkName); |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | public IEnumerable<Bookmark> Filter(string name) |
| | | 28 | | { |
| | 3744 | 29 | | return bookmarks.Where(x => x.Name == name); |
| | | 30 | | } |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Returns the Data property of the bookmark as a strongly-typed object. |
| | | 35 | | /// </summary> |
| | | 36 | | /// <param name="bookmark">The bookmark.</param> |
| | | 37 | | /// <typeparam name="T">The type of the Data property.</typeparam> |
| | | 38 | | /// <returns>The Data property of the bookmark as a strongly-typed object.</returns> |
| | 23 | 39 | | public static T GetPayload<T>(this Bookmark bookmark) => (T)bookmark.Payload!; |
| | | 40 | | } |