< Summary - SonghayCore

Information
Class: Songhay.ProgramAssemblyUtility
Assembly: SonghayCore
File(s): /home/rasx/sourceRoot/SonghayCore/SonghayCore/ProgramAssemblyUtility.cs
Line coverage
100%
Covered lines: 27
Uncovered lines: 0
Coverable lines: 27
Total lines: 80
Line coverage: 100%
Branch coverage
66%
Covered branches: 4
Total branches: 6
Branch coverage: 66.6%
Method coverage

Method coverage is only available for sponsors.

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
GetAssemblyInfo(...)100%1100%
GetAssemblyInfo(...)50%2100%
GetPathFromAssembly(...)100%1100%
GetPathFromAssembly(...)75%4100%

File(s)

/home/rasx/sourceRoot/SonghayCore/SonghayCore/ProgramAssemblyUtility.cs

#LineLine coverage
 1namespace Songhay;
 2
 3/// <summary>
 4/// Static members related to <see cref="System.Reflection"/>.
 5/// </summary>
 6public static class ProgramAssemblyUtility
 7{
 8    /// <summary>
 9    /// Returns a <see cref="string"/>
 10    /// about the executing assembly.
 11    /// </summary>
 12    /// <param name="targetAssembly">
 13    /// The executing <see cref="Assembly"/>.
 14    /// </param>
 15    /// <returns>Returns <see cref="string"/></returns>
 116    public static string? GetAssemblyInfo(Assembly targetAssembly) => GetAssemblyInfo(targetAssembly, false);
 17
 18    /// <summary>
 19    /// Returns a <see cref="string"/>
 20    /// about the executing assembly.
 21    /// </summary>
 22    /// <param name="targetAssembly">
 23    /// The executing <see cref="Assembly"/>.
 24    /// </param>
 25    /// <param name="useConsoleChars">
 26    /// When <c>true</c> selected “special” characters are formatted for the Windows Console.
 27    /// </param>
 28    /// <returns>Returns <see cref="string"/></returns>
 29    public static string? GetAssemblyInfo(Assembly? targetAssembly, bool useConsoleChars)
 130    {
 131        var sb = new StringBuilder();
 32
 133        var info = new ProgramAssemblyInfo(targetAssembly);
 34
 135        sb.Append($"{info.AssemblyTitle} {info.AssemblyVersion}{Environment.NewLine}");
 136        sb.Append(info.AssemblyDescription);
 137        sb.Append(Environment.NewLine);
 138        sb.Append(info.AssemblyCopyright);
 139        sb.Append(Environment.NewLine);
 40
 141        return useConsoleChars ? ProgramUtility.GetConsoleCharacters(sb.ToString()) : sb.ToString();
 142    }
 43
 44    /// <summary>
 45    /// Gets the directory name from assembly.
 46    /// </summary>
 47    /// <param name="assembly">The assembly.</param>
 48    public static string? GetPathFromAssembly(Assembly? assembly)
 5549    {
 5550        ArgumentNullException.ThrowIfNull(assembly);
 51
 5552        var root = Path.GetDirectoryName(assembly.Location);
 53
 5554        return root;
 5555    }
 56
 57    /// <summary>
 58    /// Gets the path from assembly.
 59    /// </summary>
 60    /// <param name="assembly">The assembly.</param>
 61    /// <param name="fileSegment">The file segment.</param>
 62    public static string GetPathFromAssembly(Assembly? assembly, string? fileSegment)
 2563    {
 2564        fileSegment.ThrowWhenNullOrWhiteSpace();
 65
 2566        fileSegment = ProgramFileUtility.TrimLeadingDirectorySeparatorChars(fileSegment);
 67
 2568        if (Path.IsPathRooted(fileSegment)) throw new FormatException("The expected relative path is not here.");
 69
 2570        fileSegment = ProgramFileUtility.NormalizePath(fileSegment);
 71
 2572        var root = GetPathFromAssembly(assembly);
 2573        var levels = ProgramFileUtility.CountParentDirectoryChars(fileSegment);
 5074        if (levels > 0) root = ProgramFileUtility.GetParentDirectory(root, levels);
 75
 2576        var path = ProgramFileUtility.GetCombinedPath(root, fileSegment);
 77
 2578        return path;
 2579    }
 80}