November 2003 - Posts

In one of my previous posts I tried generics both in VB.NET and C#, it turned out both languages support generics the same way. Ofcourse there is the syntax difference between them, and at this time C# has Intellisense that supports generics better, but I'm pretty sure the VB.NET team will catch up. Tonight I explored generics a little bit more; it's possible to add constraints to the generic type. By doing so, you are sure only instances can be created for the generic type, that support for example an interface you want it to. Another possibility is a constraint so the generic types must inherit from a specific base type. Let's say you have a base Entity class, from which your business entity classes inherit from, and a Customer entity class:
Public Class Entity
    Private _id As Long

    Public Property ID() As Long
        Get
            Return _id
        End Get
        Set(ByVal Value As Long)
            _id = Value
        End Set
    End Property
End Class

Public Class Customer
    Inherits Entity
    Private _name As String

    Public Property Name() As String
        Get
            Return _name
        End Get
        Set(ByVal Value As String)
            _name = Value
        End Set
    End Property
End Class

The generic collection class could look like this:
Public Class MyCollection(Of itemType As Entity)
    Inherits CollectionBase

    Default Public Property Item(ByVal index As Integer) As itemType
        Get
            Return CType(MyBase.InnerList(index), itemtype)
        End Get
        Set(ByVal Value As itemType)
            MyBase.InnerList(index) = Value
        End Set
    End Property

    Public Function Add(ByVal item As itemType) As Integer
        Return MyBase.InnerList.Add(item)
    End Function
End Class

Using the generic MyCollection class goes like this:
Dim c As New MyCollection(Of Customer)

So far pretty simple! The fun begins when you want to add multiple constraints. I searched the internet for some examples, but I couldn't find an example (I searched only a minute or so, yes I'm lazy). Luckily Yves was online and he was following a session about generics at U2U, so I asked him if this was possible. His answer was positive (cool!), but he saw this only in C#. So strengthened by the knowledge that this was possible in C#, I searched for the syntax in VB.NET. I tried a few possibilities, and it turned out that you have to use the & character to add more than one constraint. Extending the sample from above with an additional constraint, for example the generic type needs to implement the IComparable interface:
Public Class MyCollection(Of itemType As Entity & IComparable)
...
End Class

By the way, the C# syntax is:
public class List<ItemType> where ItemType : IComparable<ItemType>

Since I couldn't find any official documentation, I cannot garantuee that the syntax showed in this post is correct. So if anyone of MS reads this (by accident probably :-), it would be great if you can confirm this or give the correct syntax.

Last night I released a new version of the Hippo.NET Build Tool. Although it's a minor update, some cool new features are introduced:

  • Hippo.Client multi-project support
    From now on, you can manage multiple projects from a single Hippo.Client instance. You can easily switch, without having to restart the client, or having to alter the config file.
  • Get Latest Binaries Command
    After a successful build, most of the developers need to update their local assemblies with the newly compiled ones. Now this can be accomplished from within the Hippo.Client application, with a single click. For each project you can define the GetLatestBinCommand, for example a batch file that copies all the latest binaries from the build server to your development PC. Notice that this is a client-side feature.
  • Automatically Get Latest Binaries
    The GetLatestBinCommand can be executed automatically after a successful build.

As you can see all the features are client-side improvements. At this point I can already tell you the next release will focus on server-side improvements, like Scheduled Builds. This can be expected within 2 weeks. For now, download the 1.4.0 version here.

It's already old news (1 day), but I really want to pass the word: Microsoft Developer & IT Pro Days 2004 are comming on the 10th and 11th February! Microsoft Belgium has done a great job, this event is really cool: more than 50 different sessions (how much did the PDC have ;-). At then end of day one, there will also be a geek fest, be there!

Some quick links

By the way, would you like to drive a Ferrari?

Source: Duncan Mackenzie
For the next 6 months, many of the PDC Sessions will available at http://microsoft.sitestream.com/PDC2003/Default.htm as streaming audio with synchronized PPT and demos. Check it out!!

Cool!!

UPDATE: Some of the tags did not show up in the HTML (e.g. <itemType). This is corrected now... Thx Bruce.

Tonight I toyed a little bit with Generics. This feature was one of the first on my (rather long) list I wanted to try out, so I was quite curious. Thanks to the nice overview of Tom, I quickly put toghether a very simple generic collection class. The people who know me, know that I (still) prefer VB.NET over C# (I have a VB background), but I am bi-lingual, so I created the collection class both in VB.NET and C#. I noticed some minor differences between the two languages...

C#
public class MyCollection<itemType>:System.Collections.CollectionBase
{
 public MyCollection():base()
 { }

 public itemType this[int index]
 {
  get
  {
   return (itemType)base.List[index];
  }
  set
  {
   base.List[index] = value;
  }
 }

 public int Add(itemType item)
 {
  return base.List.Add(item);
 }
}

VB.NET
Public Class MyCollection(Of itemType)
    Inherits CollectionBase

    Public Sub New()
        MyBase.New()
    End Sub

    Default Public Property Item(ByVal index As Integer) As itemType
        Get
            Return CType(MyBase.List(index), itemType)
        End Get
        Set(ByVal Value As itemType)
            MyBase.List(index) = Value
        End Set
    End Property

    Public Function Add(ByVal item As itemType) As Integer
        Return MyBase.List.Add(item)
    End Function
End Class

As you can see, the structure is almost the same in VB.NET and C#, although I have to admit the C# syntax is a little bit more sexier. But the other way around: the VB.NET syntax is probably easier to understand by someone with little knowledge of Generics. Using the generic collection class is quite simple. It comes down creating a new instance of the class, and setting the type you want the collection to work with.

C#
MyCollection c = new MyCollection<string>();
c.Add("Test");
MessageBox.Show(c[0]);

VB.NET
Dim c As New MyCollection(Of String)
c.Add("Test")
MessageBox.Show(c(0))

When trying my collection both in C# and VB.NET, I noticed some differences in the Intellisense. For example when you use the Add method, the C# editor tells you, while typing, that this method expects a string value. In VB.NET Intellisense is not that smart, it can't tell you what type you need to add. Probably this is because I'm using the PDC bits, because the VB.NET editor can tell you that you can't add for example an integer to the collection (when using Option Strict ofcourse).

VB.NET IDE


C# IDE

Today I attended a BENUG session about ASP.NET V2 by Michiel van Otegem. Michiel put a lot of topics into his presentation and demos, so the a lot of cool stuff was briefly explained and showed. I was amazed how much new functionality was already available in this alpha release. My intrested went especially to the part when databinding comes into play. One demo showed how easy it was to drop a SQL Server table on a WebForm to create an editable grid. That's cool for a demo, but this is quite ugly for a production application: no layers, direct db access from the UI, ... Luckily there are several DataSources that can be used to do databinding, including a DataSource for Webservices and Objects. Even if they were not available it wouldn't be a problem because Whidbey used the Provider Model Design Pattern, so there is an IDataSource (don't remember the exact name) interface. You can create your own DataSource class by implementing this interface. Great!

Michiel also mentioned he expected Whidbey to go into beta phase around next summer (TechEd), he even made prediction for the RTM: end of 2004. BUT today I received the Whidbey DVD and at this point the installation is complete. So the magical moment happens once again: the first run of Visual Studio.NET Whidbey! It will be a long night... isn't the life of a developer great? :-)

UPDATE: I played a little bit with Whidbey and here is my first concern: there is no DataSource or similar class in WindowsForms... Maybe I overlooked it (it's already late), but as far as I can see, there are the plain “old” data classes. Are the WindowsForms developers left alone? Anyone an idea?

The last few days I toyed a little bit with the DotNetNuke open source portal system. I know this is not SharePoint, but it allows to quickly setup good looking website that can easily be maintained by non-technical people.  Although changing the layout (e.g. colors) of the site, especially the top banner with the menu, is quite hard in the beginning. I had to dive into the code to accomplish what I wanted to do. But once you get to know how the portal is designed, altering just anything is done in a second.

A DotNetNuke site consists of a number or tabs with a number of modules on. There many of these modules, including one that displays and RSS feed. This is intresting because it allows you to provide great dynamic content on your site (e.g. the .NET Weblogs Main Feed), with very little effort. By default the News Module display all the contents of the RSS feed as plain text, so HTML tags become escaped HTML tags, so the feed loses its formatting. This behaviour can be changed quite easy by editing the RSS91.xsl file in the DesktopModules\News directory. In this XSL file, I've added disable-output-escaping="yes" to the value-of tag of the description.

A second modification I've made is to limit the maximum number of news items displayed. This can come in handy when you don't want to display all the 30 or so items of a news feed, but only the last 5 of them. I've solved this by adjusting a copy of the RSS91.xsl file (e.g. RSS91_5.xsl). A new "if test" node is added, that performs a test for each news item. If the position is smaller or equal to 5, the item is displayed. To use the new RSS91_5.xsl, you have to upload the file (e.g. using the File Manager), and set the News module to use the Internal Style Sheet which you can select from the drow down list.

The following xsl displays the last 5 news items of an RSS News Feed, including the HTML formatting.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:param name="TITLE"/>
<xsl:template match="rss">
  <!-- Do not show channel image -->
  <xsl:for-each select="channel/item">
 <xsl:if test="position() &lt;= 5">
  <br>

  <strong><a href="{link}" target="_main"><xsl:value-of select="title"/></a></strong><br></br>

  <!-- only display markup for description if it's present -->
  <xsl:value-of select="description" disable-output-escaping="yes"/>

  </br>
  <br></br>
 </xsl:if>
  </xsl:for-each>
</xsl:template>

<xsl:template match="description">
  <br>
    <xsl:value-of select="."/>
  </br>
</xsl:template>

</xsl:stylesheet>

Microsoft Virtual PC 2004 can be downloaded from the MSDN Subscriber Downloads. For those of you unfamiliar with VPC; Microsoft bought the technology from Connectix that allows you to host several virtual PC's on a single machine. Each virtual PC lives in its own isolated envirionment, and is physically only a single file of the host machine. To communicate with your Virtual PC's you can use either shared folders or (virtal) network connections. You can even access your Virtual PC's from anywhere in your network! This piece of software is great for software developers; you always have a clean machine to try something out. I keep a freshly installed Windows XP on my HD, and ever time I need to try something I copy that image. No more screwing up of your host machine.

Another nice feature is that you can rollback any changes (if you want so ofcourse). Imagine having a development server and staging server that allow you to try stuff out, without having to worry to something wrong; you can allways rollback to it's previous state.

If you want to use Virtual PC, make sure you have plenty of memory, since the memory each Virtual PC uses is not virtual, but physical. :-)

MSDN Belux will organise another great MSDN Event on December 11th in Kinepolis Brussels in Belgium. There are two tracks

  • Smart Clients: The 'Building Smart Client Applications' seminar has been designed to show developers how to build rich applications with Visual Studio.NET that enable use in both online and offline scenarios as well as offer easy deployment without the infamous DLL Hell. Specifically the seminar will focus on the development of a 'real' suite of applications, built using Visual Studio .NET, the .NET Framework as well as Microsoft Office System InfoPath 2003. On top of this, the seminar will focus on Pocket PC and Windows Powered SmartPhone devices and show developers how they can target these devices using the .NET Compact Framework. Delegates are encouraged to attend the sessions most relevant to their own needs, or to attend all sessions to gain a broad understanding of the entire Smart Client platform.
  • BizTalk Server is Microsoft's primary platform for Enterprise Application Integration. The newest version, BizTalk Server 2004, will be launched in the near future and is the first phase in the delivery of Microsoft's Jupet. The aim of this seminar is to provide an architectural overview and technical background of this new version. SD Worx, one of Microsoft's BizTalk Server 2004 Early Adopter Program customers, will tell you about its experiences with the product.

Check out the complete agenda and register here. The Biztalk track will even explain the relation of Biztalk to Indigo, sounds like fun! Together with the BENUG Session of tomorrow about ASP.NET 2.0, the end of the year brings the Belgian .NET Developers some early presents. Belgian .NET Developers, cu all there!

Ok, for all of us who didn't attend the PDC (and have a MSDN Subscription), the Longhorn PDC Preview can be downloaded from the MSDN Subscriber Downloads! This is nice, but I would be happier if Whidbey could be downloaded. Visual Studio “Whidbey” referenced in the instructions is not available from MSDN Subscriber Downloads, but is available by request from MSDN customer service.

Source: http://weblogs.asp.net/prieck/posts/37181.aspx

More Posts Next page »