Proposal: allow anonymous types to implement interfaces #2016
Labels
Area-Language Design
Feature Request
Resolution-Duplicate
The described behavior is tracked in another issue
The most immediate benefit would be for unit testing. For a simple DTO-type interface, i.e. only containing properties, I would like to type something like:
or
then it would save a few lines of setting up a mock or creating a test class.
The anonymous type would only implement the getters of the interface's properties even if they are writable. Compilation would still fail if you try to set values on the anonymous type, and throw an exception if you try to set values using a reference to the interface.
The text was updated successfully, but these errors were encountered: