views:

197

answers:

4

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.

+3  A: 

You might consider using a DLR based language like Python in silverlight

AnthonyWJones
+2  A: 

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,

JustinAngel
Thanks Justin, I was refering to automatic implementation of interfaces. I just didn't realize that "mocking" was the keyword - tried to google "duck typing + silverlight" without much luck.
Karol Kolenda
+2  A: 

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();
Marc Gravell
From the 2010 preview thus far, you will certainly be able to do this type of duck typing. Unfortunately, you cannot make an object implement an interface that it doesn't already implement... even if it meets the contract of the interface. In other words, the code that uses the duck must depend upon dynamic, instead of IQuacker. I am hoping that they include this capability in the RTM ofr 4.0 (And SL 4.0), because it would be killer for abstracting out framework classes.
Brian Genisio
AFAIK there is no plan to implement what you describe.
Marc Gravell
+1  A: 

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?

Brian Genisio
Thanks Brian, I'll take a closer look at your solution.
Karol Kolenda