| | | 1 | | //======================================================================= |
| | | 2 | | // CollisionNotificationExceptions.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2026–present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using SwiftCollections; |
| | | 9 | | using System; |
| | | 10 | | using System.Runtime.CompilerServices; |
| | | 11 | | using System.Runtime.ExceptionServices; |
| | | 12 | | |
| | | 13 | | namespace Gravitas.CollisionHandling; |
| | | 14 | | |
| | | 15 | | internal static class CollisionNotificationExceptions |
| | | 16 | | { |
| | | 17 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 18 | | internal static void Capture(ref SwiftList<Exception>? exceptions, Exception exception) => |
| | 20 | 19 | | (exceptions ??= new SwiftList<Exception>(2)).Add(exception); |
| | | 20 | | |
| | | 21 | | [MethodImpl(MethodImplOptions.NoInlining)] |
| | | 22 | | internal static void ThrowIfAny(SwiftList<Exception>? exceptions) |
| | | 23 | | { |
| | 5784 | 24 | | if (exceptions == null) |
| | 5767 | 25 | | return; |
| | | 26 | | |
| | 17 | 27 | | if (exceptions.Count == 1) |
| | 14 | 28 | | ExceptionDispatchInfo.Capture(exceptions[0]).Throw(); |
| | | 29 | | |
| | 3 | 30 | | throw new AggregateException(exceptions); |
| | | 31 | | } |
| | | 32 | | } |