< Summary

Information
Class: Elsa.Expressions.Extensions.WellKnowTypeRegistryExtensions
Assembly: Elsa.Expressions
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions/Extensions/WellKnowTypeRegistryExtensions.cs
Line coverage
80%
Covered lines: 8
Uncovered lines: 2
Coverable lines: 10
Total lines: 43
Line coverage: 80%
Branch coverage
70%
Covered branches: 7
Total branches: 10
Branch coverage: 70%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
RegisterType(...)100%210%
TryGetTypeOrDefault(...)75%4485.71%
GetAliasOrDefault(...)100%22100%
GetTypeOrDefault(...)50%44100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions/Extensions/WellKnowTypeRegistryExtensions.cs

#LineLine coverage
 1using Elsa.Expressions.Contracts;
 2using Elsa.Extensions;
 3
 4namespace Elsa.Expressions.Extensions;
 5
 6/// <summary>
 7/// Extends <see cref="IWellKnownTypeRegistry"/>.
 8/// </summary>
 9public static class WellKnowTypeRegistryExtensions
 10{
 11    /// <summary>
 12    /// Register type <typeparamref name="T"/> with the specified alias.
 13    /// </summary>
 014    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    {
 33921        if (registry.TryGetType(alias, out type))
 29022            return true;
 23
 4924        var t = Type.GetType(alias);
 25
 4926        if (t == null)
 027            return false;
 28
 4929        type = t;
 4930        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) =>
 22737        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>
 11442    public static Type GetTypeOrDefault(this IWellKnownTypeRegistry registry, string alias) => registry.TryGetType(alias
 43}