# C\#: IfItQuacks turns duck typing into a library

Canonical source : [C\#: IfItQuacks turns duck typing into a library](<https://sebastien.rigaux.be/en/tech-watch/links/c-ifitquacks-turns-duck-typing-into-a-library>)

IfItQuacks lets C# code accept objects that match an interface without implementing it or sharing a base class. The `[DuckTyped]` attribute invokes a source generator that checks compatibility at compile time and creates an adapter—without reflection or `dynamic`.

Anonymous types can also act as test stubs: an object such as `{ Name = "Steven", Age = 90 }` can satisfy an `IPerson` interface. Adapters also preserve identity by forwarding `Equals`, `GetHashCode`, and `ToString` to the wrapped instance.

- Selected on : 2026-11-01

- Resource publication : 2026-09-18

- Entry updated : 2026-11-07T20:32:37+0000

- Format : Tool

- Source language : EN

- Credit : Steven Giesel

- Found via : [C\# Digest](<https://csharpdigest.net/>)

Original resource : [C\#: IfItQuacks turns duck typing into a library](<https://steven-giesel.com/blogPost/41599817-4457-441e-b874-1a5c67f4e7cc>)

Tags : [C\#](<https://sebastien.rigaux.be/en/tech-watch/tags/c-sharp>) · [.NET](<https://sebastien.rigaux.be/en/tech-watch/tags/dotnet>)

Available versions : [Français](<https://sebastien.rigaux.be/veille/liens/c-ifitquacks-transforme-le-duck-typing-en-bibliotheque>) · [English](<https://sebastien.rigaux.be/en/tech-watch/links/c-ifitquacks-turns-duck-typing-into-a-library>)

[Back to tech watch](<https://sebastien.rigaux.be/en/tech-watch>)
