Jun 17 2011

.Net Guidance Map

Category: .Net | .Net Framework | asp.net ashish sheth @ 18:05


I thought these would be very helpful to those who are learning .Net.  J. D. Meier has put up Development Guidance Map for various .Net technologies. This material includes links to technical articles, videos, how-tos, blogs, tutorials, trainings, code samples on various .Net technologies and about everything you might need to know about .net.

Happy Learning.


Tags: ,

Dec 7 2009

Invoke Google from withing VS 2008

Category: .Net | .Net Framework | C# | CodeProject | VS2008 ashish sheth @ 11:25

As programmers we need to search for many tasks that we want to accomplish. And the F1 key in visual studio does not help because it always launches the local MSDN search, even if MSDN is not installed on the local computer.

Brian Schmitt has provided the code to write a macro to search variouse sites. Here I am describing steps to how you can configure your Visual studio 2008 to invoke google search from within the IDE based on his post.

  • In the VS 2008 IDE, click Alt + F8 to launch the Macro explorer.  It should show you a tree like below at the right hand side of the IDE.



  • Right Click on theMyMacros project and create a new module named Search. (Alternately, you can goto Tools menu-> Macros -> New Macro command). This will launch the macro editor.
  • Copy and paste the below code in the macro editor. (Code taken from Brian Schmitt's article on Better Visual Studio F1)


Imports EnvDTE
Imports System.Web

Public Module Search

#Region "Search Internet Sites"
  Public Const GOOGLE_FORMAT As String = "www.google.com/search?q={0}"
  Public Const STACKOVERFLOW_FORMAT As String = "http://www.stackoverflow.com/search?q={0}"
  Public Const SEARCHDOTNET_FORMAT As String = "http://searchdotnet.com/results.aspx?cx=002213837942349435108:jki1okx03jq&q={0}&sa=Search&cof=FORID:9#1144"
  Public Const MSDN_FORMAT As String = "http://social.msdn.microsoft.com/Search/en-US/?query={0}&ac=8"
  Public Sub SearchStackOverflowForSelectedText()
  End Sub
  Public Sub SearchGoogleForSelectedText()
  End Sub
  Public Sub SearchSearchDotNetForSelectedText()
  End Sub
      Public Sub SearchMSDNForSelectedText()
  End Sub
  Private Sub SearchWebPage(ByVal SearchURLFormat As String)
      Dim sel As EnvDTE.TextSelection = DTE.ActiveWindow.Selection
      Dim srchTxt As String = sel.Text.Trim
      If srchTxt.Length > 0 Then
          DTE.ItemOperations.Navigate(String.Format(SearchURLFormat, HttpUtility.UrlEncode(srchTxt)))
      End If
  End Sub
#End Region

End Module


  • Now the macro is ready (there are four macros created one each for google, stackoverflow, searchdotnet and MSDN). Now we will assign short cut for all the four macros.
  • Go to Tools -> Options -> keyboard. In the “Show command containing” type macro. Or simply scroll through the list box to find the macro we just created.



  • In the “Press shortcut key” type in the short cut you want (for e.g. Alt + F1, Alt + Shift + F1). Note that if you press just F1, it will replace the existing binding for the F1 key to the MSDN help.
  • In the similar way type in the short cut for other macros.

Tags: ,

Aug 8 2009

Changing the default name of indexer

Category: .Net | .Net Framework | C# ashish sheth @ 12:05

.NET framework contains many hidden gems, which we rarely need and use, in the Base class libraries.

You probably know that when you write an indexer in C#, it will get compiled into two methods called get_Item and set_Item.

So when you declare an indexer like this:

public string this[int number]

it actually compiles into this:

public string get_Item(int number)

Now, did you know that you can have any other name for your indexer if you don't want the name of your indexer to be get_Item? Yes, you can use System.Runtime.CompilerServices.IndexerNameAttribute to change the name into which your indexer will be compiled. Here is the example.

    public string this[int number]

The above lines will generate a method like below:

public string get_BinaryFormatOf(int number)

I am not sure in what scenario this can be useful but it will certainely usefull if you have indexers which does fit into the getItem-setItem pattern.

Tags: , , ,