| | | 1 | | using Elsa.Workflows; |
| | | 2 | | using Elsa.Workflows.Models; |
| | | 3 | | |
| | | 4 | | // ReSharper disable once CheckNamespace |
| | | 5 | | namespace Elsa.Extensions; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Provides extensions for <see cref="ActivityDescriptor"/>. |
| | | 9 | | /// </summary> |
| | | 10 | | public static class ActivityDescriptorExtensions |
| | | 11 | | { |
| | | 12 | | extension(ActivityDescriptor activityDescriptor) |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// Returns the specified attribute from the activity descriptor. |
| | | 16 | | /// </summary> |
| | | 17 | | public T? GetAttribute<T>() where T : Attribute |
| | | 18 | | { |
| | 0 | 19 | | return (T?)activityDescriptor.Attributes.FirstOrDefault(x => x.GetType() == typeof(T)); |
| | | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Returns each wrapped input from the specified activity. |
| | | 24 | | /// </summary> |
| | | 25 | | public IEnumerable<InputDescriptor> GetWrappedInputPropertyDescriptors(IActivity activity) |
| | | 26 | | { |
| | 0 | 27 | | return activityDescriptor.Inputs.Where(x => x.IsWrapped); |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Returns each naked input from the specified activity. |
| | | 32 | | /// </summary> |
| | | 33 | | public IEnumerable<InputDescriptor> GetNakedInputPropertyDescriptors(IActivity activity) |
| | | 34 | | { |
| | 0 | 35 | | return activityDescriptor.Inputs.Where(x => !x.IsWrapped); |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// Returns each input from the specified activity. |
| | | 40 | | /// </summary> |
| | | 41 | | public IDictionary<string, Input?> GetWrappedInputProperties(IActivity activity) |
| | | 42 | | { |
| | 31576 | 43 | | var wrappedInputDescriptors = activityDescriptor.Inputs.Where(x => x.IsWrapped).ToList(); |
| | 44685 | 44 | | var inputLookup = wrappedInputDescriptors.ToDictionary(x => x.Name, x => (Input?)x.ValueGetter(activity)); |
| | 15135 | 45 | | return inputLookup; |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Returns each input descriptor from the specified activity. |
| | | 50 | | /// </summary> |
| | | 51 | | public InputDescriptor? GetWrappedInputPropertyDescriptor(IActivity activity, string name) |
| | | 52 | | { |
| | 102 | 53 | | return activityDescriptor.Inputs.FirstOrDefault(x => x.Name == name && x.IsWrapped); |
| | | 54 | | } |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Returns each input from the specified activity. |
| | | 58 | | /// </summary> |
| | | 59 | | public Input? GetWrappedInputProperty(IActivity activity, string name) |
| | | 60 | | { |
| | 0 | 61 | | var inputDescriptor = activityDescriptor.Inputs.FirstOrDefault(x => x.Name == name && x.IsWrapped); |
| | 0 | 62 | | return inputDescriptor?.ValueGetter(activity) as Input; |
| | | 63 | | } |
| | | 64 | | } |
| | | 65 | | } |