Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public sealed class Room
- {
- private readonly Func<Room> north;
- public Room(Func<Room> north)
- {
- this.north = north;
- }
- public Room North
- {
- get
- {
- return this.north();
- }
- }
- public static void Main(string[] args)
- {
- Func<Room> evilDelegate = () => { throw new Exception(); };
- var kitchen = new Room(north: evilDelegate);
- var room = kitchen.North; //<----this will throw
- }
- }
- public sealed class Room
- {
- private readonly Func<Room> north;
- private Room(Func<Room> north)
- {
- this.north = north;
- }
- public Room North
- {
- get
- {
- return this.north();
- }
- }
- public static Room Create(Func<Room> north)
- {
- try
- {
- north?.Invoke();
- }
- catch (Exception e)
- {
- throw new Exception(
- message: "Initialized with an evil delegate!", innerException: e);
- }
- return new Room(north);
- }
- public static void Main(string[] args)
- {
- Func<Room> evilDelegate = () => { throw new Exception(); };
- var kitchen = Room.Create(north: evilDelegate); //<----this will throw
- var room = kitchen.North;
- }
- }
- {
- var ignoreThis = func(arg);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement