Added
-
[DuckTyped]extension methods: the receiver is duck-typed too, soperson.Greet()works for any type fitting the interface. Previously reported withIFITQUACKS004. -
A public property or field of a delegate type satisfies an interface method of the same name, which makes an object literal a test double:
Duck.As<IRepository>(new { Find = (Func<int, Order?>)(id => ...) }). -
Duck.Stub<TShape>(value)andDuck.Stub<TShape>()return a test double that forwards the members the value provides and throwsDuckStubExceptionfor the rest. A member that is present but doesn't fit is still reported withIFITQUACKS001. -
Duck.Merge<TShape>(first, second)(and a three-value overload) builds one interface from several values, taking each member from the first value providing it - a spy or a partial fake without a mocking library. -
Sequences are adapted element by element:
IEnumerable<T>,IReadOnlyCollection<T>andIReadOnlyList<T>parameters accept aList<Person>or aPerson[]whose elements fit, andDuck.As<IReadOnlyList<INamed>>(people)keepsCountand the indexer. -
Duck.To<TTarget>(value)copies a value into a new one of a concrete type, filling the constructor and the remaining settable members from the members of the same name. DiagnosticIFITQUACKS009. -
Samples:
IfItQuacks.Sample.Extensions,IfItQuacks.Sample.Sequences,IfItQuacks.Sample.TestingandIfItQuacks.Sample.Copying.
Fixed
-
greeter?.Greet(duck)is intercepted. A conditional access used to fall through to the runtime fallback and throwDuckTypeMismatchExceptionalthough the call was right there in the project. -
base.Greet(duck)no longer silently calls the overriding method. Abasecall is not virtual, which neither an interceptor nor the fallback overload can reproduce, so it is reported with the newIFITQUACKS008. -
An argument typed as
Person?shares the adapter generated forPersoninstead of getting a second one whose generated code warned about a possible null dereference.
Changed
IFITQUACKS007is titled Duck conversion target must be an interface and names the conversion (Duck.As,Duck.StuborDuck.Merge) that was called.