Project Description
Extension methods that allow for something that approximates to duck typing in C#. While certainly not as syntactically clean as Ruby, using this library allows the user to not have to write the same reflection code over and over again when duck typing is desired.

This project is released under the MIT license.

There are currently two primary means of duck typing. One of which is to use DuckCall directly, which allows you to pass a string and a set of parameters as an array of objects to perform a duck call.

A second method uses a dynamic proxy to allow you to use the object with an already existing interface at runtime, allowing you to make calls to that object "as if" it supported that interface, via the As<T> method. Usage:

interface IEggable { string LayEgg(); }
class Platypus { public string LayEgg { return "egg"; } } //notice it does not implement IEggable

//we don't know for sure if a platypus can lay eggs, since we are dealing with it as an object, but we can try
object someObjectThatMightLayEggs = new Platypus();
var eggLayingPlatypus = someObjectThatMightLayEggs.As<IEggable>();
Assert.IsTrue(eggLayingPlatypus.LayEgg() == "egg");

The intent isn't to re-create Ruby style duck typing or anything like that, but really, to help people not have to re-write the same reflection calls over and over again when this type of functionality is needed.
Last edited Jul 1 2008 at 8:49 PM by ericksoa, version 5

 

Want to leave feedback?
Please use Discussions or Reviews instead.

Updating...
© 2006-2009 Microsoft | About CodePlex | Privacy Statement | Terms of Use | Code of Conduct | Advertise With Us | Version 2009.10.27.15987