Archives

Archives / 2003 / June
  • My MSDN Belux Article online!

    Today my article about Collections in .NET was published on the MSDN Belux site. The article is the first of two about the collection classes in the .NET Framework:
    <quote>
    When you lookup the System.Collections namespace in the MSDN Library, you will find over 10 different classes. Choosing the right one for using in your application can be hard. This article will provide an overview and give some guidelines for choosing the right collection. The next article in this series will focus on building custom strongly typed collections and applying advanced techniques on them, such as data binding and sorting.
    </quote>

  • NAnt BuildFile Builder Beta Version

    One of the complaints that I've received about using the Hippo.NET Build tool, is the fact that you manually have to write your own NAnt build file. So one of the features I want to implement in the next release of Hippo.NET, is either generating buildfiles on the fly, or providing  a tool to easily generate buildfiles based on the Visual Studio project file. That's why I've created the Hippo.NET BuildFile Builder (what's in a name ;-). On this site, you can generate NAnt buildfiles, based on a Visual Studio project file. You simply browse to your project file on your local harddisk and press the Generate button and a the contents of a NAnt buildfile are generated.

  • Extending Intellisense: Namespace lookup with a macro (bis)

    A few weeks ago, I posted a macro to improve the Intellisense of Visual Studio. This macro automates the lookup of namespaces (AddDirective methode). For example when you type "Dim r As XmlReader", you probably need to add the "Imports System.Xml" (or "using System.Xml;" in C#) statement to your code. This macro helps you by searching for the corresponding namespace and add it to your code automatically. Additional there is a macro function (AddNamespace method) that replaces "xmlreader" with "System.Xml.XmlReader", so it just adds the namespace in front of your type.

    Thanks to a tip of Yves Hanoulle, there is now one single function that adds the using/Imports directive for both VB.NET and C#.

    The macro works great if you assign a shortcut key to it, you can do that like this:

    • Enter or copy-and-paste the macro code in the Macro Editor of Visual Studio.
    • Choose in the Tools menu the Customize menu item.
    • Press the Keyboard button (below right).
    • In the list of the commands, find Macros.MyMacros.TypeFinder.AddDirective, and select it.
    • In the textbox "Press shortcut key(s)", press the key combination you want to use. (I use Ctrl+`)
    • Change the "Use new shortcut in:" value to "Text Editor"
    • Press the Assign button.
    Let me know if you have any remarks, problems, ... The complete source code of the macro is:

    Imports EnvDTE
    
    Imports System.Diagnostics
    Imports System

    Public Module TypeFinder
    Private Function SearchTypeInAssembly(ByVal typename As String _
    , ByVal ass As Reflection.Assembly)
    DTE.StatusBar.Text = "Searching for '" & typename & "' " & _
    ass.GetName.Name & "..."
    Dim t As Type
    For Each t In ass.GetTypes
    If t.Name.ToLower = typename Then
    Return t
    End If
    Next
    End Function
    Private Function SearchType(ByVal typename As String) As Type
    typename = typename.ToLower
    Dim projs As System.Array = DTE.ActiveSolutionProjects
    Dim ass As Reflection.Assembly = _
    Reflection.Assembly.LoadWithPartialName("mscorlib")
    Dim t As Type = SearchTypeInAssembly(typename, ass)
    If Not t Is Nothing Then Return t
    Dim proj As Project
    For Each proj In projs
    Dim o As VSLangProj.VSProject = proj.Object
    Dim ref As VSLangProj.Reference
    For Each ref In o.References
    ass = Reflection.Assembly.LoadFile(ref.Path)
    t = SearchTypeInAssembly(typename, ass)
    If Not t Is Nothing Then Return t
    Next
    Next
    DTE.StatusBar.Text = "Could not find type '" & typename & _
    "' in the referenced libraries. Make sure your cursor " & _
    "is right behind the text (without selection)!"
    DTE.StatusBar.Highlight(True)
    Return Nothing
    End Function
    Public Sub AddNamespace()
    Dim text As TextSelection = DTE.ActiveDocument.Selection
    text.WordLeft(True)
    Dim t As Type = SearchType(text.Text)
    If Not t Is Nothing Then
    text.Text = t.FullName
    text.EndOfLine()
    DTE.StatusBar.Text = "Ready"
    End If
    End Sub
    Public Sub AddDirective()
    Dim text As TextSelection = DTE.ActiveDocument.Selection
    text.WordLeft(True)
    Dim t As Type = SearchType(text.Text)
    If Not t Is Nothing Then
    Dim keyword, suffix As String
    Dim line As Integer = text.AnchorPoint.Line
    text.Text = t.Name
    text.StartOfDocument()
    Select Case DTE.ActiveDocument.Language
    Case "CSharp"
    keyword = "using"
    suffix = ";"
    Case "Basic"
    keyword = "Imports"
    suffix = String.Empty
    Case Else
    Throw New System.Exception("Invalid Language: " & _
    DTE.ActiveDocument.Language)
    End Select
    text.Insert(keyword & " " & t.Namespace & suffix & vbCrLf)
    text.MoveToLineAndOffset(line + 1, 1)
    text.EndOfLine()
    DTE.StatusBar.Text = "'" & keyword & " " & t.Namespace & _
    suffix & "' added to the document."
    DTE.StatusBar.Highlight(True)
    End If
    End Sub
    End Module




  • Extending Intellisense: Namespace lookup with a macro

    Namespaces in .NET are great! But how many times do you find yourself typing "Private r As xmlreader", and then noticing that there is no Imports/using statement for the System.Xml Namespace? Then you would have to scroll to the top of your document and add the Imports/using statement by hand. Alternatively you could choose to add the namespace to your declaration: "Private r As System.Xml.XmlReader". Since we are all developers, why not develop something to help developers with this tedious task of namespace lookups?

  • PowerToys going open source

    Yesterday I wrote something about the new PowerToys, and compared them to the other alternatives. I you read that post, you'll see the comments of Josh Ledgard of MS:
    Hi Jan.  I'm one of the guys at Microsoft who works on the Power Toys.  I wanted to let you know a little bit about the PowerToys effort.  I promise that we didn't work on these projects to displace third party tools.  I actually think that all of the commenting tools you mention have their plusses and minuses.  And at the moment some are more polished than the one our team released.  One of the motivations included giving people samples from Microsoft for extending the shell.  You can never have too many samples.  Another is that we just thought it would be a cool project to work on and provide a forum for other developers in the community to also work on.  Actually, we've been in contact with the writer of the VBXC tool you mentioned and he has recently joined our workspace project on gotdotnet that allows for other people to modify the code.  If your interested feel free to check out our workspaces.. http://www.gotdotnet.com/Community/MessageBoard/Thread.aspx?id=107870
    Thanks, 
     josh


    I think Josh is completly right: you can't have too many samples and it's a cool project to work on! And ofcourse they did not start these projects to kill similar third party tools. I hope my previous post wasn't misunderstood, because I was trying to say that I really like the initiative. And going open source to the GotDotNet workspaces only makes it better:

  • XML Comments in VB: PowerToys and "the others"

    Microsoft has released some PowerToys for Visual Studio.NET 2003, including a tool that enables XML comments in Visual Basic.NET: VB Commenter. XML comments were available for C# developers since VS.NET 2002, and I still do not understand why they did not implement them in VB. But anyway, the great (open source) community of (VB).NET, has produced several tools to enable XML comments in VB:

  • Remoting, Events and the 1.1 Framework

    This weekend I played with the Observer Pattern to create a system that could publish events to a central server. To this server, other applications could subscribe to receive this events. Because I wanted the system to be fast, I choose .NET Remoting as communication between the clients and the server.