| | | 1 | | using System.Dynamic; |
| | | 2 | | using Elsa.Expressions.JavaScript.Contracts; |
| | | 3 | | using Elsa.Expressions.JavaScript.Extensions; |
| | | 4 | | using Elsa.Workflows.LogPersistence; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Expressions.JavaScript.Services; |
| | | 7 | | |
| | | 8 | | /// <inheritdoc /> |
| | | 9 | | public class TypeAliasRegistry : ITypeAliasRegistry |
| | | 10 | | { |
| | 4 | 11 | | private readonly IDictionary<Type, string> _typeAliasDictionary = new Dictionary<Type, string>(); |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Constructor. |
| | | 15 | | /// </summary> |
| | 4 | 16 | | public TypeAliasRegistry() |
| | | 17 | | { |
| | 4 | 18 | | this.RegisterType<object>("any"); |
| | 4 | 19 | | this.RegisterType<ExpandoObject>("any"); |
| | 4 | 20 | | this.RegisterType<string>("string"); |
| | 4 | 21 | | this.RegisterType<bool>("boolean"); |
| | 4 | 22 | | this.RegisterType<short>("number"); |
| | 4 | 23 | | this.RegisterType<int>("number"); |
| | 4 | 24 | | this.RegisterType<long>("number"); |
| | 4 | 25 | | this.RegisterType<decimal>("Decimal"); |
| | 4 | 26 | | this.RegisterType<float>("Single"); |
| | 4 | 27 | | this.RegisterType<double>("Double"); |
| | 4 | 28 | | this.RegisterType<byte[]>("Buffer"); |
| | 4 | 29 | | this.RegisterType<Stream>("Stream"); |
| | 4 | 30 | | this.RegisterType<Guid>("Guid"); |
| | 4 | 31 | | this.RegisterType<DateTime>("Date"); |
| | 4 | 32 | | this.RegisterType<DateTimeOffset>("Date"); |
| | 4 | 33 | | this.RegisterType<DateOnly>("Date"); |
| | 4 | 34 | | this.RegisterType<TimeOnly>("Date"); |
| | 4 | 35 | | this.RegisterType<IDictionary<string, object>>("ObjectDictionary"); |
| | 4 | 36 | | this.RegisterType<LogPersistenceMode>("LogPersistenceMode"); |
| | 4 | 37 | | } |
| | | 38 | | |
| | | 39 | | /// <inheritdoc /> |
| | | 40 | | public void RegisterType(Type type, string alias) |
| | | 41 | | { |
| | 105 | 42 | | _typeAliasDictionary[type] = alias; |
| | 105 | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <inheritdoc /> |
| | 0 | 46 | | public bool TryGetAlias(Type type, out string alias) => _typeAliasDictionary.TryGetValue(type, out alias!); |
| | | 47 | | } |