Advertisement
Guest User

Untitled

a guest
May 24th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. using System;
  2.  
  3. namespace TestAllTheThings
  4. {
  5. public class ConfigurePattern
  6. {
  7. public void Configure(Action<SomeOptions> configureOptions)
  8. {
  9. var opts = new SomeOptions();
  10. opts.Fixed = true; // set a default
  11. configureOptions(opts);
  12. // do validation or additional steps
  13. }
  14. }
  15.  
  16. public class SomeOptions
  17. {
  18. public bool Fixed { get; set; }
  19. public string NameThing { get; set; }
  20. public bool AnotherSwitch { get; set; }
  21. }
  22.  
  23. public class Demo
  24. {
  25. public void Run()
  26. {
  27. var optionsPat = new ConfigurePattern();
  28.  
  29. optionsPat.Configure(options =>
  30. {
  31. options.NameThing = "aasdasd";
  32. options.AnotherSwitch = true;
  33. });
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement