View difference between Paste ID: iHkZ5Qez and 1UXXvxW8
SHOW: | | - or go back to the newest paste.
1-
   public async Task<LifeTime> Life(Person me)
1+
   public async Task<LifeTime> Life(Person me)
2-
        {
2+
        {
3-
            while (me.alive)
3+
            while (me.alive)
4-
            {
4+
            {
5-
                try
5+
                try
6-
                {
6+
                {
7-
                    //
7+
                    //
8-
                    //...
8+
                    //...
9-
                    //
9+
                    //
10-
                }
10+
                }
11-
                catch (Exception x)
11+
                catch (Exception x)
12-
                {
12+
                {
13-
                 
13+
                 
14-
                    bool result= await me.DoSomeWork(()=>Shop.Buy(Goods.Vodka, me)); //await in catch - c# 6
14+
                    bool result= await me.DoSomeWork(()=>Shop.Buy(Goods.Vodka, me)); //await in catch - c# 6
15-
                    if (result)
15+
                    if (result)
16-
                    {
16+
                    {
17-
                        me.Use(await me.GetItem(Goods.Vodka));
17+
                        me.Use(await me.GetItem(Goods.Vodka));
18-
                        //
18+
                        //
19-
                        //...
19+
                        //...
20-
                        //
20+
                        //
21-
                    }
21+
                    }
22-
                    else
22+
                    else
23-
                    {
23+
                    {
24-
                        Debug.WriteLine("life sucks");
24+
                        Debug.WriteLine("life sucks");
25-
                    }
25+
                    }
26-
                }
26+
                }
27-
27+
28-
            }
28+
            }
29-
            return new LifeTime(me);
29+
            return new LifeTime(me);
30-
        }
30+
        }
31
    }
32-
    public class LifeTime
32+
    public class LifeTime
33-
    {
33+
    {
34-
        public LifeTime(Person me)
34+
        public LifeTime(Person me)
35-
        {
35+
        {
36-
            //
36+
            //
37-
            //...
37+
            //...
38-
            //
38+
            //
39-
        }
39+
        }
40
    }
41-
    public  class Person
41+
    public  class Person
42-
    {
42+
    {
43-
        public void Use(Item i)
43+
        public void Use(Item i)
44-
        {
44+
        {
45-
            //
45+
            //
46-
            //...
46+
            //...
47-
            //
47+
            //
48-
        }
48+
        }
49-
        public async Task<bool> DoSomeWork(Func<Task<bool>> work)
49+
        public async Task<bool> DoSomeWork(Func<Task<bool>> work)
50-
        {
50+
        {
51-
           return await AsyncInfo.Run(c => work());
51+
           return await AsyncInfo.Run(c => work());
52-
        }
52+
        }
53-
        public async Task<Item> GetItem(Goods item)
53+
        public async Task<Item> GetItem(Goods item)
54-
        {
54+
        {
55-
            return Things[item];
55+
            return Things[item];
56-
        }
56+
        }
57-
        public bool alive { get; private set; }
57+
        public bool alive { get; private set; }
58-
        public Dictionary<Goods, Item> Things = new Dictionary<Goods, Item>();
58+
        public Dictionary<Goods, Item> Things = new Dictionary<Goods, Item>();
59-
59+
60
    }
61-
    public static class Shop
61+
    public static class Shop
62-
    {
62+
    {
63-
        public static async Task<bool> Buy(Goods vodka, Person me)
63+
        public static async Task<bool> Buy(Goods vodka, Person me)
64-
        {
64+
        {
65-
            //
65+
            //
66-
            //...
66+
            //...
67-
            //
67+
            //
68-
            return true;
68+
            return true;
69-
        }
69+
        }
70
    }
71-
    public enum Goods
71+
    public enum Goods
72-
    {
72+
    {
73-
        Vodka
73+
        Vodka
74
    }
75-
    public class Item
75+
    public class Item
76-
    {
76+
    {
77-
77+
78
    }
79-
    public class Vodka : Item
79+
    public class Vodka : Item
80-
    {
80+
    {
81-
81+
82
    }