| | | 1 | | using System.Collections.ObjectModel; |
| | | 2 | | using System.Dynamic; |
| | | 3 | | using System.Text.Json; |
| | | 4 | | using System.Text.Json.Nodes; |
| | | 5 | | using Elsa.Extensions; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Expressions.Options; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Options for the expression feature. |
| | | 11 | | /// </summary> |
| | | 12 | | public class ExpressionOptions |
| | | 13 | | { |
| | 3 | 14 | | private readonly IDictionary<string, Type> _aliasTypeDictionary = new Dictionary<string, Type>(); |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Initializes a new instance of the <see cref="ExpressionOptions"/> class. |
| | | 18 | | /// </summary> |
| | 3 | 19 | | public ExpressionOptions() |
| | | 20 | | { |
| | 3 | 21 | | AliasTypeDictionary = new ReadOnlyDictionary<string, Type>(_aliasTypeDictionary); |
| | | 22 | | |
| | 3 | 23 | | this.AddTypeAlias<short>("Int16"); |
| | 3 | 24 | | this.AddTypeAlias<int>("Int32"); |
| | 3 | 25 | | this.AddTypeAlias<long>("Int64"); |
| | 3 | 26 | | this.AddTypeAlias<long>("Long"); |
| | 3 | 27 | | this.AddTypeAlias<float>("Single"); |
| | 3 | 28 | | this.AddTypeAlias<object>("Object"); |
| | 3 | 29 | | this.AddTypeAlias<string>("String"); |
| | 3 | 30 | | this.AddTypeAlias<bool>("Boolean"); |
| | 3 | 31 | | this.AddTypeAlias<decimal>("Decimal"); |
| | 3 | 32 | | this.AddTypeAlias<double>("Double"); |
| | 3 | 33 | | this.AddTypeAlias<byte[]>("ByteArray"); |
| | 3 | 34 | | this.AddTypeAlias<Guid>(); |
| | 3 | 35 | | this.AddTypeAlias<DateTime>(); |
| | 3 | 36 | | this.AddTypeAlias<DateTimeOffset>(); |
| | 3 | 37 | | this.AddTypeAlias<TimeSpan>(); |
| | 3 | 38 | | this.AddTypeAlias<Stream>(); |
| | 3 | 39 | | this.AddTypeAlias<ExpandoObject>("JSON"); |
| | 3 | 40 | | this.AddTypeAlias<JsonElement>(); |
| | 3 | 41 | | this.AddTypeAlias<JsonNode>(); |
| | 3 | 42 | | this.AddTypeAlias<JsonObject>(); |
| | 3 | 43 | | this.AddTypeAlias<IDictionary<string, string>>("StringDictionary"); |
| | 3 | 44 | | this.AddTypeAlias<IDictionary<string, object>>("ObjectDictionary"); |
| | 3 | 45 | | this.AddTypeAlias<Dictionary<string, string>>("StringMap"); |
| | 3 | 46 | | this.AddTypeAlias<Dictionary<string, object>>("ObjectMap"); |
| | 3 | 47 | | } |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// Gets the type alias dictionary. |
| | | 51 | | /// </summary> |
| | 6 | 52 | | public IDictionary<string, Type> AliasTypeDictionary { get; set; } |
| | | 53 | | |
| | | 54 | | /// <summary> |
| | | 55 | | /// Registers a well-known type alias. |
| | | 56 | | /// </summary> |
| | | 57 | | public ExpressionOptions RegisterTypeAlias(Type type, string alias) |
| | | 58 | | { |
| | 85 | 59 | | _aliasTypeDictionary[alias] = type; |
| | 85 | 60 | | return this; |
| | | 61 | | } |
| | | 62 | | } |