Open lundmikkel opened 8 years ago
This is an interesting request. The short answer on first question: this still impossible.
But I would like to clarify what exactly you meant by 'contracts for delegates'?
Do you want to define a contract on the delegate type? Like this:
// Want to define that s is not null and result is not null?
public delegate string Foo(string s);
I assume that this sceanrio was mentioned in Code Contracts User Manual and the reason why this is complicated to have is because there is no way to express contracts (need another attirbute ContractForDelegate
?) and not clear how to enforce them at runtime (I'm not even talking about static checker).
The Code Contracts User Manual from August 14, 2013 says:
To the best of my knowledge, this still isn't possible. Are there any plans to add this?
Likewise, it would be beneficial to allow contracts on events. For instance, ensuring that a method raises an event, and that the values in the event handler are as expected.