| | | 1 | | using System.Dynamic; |
| | | 2 | | using Elsa.Extensions; |
| | | 3 | | using Elsa.Expressions.JavaScript.TypeDefinitions.Abstractions; |
| | | 4 | | using Elsa.Expressions.JavaScript.TypeDefinitions.Contracts; |
| | | 5 | | using Elsa.Expressions.JavaScript.TypeDefinitions.Models; |
| | | 6 | | using Elsa.Workflows.Management.Options; |
| | | 7 | | using JetBrains.Annotations; |
| | | 8 | | using Microsoft.Extensions.Options; |
| | | 9 | | |
| | | 10 | | namespace Elsa.Expressions.JavaScript.Providers; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Produces <see cref="TypeDefinition"/>s for variable types. |
| | | 14 | | /// </summary> |
| | | 15 | | [UsedImplicitly] |
| | 1 | 16 | | internal class VariableTypeDefinitionProvider(ITypeDescriber typeDescriber, IOptions<ManagementOptions> options) : TypeD |
| | | 17 | | { |
| | | 18 | | protected override IEnumerable<TypeDefinition> GetTypeDefinitions(TypeDefinitionContext context) |
| | | 19 | | { |
| | 0 | 20 | | var excludedTypes = new Func<Type, bool>[] |
| | 0 | 21 | | { |
| | 0 | 22 | | type => type == typeof(ExpandoObject), |
| | 0 | 23 | | type => type.IsPrimitive, |
| | 0 | 24 | | type => type.ContainsGenericParameters, |
| | 0 | 25 | | type => type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IDictionary<,>), |
| | 0 | 26 | | type => type == typeof(object), |
| | 0 | 27 | | type => type == typeof(string) |
| | 0 | 28 | | }; |
| | | 29 | | |
| | 0 | 30 | | var variableTypes = |
| | 0 | 31 | | from variableDescriptor in options.Value.VariableDescriptors |
| | 0 | 32 | | let variableType = variableDescriptor.Type |
| | 0 | 33 | | where (variableType.IsClass || variableType.IsInterface || variableType.IsEnum) && !excludedTypes.Any(x => x |
| | 0 | 34 | | select variableType; |
| | | 35 | | |
| | 0 | 36 | | foreach (var variableType in variableTypes.Distinct()) |
| | | 37 | | { |
| | 0 | 38 | | yield return typeDescriber.DescribeType(variableType); |
| | | 39 | | } |
| | 0 | 40 | | } |
| | | 41 | | } |