Stupid .NET Tricks #10

January 9, 2008 by Craig

Some .NET classes (System.Data.DataSet is the one I’m currently using) define a property called “Namespace”. In VB, “Namespace” (note the capital “N”) is a reserved word used to associate a class with a particular namespace. Since it’s a reserved word, it’s not a valid identifier in VB… meaning that the MS classes that contain the property “Namespace” were not written in VB (at least without some sort of compiler hack).

Currently I’m trying to reimplement a (legacy) class that subclasses DataSet; I want to break the DataSet inheritance and replace it with custom members. Due to the “Namespace” conflict, I can’t do this in VB, although it wouldn’t be a problem in C#, and isn’t a problem for all of the other properties in the old class.

So much for language independence.

Update: I spoke too soon; VB does have a mechanism for specifying identifier names that match keywords: just enclose the identifier in brackets. It’s unfortunate that it’s necessary, but it’s easy enough to implement once you know the trick.


No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.