Home > Microsoft .Net Development Tips > Visual Basic and Visual Basic .NET > Visual Basic team offering Extension Methods tutorials
Win Development Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

VISUAL BASIC AND VISUAL BASIC .NET

Visual Basic team offering Extension Methods tutorials


SearchVB.com staff
04.26.2007
Rating: --- (out of 5)


.NET Essentials Channel
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


Visual Basic 9.0 is full of new features. One of them is Extension Methods, which, in the words of Scott Wisniewski of the VB compiler group, "provide a very powerful and elegant way to inject your own custom functionality into other people's types….Extension Methods enable you to create a method in a module decorated with an attribute and have that method appear as if it was an instance method defined on another type."

Wisniewski recently posted a six-part Extension Methods tutorial on Microsoft's Visual Basic Team blog. He focused on this feature of Visual Basic 9.0 because, well, it is his favorite. Below we link to each part and offer a bit of insight into what is covered.

Part 1: An introduction to Extension Methods describes how they provide "discoverability." In Visual Studio 2005, calling a utility method uses a different syntax than calling an instance method, so programmers must know, ahead of time, whether they are calling a shared utility method written by a third party or an instance method provided directly by a class author, Wisniewski notes. Visual Studio Orcas' Extension Methods merge these types of methods.

Part 2: Rules for consuming Extension Methods provides tips for defining and consuming these methods. Wisniewski points out the differences between Extension Methods in C# and in VB. He also outlines the "precedence levels" that determine which Extension Method takes precedence in the event that two methods conflict.

Part 3: Extension Methods and byval / byref parameters offers a quick look at how the compiler evaluates Extension Methods calls and a hint or two for working with value-type extensions.

Part 4: Extension Methods and late binding explains why Extension Methods do not support late binding -- it is because the methods are closely tied to IntelliSense, which does not work in late-bound scenarios. Wisniewski then points out that, as a result, Extension Methods cannot be called off any expression statically typed as Object.

Part 5: Generics and Extension Methods discusses why Visual Studio Orcas deals with generic Extension methods differently than regular generic methods. "When binding against extension methods we now perform generic type parameter inference in two passes instead of one," Wisniewski writes. "During the first pass we infer types for type parameters referenced by the first argument and during the second pass we infer types for any type parameters referenced by subsequent arguments." There are three reasons for this -- transparency, better use of IntelliSense and improved query support.

Part 6: Extension Methods Best Practices gives seven tidbits of advice, such as putting Extension Methods into their own namespaces and being as specific as possible when extending a type.

Rate this Tip
To rate tips, you must be a member of SearchWinDevelopment.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
.NET Framework 3.5 and Visual Studio 2008 development
Printing in Windows Presentation Foundation
Book excerpt: Murach's VB 2008
Mainsoft introduces .NET-to-Java translation tool
A view on VS 2008: On-line agency sees reasons to upgrade
LINQ Learning Guide: LINQ and Visual Studio 2008's new language features
Customizing Visual Studio 2008 using VS Shell
Shell Objects adds Visual Studio 2008, x64 support
How to uninstall pre-release versions of Visual Studio 2008
.NET Framework Library source code released
.NET Framework goes multicore

Visual Basic and Visual Basic .NET
Compose XML more quickly using Visual Basic 9
Virtualization keeps Legacy Apps alive
VB 9 Anonymous Types help create flexible objects
Visual Studio Team System Add-ins: Conchango Scrum for Team System and Scrum Dashboard
Book Excerpt: Sams Teach Yourself Visual Basic 2008 in 24 Hours -- Complete Starter Kit
Check out CodePlex for a ton of interesting .NET projects
Book excerpt: Murach's VB 2008
Book excerpt: Printing in Visual Basic 2005
Visual Basic 2008 and closures
WinForms development using SQL Server 2005 and Visual Basic 2005

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
Cosmos  (SearchWinDevelopment.com)
IronRuby  (SearchWinDevelopment.com)
Visual Studio Express (VSE)  (SearchWinDevelopment.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2000 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts