The ultimate goal is to specify contracts for a class that is in an external assembly with which I do not control (i.e. I can’t just add contracts to this class directly).
What I have tried so far:
ContractClassFor.
It does not work because the target class must point to the class of the contract.
Manually create a reference assembly (eg. MyAsm.Contracts.dll) by reverse engineering the auto-generated ones. It doesn’t work, because immediately after compiling it, the rewriter writes and removes the attribute ContractDeclarativeAssembly, which makes the assembly unrecognizable by the tools as “assembly of contract references”. And I cannot find a way to disable rewriting.
Create a “fake” assembly with the same name, version, strong name (if any) and other attributes as the target assembly, and put the classes with the same names with the same names. Then compile this assembly with the "build contract reference" option enabled, then take the created reference assembly and use it.
For some reason, this did not work either, although I have no idea what the reason is. The static controller simply ignores my link assembly created by smartypants as if it weren't there.
And one more thing: just in case, it is important: the target assembly is compiled for .NET 2.0, and I can not recompile it for 4.0.
Update
Writing a wrapper library with certain contracts is out of the question.
-, . , : () - "", "" . . , , , , . ? , , Cast<T>() , / . , , , , .
, CC: mscorlib, System.Core , ? ? , , .
, , , : , .:-) - Fyodor Soikin 18