So, I have a little problem here.
Suppose I have:
public class Repository<TEntity>
where TEntity : class
{
public abstract void Add(TEntity entity);
// ...and so on...
}
And now I want to define a contract class, like so:
public class RepositoryContracts<TEntity> : Repository<TEntity>
where TEntity : class
{
public void Add(TEntity entity)
{
Contract.Requires(entity != null);
}
// ...etc...
}
Now, I'd have to mark these classes with ContractClassAttribute and ContractClassForAttribute. Problem being, this won't work:
[ContractClassFor(typeof(Repository<TEntity>))] // what is TEntity?! error!
So, the question boils down to: How do I link these two classes together using those attributes, when they're generic?