The Weekly Source Code 1
Sponsored By
In my new ongoing quest to read source code to be a better developer, I now present the first in an infinite number of a weekly series called "The Weekly Source Code." Here's some source I'm reading this week that I enjoyed.
- PowerShell Drive Provider for Amazon S3 (Simple Storage Service) - C# Source that interfaces Amazon's S3 to PowerShell so you can "dir" your S3 area.
- AForge.NET by Andrew Kirillov - I used Andrew's very powerful AForge library in my Coding4Fun Article on a Motion Detecting Baby Webcam. His amazing source is up on Google Code as a project now. A gold mine of image processing and neuro network computation. When I can read this and understand it, I will be smarter.
- DotNetOpenId - The C# port of the JanRain OpenID library, originally written in Boo, that caused me to go through the Programmer Phases of Grief, is up on Google Code and championed by a team smarther-than-I that's extended it. Headed by Jason Alexander and ScottWater, with a member list of excellent programmers and .NET literati. I haven't been very involved since the inception (life happens) but Jason and team have taken it far beyond my skills. It's fun to return and see how much more awesome some source has become without me.
- C# Duck Typing by David Meyer - I'm still trying to get my head around this one. It's a .NET class library written in C# that enables duck typing. I'm trying to understand where this project fits in the world of C# 3.0 "var" style declarations, as well as within the context of the DLR.
Feel free to send me links to cool source that you find hasn't been given a good read.
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
About Newsletter
The Duck Typing project is pretty interesting, but doesn't have much to do with the Var type of situation. What he's doing is a very clever bit of reflection.
He's dynamically creating a type at runtime that wraps the original type using reflection. It basically dynamically creates a proxy to the target type. So, for example, you could DuckType a control of type DropDownList as a control of type RadioButtonList as long as you access properties that are of the same type. So, you could do something like the following:
RadioButtonList rblDuck = DuckTyping.Cast<RadioButtonList>(myDropDownList);
rbl.SelectedValue = "Example";
Both RadioButtonLists and DropDownLists have "SelectedValue" in common, so the RadioButtonList "ducktype" acts as a proxy to the actual underlying DropDownList, forwarding the values on to myDropDownList. Neat stuff.
This is all at runtime, though. Var is different because it is a type that is determined at compile time. It's possible that Microsoft's DLR strategy is similar, but I'm not sure about that yet.
He's dynamically creating a type at runtime that wraps the original type using reflection. It basically dynamically creates a proxy to the target type. So, for example, you could DuckType a control of type DropDownList as a control of type RadioButtonList as long as you access properties that are of the same type. So, you could do something like the following:
RadioButtonList rblDuck = DuckTyping.Cast<RadioButtonList>(myDropDownList);
rbl.SelectedValue = "Example";
Both RadioButtonLists and DropDownLists have "SelectedValue" in common, so the RadioButtonList "ducktype" acts as a proxy to the actual underlying DropDownList, forwarding the values on to myDropDownList. Neat stuff.
This is all at runtime, though. Var is different because it is a type that is determined at compile time. It's possible that Microsoft's DLR strategy is similar, but I'm not sure about that yet.
Comments are closed.
Anyway, here's my contribution:
RSS feed of the Firebug source code:
http://feedchopper.ning.com/index.php/main/feed/showUrl?id=3299679
RSS feed of the Haskell Prelude:
http://feedchopper.ning.com/index.php/main/feed/showUrl?id=6633928