Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics.Contracts;
- namespace ContractsExample
- {
- public class SimpleModel
- {
- public ShouldNotBeNull TestData { get; set; }
- public SimpleModel()
- {
- TestData = new ShouldNotBeNull {SomeData = 0};
- }
- public void SomePerformances()
- {
- Contract.Requires<ArgumentNullException>(TestData != null);
- Contract.Requires<ArgumentOutOfRangeException>(TestData.SomeData == 0);
- Contract.Ensures(TestData.SomeData < 10);
- Console.WriteLine($"Number {TestData.SomeData}.");
- loopInvariantExample();
- }
- private void loopInvariantExample()
- {
- for (int i = 0; i < 30; i++)
- {
- TestData.SomeData++;
- }
- }
- [ContractInvariantMethod]
- private void invariantValidation()
- {
- Contract.Invariant(TestData.SomeData < 10);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement