< Summary

Information
Class: Elsa.Extensions.ActivityDescriptorExtensions
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Extensions/ActivityDescriptorExtensions.cs
Line coverage
44%
Covered lines: 4
Uncovered lines: 5
Coverable lines: 9
Total lines: 65
Line coverage: 44.4%
Branch coverage
12%
Covered branches: 1
Total branches: 8
Branch coverage: 12.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Extensions/ActivityDescriptorExtensions.cs

#LineLine coverage
 1using Elsa.Workflows;
 2using Elsa.Workflows.Models;
 3
 4// ReSharper disable once CheckNamespace
 5namespace Elsa.Extensions;
 6
 7/// <summary>
 8/// Provides extensions for <see cref="ActivityDescriptor"/>.
 9/// </summary>
 10public 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        {
 019            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        {
 027            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        {
 035            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        {
 3157643            var wrappedInputDescriptors = activityDescriptor.Inputs.Where(x => x.IsWrapped).ToList();
 4468544            var inputLookup = wrappedInputDescriptors.ToDictionary(x => x.Name, x => (Input?)x.ValueGetter(activity));
 1513545            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        {
 10253            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        {
 061            var inputDescriptor = activityDescriptor.Inputs.FirstOrDefault(x => x.Name == name && x.IsWrapped);
 062            return inputDescriptor?.ValueGetter(activity) as Input;
 63        }
 64    }
 65}