Preconditions C# with Example



Preconditions C# with Example

namespace CodeContractsDemo 
{ 
using System; 
using System.Collections.Generic; 
using System.Diagnostics.Contracts; 
public class PaymentProcessor 
{ 
private List _payments = new List(); 
public void Add(Payment payment) 
 

{ 
Contract.Requires(payment != null); 
Contract.Requires(!string.IsNullOrEmpty(payment.Name)); 
Contract.Requires(payment.Date <= DateTime.Now); 
Contract.Requires(payment.Amount > 0); 
this._payments.Add(payment); 
} 
} 
} 
 

Assertions 

0 Comment's

Comment Form