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

TestContext.cs « Xamarin.PropertyEditing.Tests - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b7ede7e242983c16678cc8ee94beb6eaeda052e5 (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
using System;
using System.Collections.Generic;
using System.Runtime.ExceptionServices;
using System.Threading;

namespace Xamarin.PropertyEditing.Tests
{
	internal class TestContext
		: SynchronizationContext
	{
		public override void Post (SendOrPostCallback d, object state)
		{
			try {
				d (state);
			} catch (Exception ex) {
				var info = ExceptionDispatchInfo.Capture (ex);
				this.exceptions.Add (info);
				throw;
			}
		}

		public override void Send (SendOrPostCallback d, object state)
		{
			try {
				d (state);
			} catch (Exception ex) {
				var info = ExceptionDispatchInfo.Capture (ex);
				this.exceptions.Add (info);
				throw;
			}
		}

		public void ThrowPendingExceptions ()
		{
			if (this.exceptions.Count > 0)
				this.exceptions[0].Throw();
		}

		private readonly List<ExceptionDispatchInfo> exceptions = new List<ExceptionDispatchInfo> ();
	}
}