views:

248

answers:

1

In C#, if you do this, it will compile:

namespace Name
{
    public class Test
    {
    }

    public class TestUse
    {
        private global::Name.Test test;
    }
}

If you try the same in VB.NET, however, it won't:

Namespace Name
    Public Class Test
    End Class

    Public Class TestUse
        Private test As Global.Name.Test
    End Class
End Namespace

I get (depending on the way I try to use "Test") either "'Name' is not a member of '<Default>'." or "Type 'Name.Test' is not defined." in my error list. I've found two ways to make it work, but neither are reasonable to expect of a user. One is to remove the "Root Namespace" from the project properties. The other is to include that namespace between "Global" and "Name".

I have made a custom tool that uses CodeDom to generate code for both C# and VB.NET. This is the reason why neither of the two fixes above are feasible: I can't expect my users to have an empty root namespace, and I'd hate to have to do VB-specific tricks in my code generation (kind of defeats the purpose of using a language-neutral tool, doesn't it?) such as picking out the "Root Namespace" (not that I'd know how off the top of my head) and including it in my code generation.

I don't want to leave out the global modifier either, because it protects the tool from users picking bad names for the generated output. Does anybody have a suggestion for how I should deal with this?

+2  A: 

Given that you have to perform different code-gen tasks for either language anyway, it'd be just another drop in the bucket of differences for generating that code.

Coding in the VB-specific trick of inserting the default namespace isn't too big an issue, on first glance, compared to the other implementation details.

Good luck!

p.campbell
Yeah, I ended up just adding a little VB-specific code generation quirk. I could unfortunately not see any other solution.
Alex