Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ExceptionServices.cs « Internal « Reactive « System.Reactive.Core « Rx.NET - github.com/mono/rx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1fceebad86f5ffd1a3feb003d6096f4dc81ba721 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.

using System.ComponentModel;
using System.Reactive.PlatformServices;

namespace System.Reactive
{
    internal static class ExceptionHelpers
    {
        private static Lazy<IExceptionServices> s_services = new Lazy<IExceptionServices>(Initialize);

        public static void Throw(this Exception exception)
        {
            s_services.Value.Rethrow(exception);
        }

        public static void ThrowIfNotNull(this Exception exception)
        {
            if (exception != null)
                s_services.Value.Rethrow(exception);
        }

        private static IExceptionServices Initialize()
        {
            return PlatformEnlightenmentProvider.Current.GetService<IExceptionServices>() ?? new DefaultExceptionServices();
        }
    }
}

namespace System.Reactive.PlatformServices
{
    /// <summary>
    /// (Infrastructure) Services to rethrow exceptions.
    /// </summary>
    /// <remarks>
    /// This type is used by the Rx infrastructure and not meant for public consumption or implementation.
    /// No guarantees are made about forward compatibility of the type's functionality and its usage.
    /// </remarks>
    [EditorBrowsable(EditorBrowsableState.Never)]
    public interface IExceptionServices
    {
        /// <summary>
        /// Rethrows the specified exception.
        /// </summary>
        /// <param name="exception">Exception to rethrow.</param>
        void Rethrow(Exception exception);
    }
}