I am writing code contracts on an interface that uses events:
interface EventInterface<T> {
event EventHandler ItemAdded;
bool Add(T item);
}
When an item is added to a collection that implements the interface, the collection must raise an ItemAdded
event.
The event must only be raised if the item is added;
this is given by the return value (think of a set, where true
means the item was added, false
means it wasn't added because it already existed in the set).
I wish to have a contract that ensures that if the result is true, an event will be raised. And likewise, if the result is false, no event is raised. Is there a way to check that using contracts?