Sébastien Rigaux

C#: IfItQuacks turns duck typing into a library

ToolC#.NET
View resource

steven-giesel.com

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.

Yellow “Buy me a coffee” graphic with a stylized cup.