| | | 1 | | using Elsa.Expressions.Contracts; |
| | | 2 | | using Elsa.Extensions; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Expressions.Extensions; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Extends <see cref="IWellKnownTypeRegistry"/>. |
| | | 8 | | /// </summary> |
| | | 9 | | public static class WellKnowTypeRegistryExtensions |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Register type <typeparamref name="T"/> with the specified alias. |
| | | 13 | | /// </summary> |
| | 0 | 14 | | public static void RegisterType<T>(this IWellKnownTypeRegistry registry, string alias) => registry.RegisterType(type |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Attempt to return a type with the specified alias. |
| | | 18 | | /// </summary> |
| | | 19 | | public static bool TryGetTypeOrDefault(this IWellKnownTypeRegistry registry, string alias, out Type type) |
| | | 20 | | { |
| | 339 | 21 | | if (registry.TryGetType(alias, out type)) |
| | 290 | 22 | | return true; |
| | | 23 | | |
| | 49 | 24 | | var t = Type.GetType(alias); |
| | | 25 | | |
| | 49 | 26 | | if (t == null) |
| | 0 | 27 | | return false; |
| | | 28 | | |
| | 49 | 29 | | type = t; |
| | 49 | 30 | | return true; |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Returns the alias for the specified type. If no alias was found, the assembly qualified type name is returned in |
| | | 35 | | /// </summary> |
| | | 36 | | public static string GetAliasOrDefault(this IWellKnownTypeRegistry registry, Type type) => |
| | 227 | 37 | | registry.TryGetAlias(type, out var alias) ? alias : type.GetSimpleAssemblyQualifiedName(); |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Returns the type associated with the specified alias. If no type was found, the alias is interpreted as a type n |
| | | 41 | | /// </summary> |
| | 114 | 42 | | public static Type GetTypeOrDefault(this IWellKnownTypeRegistry registry, string alias) => registry.TryGetType(alias |
| | | 43 | | } |