The code is below. It gives an "ensures unproven" in the Add method.
Some notes about the code:
+ Some methods are implemented yet, but this makes no difference.
+ the mBackend field is readonly and assigned in constructor, so technically the Invariant shouldnt even be neccessary, but that's a different story...
Code:
public class WrappedCollection<T>: ICollection<T> {
private readonly ICollection<T> mBackend = new List<T>();
[ContractInvariantMethod]
private void Invariant() {
ICollection<T> @this = this;
Contract.Invariant(mBackend != null);
}
void ICollection<T>.Add(T item) {
mBackend.Add(item);
}
void ICollection<T>.Clear() {
throw new NotImplementedException();
}
bool ICollection<T>.Contains(T item) {
throw new NotImplementedException();
}
void ICollection<T>.CopyTo(T[] array, int arrayIndex) {
throw new NotImplementedException();
}
int ICollection<T>.Count {
get {
return mBackend.Count;
}
}
bool ICollection<T>.IsReadOnly {
get {
return false;
}
}
bool ICollection<T>.Remove(T item) {
return mBackend.Remove(item);
}
IEnumerator<T> IEnumerable<T>.GetEnumerator() {
return mBackend.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
return mBackend.GetEnumerator();
}
}