| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Diagnostics; |
| | 4 | | using System.Diagnostics.CodeAnalysis; |
| | 5 | | using System.Threading.Channels; |
| | 6 | |
|
| | 7 | | namespace mkmrk.Channels; |
| | 8 | |
|
| | 9 | | /// <summary> |
| | 10 | | /// <see cref="Channel"/> is not closed, mutate actions not available. |
| | 11 | | /// </summary> |
| | 12 | | [ SuppressMessage( "Design", "CA1032:Implement standard exception constructors" ) ] |
| | 13 | | public sealed class ChannelNotClosedException : Exception { |
| | 14 | | /// <inheritdoc cref="ChannelNotClosedException" /> |
| 2 | 15 | | private ChannelNotClosedException( Exception? innerException ) : base( "Channel is not closed, mutate actions not av |
| | 16 | |
|
| | 17 | | /// <inheritdoc cref="ChannelNotClosedException" /> |
| | 18 | | [ DoesNotReturn ] |
| | 19 | | [ StackTraceHidden ] |
| 0 | 20 | | public static void Throw( Exception? innerException = null, IDictionary? data = null ) { |
| 0 | 21 | | var exception = new ChannelNotClosedException( innerException ); |
| 0 | 22 | | if ( data is { } ) { |
| 0 | 23 | | foreach ( var key in data.Keys ) { |
| 0 | 24 | | exception.Data.Add( key, data[ key ] ); |
| 0 | 25 | | } |
| 0 | 26 | | } |
| 0 | 27 | | throw exception; |
| | 28 | | } |
| | 29 | |
|
| | 30 | | /// <inheritdoc cref="ChannelNotClosedException" /> |
| | 31 | | [ DoesNotReturn ] |
| | 32 | | [ StackTraceHidden ] |
| 2 | 33 | | public static TReturn Throw<TReturn>( Exception? innerException = null, IDictionary? data = null ) { |
| 2 | 34 | | var exception = new ChannelNotClosedException( innerException ); |
| 2 | 35 | | if ( data is { } ) { |
| 0 | 36 | | foreach ( var key in data.Keys ) { |
| 0 | 37 | | exception.Data.Add( key, data[ key ] ); |
| 0 | 38 | | } |
| 0 | 39 | | } |
| 2 | 40 | | throw exception; |
| | 41 | | } |
| | 42 | | } |