Do you know any duck typing library for Silverlight? There are a few for full-blown .Net framework but I'm looking for something lighter.
You might consider using a DLR based language like Python in silverlight
By asking for "Silverlight Duck typing" are you refering to the strongly-typed automatic implementation of interfaces? or the dynamic creation of object metadata through using an object instance?
If it's the letter, Anthony's recommandation is spot on.
Strongly-typed languages that run on the CLR (C# and VB.Net) cannot support true dynamic duck typing.
Thus, you can use IronRuby or IronPython that ship as part of the Silverlight DLR project.
If you're looking for the former, than you're essiantially looking for a mocking library. Silverlight supports a myriad of open source mocking frameworks.
Moq - http://code.google.com/p/moq/ (download: http://moq.googlecode.com/files/Moq.Silverlight.4.0.812.4-bin.zip)
RhinoMocks - http://ayende.com/projects/rhino-mocks.aspx (download: http://ayende.com/20/section.aspx/download/230)
AutoFac - http://code.google.com/p/autofac/ (download: http://autofac.googlecode.com/files/Autofac-1.4.4.572-SL3.zip)
TypeMock / SilverUnit - http://cthru.codeplex.com (download: http://cthru.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=27748#DownloadId=69201)
Sincerely,
Depending on your interpretation of duck-typing, I would hope that this arrives in C# 4.0 and dynamic
, when that becomes available on Silverlight. Then you can pick-and-choose which bits are duck-typed (dynamic
) vs static-typed (everything else). All within C#.
dynamic duck = /* pretty much anything */
duck.Quack();
I recently created a utility I call "DynamicWrapper". It uses Reflection.Emit to generate a wrapper class on the fly that implements the interface -- a way to achieve duck typing in C#.
Unfortunately, it doesn't work in Silverlight. It works really well in .Net 3.5 and my tests passed in my SL environment, but in the SL runtime, I get a security exception.
I haven't had any time to figure it out, but the code is pretty straight forward. Maybe this code can point you in the right direction?