Claudio Lassala @ Houston .NET UG on LInQ Mar 9, 2006

Fellow MVP Claudio Lassala will be speaking at the Houston .NET UG March 9th from 6:30-8:30pm, on one of my favorite topics: Language INtegrated Query (LINQ).

Class design considerations for extension methods and anonymous types

One of my readers was watching the DNRTV episode I did on LINQ recently and had this question: 

At some point, when you're explaining object initializers and anonymous types, you say something regarding extension methods, like how they could be used with the anonymous types. I'm not sure how that'd work: if the anonymous type gets named dynamically as something like "<Projection>F__4", and if the extension is declared during compile time as something like "method (this type)", how can we extend the dynamic class?

He is correct in pointing out the difficulty. These projection or anonymous types have dynamically declared names and when you declare an extension method, you must specify the type after "this" in the argument clause.

One thing that is not obvious is that the type specified after “this” in an extension method doesn't have to be the exact type, but can be an ancestor or interface implemented by the type you are ultimately wishing to extend.

public static float GetArea(this IPolygon shape){...}

As an example, the above extension method could be used as an extension method over anything that implements IPolygon.

The downside is that anonymous types (and linq projections) inherit directly from object and I don't expect that they will implement any special interfaces (the goal is too keep them simple for C# 3.0). What are you left to do? Create extension methods on "object". That is certainly a theoretical option I suppose, but that seems a little bit extreme.

To be honest though, try to think of real cases when you'd want to extend an anonymous type. If the type is truly anonymous, you know absolutely nothing about it, and what assumptions can you really make about it in an extension method? Truly, in some cases, you are going to choose to implement a named type instead of an anonymous type, and it appears that we'll see refactoring support in the tools to promote an anonymous type to a real type. This is a very likely scenario.

The reasonable cases that I can think of where anonymous types are the preference (i.e. I have no burning need to have a named type) but still need (and can) extend them, is when they are used in the context of a collection or another generic type.

For a good example of that, let's take a look at some of the extension methods provided by Linq itself.

  public static class Sequence {

    public static IEnumerable<T> Where<T>(

             this IEnumerable<T> source,

                  Func<T, bool> predicate) {

      foreach (T item in source)

        if (predicate(item))

          yield return item;

    }

  }

Consider that this is an Extension method for anything IEnumerable<T>. In this case, we're using this extension method against an IEnumerable collection of type <T> - a generic. That generic type could be an anonymous type. But the important information here is that we know something more about the anonymous type here and that is that it's used inside of an Enumerable collection, and hence we can provide the value of iterating through it in the foreach, evaluating some criteria, and yielding the items that pass the criteria into another collection.

Speaking at Chicago .NET Users Group in Downers Grove on March 15th

I'll be speaking at the Chicago .NET Users Group in Downers Grove on March 15th

Stay tuned for details....

http://www.cnug.org/Default.aspx?tabid=31

 

The Code Room: Episode 3 - Breaking into Las Vegas

It's the good guys vs. the bad guys, fighting over millions of dollars. Could this happen to you? Maybe it already has. 

http://www.thecoderoom.com/vegas/

Visual Studio Team System and Team Foundation Server Seminar across Canada

In November, 2005, Microsoft launched Visual Studio 2005, a major new release of its developer tools environment, and the foundation of Microsoft platform development for the next few years. In addition, this marked our entry into the lifecycle tools market, with the addition of Visual Studio Team System and the Team Foundation Server, to support end-to-end system development scenarios. We are bringing the tools we have been using for years internally to market to help address customers need to more rapidly develop and deliver solutions that meet the business performance, scalability and end user requirements.

Visual Studio Team System adds significant new capabilities and value to the suite of Microsoft developer tools, with advanced end-to-end role collaboration, real-time reporting and analysis, and a host of new tools covering architecture, development, and testing.


Many of you may have already transition to one of the individual role based offerings in Visual Studio Team System, but are still learning all the new tools and benefits of the offering. This session is intended to provide an introduction to Visual Studio Team System, highlight the new functionality and business value in each offering, and outline the transition steps for existing Visual Studio and MSDN customers. We will also demonstrate Visual Studio Team System in action.


This is your opportunity to attend a free education session and fast track your knowledge and use of Visual Studio Team System.

 

On-Site VSTS Event Details & Registration:

City: Mississauga
Date/Time: February 22nd 2006 -- 3:00 to 5:00pm
Location: MS Mississauga Office MPR Room
Conference ID: 1032290174
TO REGISTER for this event click here

City: Vancouver:
Date/Time: March 2nd 2006 -- 9:00 to 11:00am
Location: MS Vancouver OFC
Conference ID: 1032290176
TO REGISTER for this event click here

City: Mississauga
Date/Time: March 21st 2006 -- 1:00 to 3:00pm
Location: MS Mississauga Office MPR Room
Conference ID: 1032290177
TO REGISTER for this event click here

City: Ottawa
Date/Time: Apr 19th 2006 -- 1:00 to 3:00pm
Location: MS Ottawa Office Glacier Room
Conference ID: 1032290179
TO REGISTER for this event click here

City: Calgary
Date/Time: May 17th 2006 -- 9:00 to 11:00am
Location: MS Calgary Office Bldg (*TBC) - registrants will be notified of location
Conference ID: 1032290181
TO REGISTER for this event click here
City: Toronto

Date/Time: June 21st 2006 -- 1:00 to 3:00pm
Location: Intercontinental Hotel on Front Street (*TBC) - downtown Toronto
Conference ID: 1032290183
TO REGISTER for this event click here
*TBC – To be confirmed

Alternative Registration Options:

  • By calling 1-877-673-8368 to reserve your place, 24 hours a day, 7 days a week, and quoting the event ID.
  • Register online at www.microsoft.com/canada/events by clicking on Search Event or Event ID in the left hand column and typing in the event ID.

Scientific Study on Workstyles in Software and Interaction Design

Pedro Campos from the University of Madeira is conducing a very short survey. If you design applications and the user interactions then Pedro would be most pleased if you could spend 2-3 minutes on his short survey.

http://www.surveymonkey.com/s.asp?u=711631790575

VSLive 2006 Toronto Dates announced

Not sure this is news to most of you but VSLive is making another trip to Toronto again this year April 24-27th, 2006. It's back at the Toronto Congress Centre out by the airport again (I have mixed emotions about that one). Anyway, make sure to check it out: http://www.ftponline.com/conferences/vslive/2006/toronto/

Get Rich by Running Windows XP on a MacBook

Colin Nederkoorn is hosting a contest over at winxponmac.com to see who can get a MacBook Pro to natively dual boot into Windows XP first. The new MacBook, which is built on a 32-bit dual core Intel CPU, starts shipping February 15th, 2006 and he has his order placed. But if he can't run WinXP on it, he's going to have to send it back

Even though the new MacBook Pro is an Intel based machine, it forgoes a traditional BIOS in favour of a new EFI based hardware abstraction. While Microsoft officially supports EFI motherboards in Windows Vista and and 64-bit versions of Windows, they have stated that they will not support EFI in Windows XP 32-bit. There is hope that a BIOS compatibility mode normally included on Intel's EFI chipsets will be present on the shipping version versions of the MacBook. If not, maybe it can be retrofitted. Apple has publicly stated that they will not do anything specifically to prevent running Windows XP on their hardware so optimism is running high..

Colin has offered $100 of his own money for the contest and invited others to add to the pool which is now over $7500....wow!

Bell Mobility's latest bluetooth offering: Samsung SPH-a920

Back in August I wrote about Bell Mobility's first (and crippled) Bluetooth phone. This past week I picked up their latest phone with Bluetooth capabilities, the Samsung SPH-a920. I must say that I'm much happier with this phone so far. In particular the phone supports the OBEX profile for Object Exchange between two devices. I haven't done enough research about the software I can use to make use of this feature, but it's nice to know my phone has this support. Primarily I wanted to be able to send my pictures from the built in camera to my PC. Looks like the software in the phone will only allow me to send contacts. Calendar appointments and photos doesn't seem to have that option.

The good news for pictures is that this camera has a slot for a transflash memory card and they include a 32mb card to get you started (in addition to the 24mb internal memory) and a SD flash adapter so I can easily pop the chip out and pop it into the card reader of my computer. Problem solved.

In addition to being a 1.3 megapixel camera, there is also a camcorder mode for taking up to 30 second videos. When I get a chance I'll pop a few videos up on this blog.

Supporting a flash memory and video, you can imagine this phone probably plays mp3's too. I'm not a fan of flip phones, but the outer face has a separate display and a few buttons for navigating through your play list. The package also includes stereo headphones with a microphone. A nice touch.

Speaking of nice touches, I was pleasantly surprised to find they also include a USB data cable in the box. The unfortunate part of that cable is that it can't be used for charging the phone too. I'll have to look at 3rd party options like ziplinq for that.

In addition to OBEX, Audio Gateway and Dial Up Networking profiles are also supported. Which brings me to the next feature which is support for the EV-DO network. I haven't connected yet, but will be trying this in the next few days to see what the speeds and coverage are like. I generally have a week CDMA and 1X signal in my house, but surprisingly I can get an EV-DO signal most of the time.

All in all, my out of box experience has been pretty high with this phone. Takes the sting out of being stuck on the CDMA network.

Update (Feb 17/06): The Bell specific user guide for the Samsung SPH-a920 can be found here: http://bell.userguides.ca/guides/interactive.aspx?tab=h&device=76. It's a nice interactive guide.

Pricing for Mobile Data through your phone is available here: http://www.businessonthego1.com/english/wp_datapricing_cards.asp. You should call 1.877.DATA.123 (1.877.328.2123) to sign up for a package.

How Do I Revert a Changest in Team Foundation Source Control?

This question came up in our VSTS for Developers Training Course in Toronto this week. One of my students wanted to know how to undo or rollback a checkin, something you could do in Visual Source Safe.

Unfortunately this feature was cut for V1 of Team Foundation Server. Buck Hodges and Brian Harry from Microsoft share how this was a painful cut to help get V1 out the door in this forum post. 

Update: James Manning (via the comments) points out that the Team Foundation PowerToy will do this for you. Great tool btw - check it out. Includes the following tools: Unshelve & Merge local changes, Rollback, Online (syncs offline changes to source control), Get Changset, and Undo Unchanged.