Advertisement
Guest User

Untitled

a guest
May 28th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    public async Task<LifeTime> Life(Person me)
  2.         {
  3.             while (me.alive)
  4.             {
  5.                 try
  6.                 {
  7.                     //
  8.                     //...
  9.                     //
  10.                 }
  11.                 catch (Exception x)
  12.                 {
  13.                  
  14.                     bool result= await me.DoSomeWork(()=>Shop.Buy(Goods.Vodka, me)); //await in catch - c# 6
  15.                     if (result)
  16.                     {
  17.                         me.Use(await me.GetItem(Goods.Vodka));
  18.                         //
  19.                         //...
  20.                         //
  21.                     }
  22.                     else
  23.                     {
  24.                         Debug.WriteLine("life sucks");
  25.                     }
  26.                 }
  27.  
  28.             }
  29.             return new LifeTime(me);
  30.         }
  31.     }
  32.     public class LifeTime
  33.     {
  34.         public LifeTime(Person me)
  35.         {
  36.             //
  37.             //...
  38.             //
  39.         }
  40.     }
  41.     public  class Person
  42.     {
  43.         public void Use(Item i)
  44.         {
  45.             //
  46.             //...
  47.             //
  48.         }
  49.         public async Task<bool> DoSomeWork(Func<Task<bool>> work)
  50.         {
  51.            return await AsyncInfo.Run(c => work());
  52.         }
  53.         public async Task<Item> GetItem(Goods item)
  54.         {
  55.             return Things[item];
  56.         }
  57.         public bool alive { get; private set; }
  58.         public Dictionary<Goods, Item> Things = new Dictionary<Goods, Item>();
  59.  
  60.     }
  61.     public static class Shop
  62.     {
  63.         public static async Task<bool> Buy(Goods vodka, Person me)
  64.         {
  65.             //
  66.             //...
  67.             //
  68.             return true;
  69.         }
  70.     }
  71.     public enum Goods
  72.     {
  73.         Vodka
  74.     }
  75.     public class Item
  76.     {
  77.  
  78.     }
  79.     public class Vodka : Item
  80.     {
  81.  
  82.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement