I can have a nested contracts type for a non-generic interface:
[ContractClass(typeof(Foo.FooContracts))]
public interface IFoo
{
string Bar(object obj);
}
But it complains when I try to do the same thing with a generic interface:
[ContractClass(typeof(Foo.FooContracts<>))]
public interface IFoo<T>
{
string Bar(T obj);
}
The warning is:
The contract class
Foo+FooContracts`1
and the typeIFoo`1
must have the same declaring type if any.
It compiles without a warning if I get FooContracts
out of the Foo
class.
- Why does that limitation exist for generic interfaces?
- Why doesn't that limitation exist for non-generic ones?
FooContracts
within a genericFoo<T>
class, and set everything up as above. In addition to the message you've shown, this also now generates "The contract class 'Foo1+FooContracts' and the type 'IFoo
1' must agree on all generic parameters." I'm wondering if this is the start of a quagmire that they're trying to avoid by having the rule you've found.