< Summary

Information
Class: Elsa.Workflows.Helpers.ActivityTypeNameHelper
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Helpers/ActivityTypeNameHelper.cs
Line coverage
93%
Covered lines: 15
Uncovered lines: 1
Coverable lines: 16
Total lines: 48
Line coverage: 93.7%
Branch coverage
90%
Covered branches: 18
Total branches: 20
Branch coverage: 90%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GenerateNamespace(...)100%44100%
GenerateTypeName(...)100%1212100%
GenerateTypeName()100%11100%
GenerateTypeName(...)100%11100%
GetCategoryFromNamespace(...)50%4475%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Helpers/ActivityTypeNameHelper.cs

#LineLine coverage
 1using System.Reflection;
 2using Elsa.Workflows.Attributes;
 3
 4namespace Elsa.Workflows.Helpers;
 5
 6public static class ActivityTypeNameHelper
 7{
 8    public static string? GenerateNamespace(Type activityType)
 9    {
 3830310        var activityAttr = activityType.GetCustomAttribute<ActivityAttribute>();
 3830311        return activityAttr?.Namespace ?? activityType.Namespace;
 12    }
 13
 14    public static string GenerateTypeName(Type type, string? ns)
 15    {
 3781316        var activityAttr = type.GetCustomAttribute<ActivityAttribute>();
 17        string typeName;
 18
 3781319        if (type.IsGenericType)
 20        {
 14921            var sanitizedTypeName = activityAttr?.Type ?? type.Name.Substring(0, type.Name.IndexOf("`", StringComparison
 29822            var genericArgs = type.GenericTypeArguments.Select(type1 => GenerateTypeName(type1, null));
 14923            typeName = $"{sanitizedTypeName}<{string.Join(',', genericArgs)}>";
 24        }
 25        else
 3766426            typeName = activityAttr?.Type ?? type.Name;
 27
 3781328        return ns != null ? $"{ns}.{typeName}" : typeName;
 29    }
 30
 579231    public static string GenerateTypeName<T>() where T : IActivity => GenerateTypeName(typeof(T));
 32
 33    public static string GenerateTypeName(Type type)
 34    {
 3766435        var ns = GenerateNamespace(type);
 3766436        return GenerateTypeName(type, ns);
 37    }
 38
 39    public static string? GetCategoryFromNamespace(string? ns)
 40    {
 63941        if (string.IsNullOrWhiteSpace(ns))
 042            return null;
 43
 63944        var index = ns.LastIndexOf('.');
 45
 63946        return index < 0 ? ns : ns[(index + 1)..];
 47    }
 48}