< Summary - erichiller/mkmrk.Channels coverage

Information
Class: mkmrk.Channels.ValueTaskExtensions
Assembly: mkmrk.Channels
File(s): /home/runner/work/mkmrk.Channels/mkmrk.Channels/src/mkmrk.Channels/Common.cs
Tag: 161_8859726157
Line coverage
0%
Covered lines: 0
Uncovered lines: 12
Coverable lines: 12
Total lines: 82
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
WhenAll()0%60%

File(s)

/home/runner/work/mkmrk.Channels/mkmrk.Channels/src/mkmrk.Channels/Common.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Diagnostics.CodeAnalysis;
 4using System.Linq;
 5using System.Threading.Tasks;
 6
 7namespace mkmrk.Channels;
 8
 9/// <summary>
 10/// Extensions for <see cref="IEnumerable{T}"/> and similar, mostly for <see cref="System.Linq"/> type applications
 11/// </summary>
 12internal static class Extensions {
 13    /// <summary>
 14    /// Display a more concise Generic Type representation
 15    /// </summary>
 16    public static string GenericTypeShortDescriptor( this Type type, bool useShortGenericName = true ) =>
 17        type switch {
 18            null                      => throw new ArgumentNullException( nameof(type) ),
 19            _ when type.IsGenericType => $"{type.Name.Split( '`' ).First()}<{type.GenericTypeArguments.Select( t => Gene
 20            _                         => type.Name
 21        };
 22
 23
 24    /// <summary>
 25    /// Create <paramref name="joinString"/> separated string of elements
 26    /// </summary>
 27    [ return: NotNullIfNotNull( "list" ) ]
 28    private static string? toXSeparatedString( this System.Collections.IEnumerable? list, int? maxElementsToPrint, strin
 29        if ( list is null ) {
 30            return null;
 31        }
 32        List<string> strList = new ();
 33        int          i       = 0;
 34        foreach ( var x in list ) {
 35            strList.Add( x?.ToString() ?? "null" );
 36            if ( maxElementsToPrint is { } && ++i == maxElementsToPrint ) {
 37                strList.Add( "..." );
 38            }
 39        }
 40        return String.Join( joinString, strList );
 41    }
 42
 43    /// <summary>
 44    /// Create comma separated string of elements
 45    /// </summary>
 46    /// <returns>
 47    /// eg. <c>element1, element2, element3</c>
 48    /// </returns>
 49    [ return: NotNullIfNotNull( "list" ) ]
 50    internal static string? ToCommaSeparatedString( this System.Collections.IEnumerable? list, int? maxElementsToPrint =
 51        => toXSeparatedString( list, maxElementsToPrint, joinString );
 52}
 53
 54/// <summary>
 55/// Augmentations for <see cref="System.Threading.Tasks.ValueTask"/>
 56/// </summary>
 57internal static class ValueTaskExtensions {
 58    /// <summary>
 59    ///
 60    /// </summary>
 61    /// <remarks>This runs faster than using <c>Task.WhenAll( ...Select( ...AsTask ) )</c></remarks>
 62    [ SuppressMessage( "Design", "CA1031:Do not catch general exception types", Justification = "Required in order to co
 63    [ SuppressMessage( "Maintainability", "CA1508:Avoid dead conditional code" ) ]
 064    internal static async ValueTask WhenAll( this ValueTask[] tasks ) {
 65        // We don't allocate the list if no task throws
 066        List<Exception>? exceptions = null;
 67
 068        for ( var i = 0 ; i < tasks.Length ; i++ )
 069            try {
 070                await tasks[ i ].ConfigureAwait( false );
 71                // } catch ( TaskCanceledException ) {
 72                //     // TODO: is this correct?
 73                //     return;
 074            } catch ( Exception ex ) {
 075                exceptions ??= new List<Exception>( tasks.Length );
 076                exceptions.Add( ex );
 077            }
 078        if ( exceptions is not null ) {
 079            throw new AggregateException( exceptions );
 80        }
 081    }
 82}

Methods/Properties

WhenAll()