A View Inside My Head

Jason's Random Thoughts of Interest
posts - 81, comments - 172, trackbacks - 18

You Need that Using Statement for Extension Methods!

I was working through some Windows Azure example code today, and came across a situation where IntelliSense did not show a method that the sample code used (CreateCloudBlobClient(), in this case):

var storageAccount = Microsoft.WindowsAzure.CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
var blobStorage = storageAccount.CreateCloudBlobClient();

A lot of times, when I'm exploring an API, I will type out the fully qualified class name in code so that I can use IntelliSense to see what the other members exist in the same namespace. And, while I'm exploring, I usually don't bother to include a using statement at the top of my code because it's so easy to just use the "Remove Type Qualifier" refactoring available in CodeRush to clean up the code when I'm ready to move on.

Well, something that I guess I didn't remember soon enough was that using statements are required in order to enable Extension Methods belonging to that namespace. In this case, CreateClousBlobClient() was not a method of CloudStorageAccount, but rather an Extension Method (and this fact is not something that is very apparent when typing in sample code that you find in a document).

IntelliSense showed that method (and more!) after adding the following line of code to the top of my file:

using Microsoft.WindowsAzure.StorageClient;



Print | posted on Thursday, February 25, 2010 2:11 PM | Filed Under [ Articles .NET Azure ]

Comments have been closed on this topic.

Powered by: