Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. public sealed class Room
  2. {
  3. private readonly Func<Room> north;
  4.  
  5. public Room(Func<Room> north)
  6. {
  7. this.north = north;
  8. }
  9.  
  10. public Room North
  11. {
  12. get
  13. {
  14. return this.north();
  15. }
  16. }
  17.  
  18. public static void Main(string[] args)
  19. {
  20. Func<Room> evilDelegate = () => { throw new Exception(); };
  21.  
  22. var kitchen = new Room(north: evilDelegate);
  23.  
  24. var room = kitchen.North; //<----this will throw
  25.  
  26. }
  27. }
  28.  
  29. public sealed class Room
  30. {
  31. private readonly Func<Room> north;
  32.  
  33. private Room(Func<Room> north)
  34. {
  35. this.north = north;
  36. }
  37.  
  38. public Room North
  39. {
  40. get
  41. {
  42. return this.north();
  43. }
  44. }
  45.  
  46. public static Room Create(Func<Room> north)
  47. {
  48. try
  49. {
  50. north?.Invoke();
  51. }
  52. catch (Exception e)
  53. {
  54. throw new Exception(
  55. message: "Initialized with an evil delegate!", innerException: e);
  56. }
  57.  
  58. return new Room(north);
  59. }
  60.  
  61. public static void Main(string[] args)
  62. {
  63. Func<Room> evilDelegate = () => { throw new Exception(); };
  64.  
  65. var kitchen = Room.Create(north: evilDelegate); //<----this will throw
  66.  
  67. var room = kitchen.North;
  68. }
  69. }
  70.  
  71. {
  72. var ignoreThis = func(arg);
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement