Beispiel #1
0
        public void CanAdd()
        {
            var f1 = new AsyncTryFrame(
                TryFrameType.Action,
                _ => Task.FromResult(new object()),
                null);

            var f2 = new AsyncTryFrame(
                TryFrameType.CatchClause,
                null,
                new AsyncCatchClause(
                    async _ => 9,
                    typeof(ArithmeticException)));

            var frames = new[]
            {
                f1,
            };

            var x = new AsyncTryFrames(frames);
            var y = x.Add(f2);

            Assert.AreEqual(1, x.Length);
            Assert.AreEqual(2, y.Length);

            Assert.AreSame(f1, x[0]);
            Assert.AreSame(f1, y[0]);
            Assert.AreSame(f2, y[1]);
        }
Beispiel #2
0
        public AsyncTryFrames Add(AsyncTryFrame frame)
        {
            var clausesLength = Frames.Length;

            var arr = new AsyncTryFrame[clausesLength + 1];

            Array.Copy(Frames, arr, clausesLength);
            arr[clausesLength] = frame;

            return(new AsyncTryFrames(arr));
        }
Beispiel #3
0
        public void CanCreate()
        {
            var type = TryFrameType.CatchClause;
            Func <object, Task <object> > action = async o => o;
            var clause = new AsyncCatchClause(async exception => 9, typeof(ArithmeticException));

            var x = new AsyncTryFrame(type, action, clause);

            Assert.AreEqual(type, x.FrameType);
            Assert.AreSame(action, x.Action);
            Assert.AreSame(clause, x.CatchClause);
        }
Beispiel #4
0
        public AsyncTryFrames ToAsync()
        {
            var framesLength = Frames.Length;
            var frames       = new AsyncTryFrame[framesLength];

            for (int i = 0; i < framesLength; i++)
            {
                var cur = (SyncTryFrame)Frames[i];

                if (cur.FrameType == TryFrameType.Action)
                {
                    frames[i] = new AsyncTryFrame(cur.FrameType, async x => cur.Action(x), null);
                }
                else
                {
                    frames[i] = new AsyncTryFrame(TryFrameType.CatchClause, null, cur.CatchClause.ToAsync());
                }
            }

            return(new AsyncTryFrames(frames));
        }