Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. class Foo
  2. {
  3. private static readonly Foo instance = new Foo();
  4. private readonly string bar;
  5.  
  6. public static Foo Instance
  7. // workaround for not being able to put invariants on static fields
  8. {
  9. get
  10. {
  11. Contract.Ensures(Contract.Result<Foo>() != null);
  12. Contract.Ensures(Contract.Result<Foo>().bar != null);
  13.  
  14. Contract.Assume(instance.bar != null);
  15. return instance;
  16. }
  17. }
  18.  
  19. public Foo()
  20. {
  21. Contract.Ensures(bar != null);
  22. bar = "Hello world!";
  23. }
  24.  
  25. public static int BarLength()
  26. {
  27. Contract.Assert(Instance != null);
  28. Contract.Assert(Instance.bar != null);
  29. // both of these are proven ok
  30.  
  31. return Instance.bar.Length;
  32. }
  33. }
  34.  
  35. private static Foo instance = new Foo();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement