|
-
Jan 4th, 2011, 12:02 AM
#1
VB.NET Extension Methods primary
This articles intent is to provide some basics to writing extension methods with practical examples along with references at the end of the article. Please note that the “how-to” is emphasized here over actual code within the extensions since if you were to ask 10 programmers how to do task A there will more likely than not at least five different ways to accomplish the task.
One of the features I embraced when VS2008 arrived was extension method (I tend to call them language extensions) as my style of programming is declarative in nature so this was a natural progression for me.
When reading various documents from MSDN web site along with the sparse amount of information I did pick it up easily. Also realized that for some developers not in the game for very long may not see the benefits of using extensions along with others who might abuse extension or would shun them if the few limitations caused them discomfort.
From MSDN Visual Basic 2008 introduces extension methods, which enable developers to add custom functionality to data types that are already defined without creating a new derived type. Extension methods make it possible to write a method that can be called as if it were an instance method of the existing type.
http://msdn.microsoft.com/en-us/libr...36(VS.90).aspx
Okay my intent is to show the average developer useful ways to use extension methods in their every day task of developing solutions. If you want in-depth information, check out the links at the bottom of this article.
First steps: Do not write an extension simply because you can but instead because it serves a valid purpose over writing a convention function or procedure. Secondly, write the extension as a conventional function or sub until you get the hang of writing extension methods. Another consideration is how show exceptions be handled and finally in regards to starting out writing extensions think about their scope.
Last edited by kareninstructor; Aug 11th, 2011 at 08:04 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|