Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

CodeDom Question

I'm just getting started with CodeDom, and I'm playing with generating files with it.  I'm using the CodeProvider.FileExtension property to create a suffix for the output (obviously), and it works fine for most languages ("foo." + provider.FileExtension -> "foo.cs" for CSharp), but when I use the VJSharp provider it messes up.  (I get "foo..jsl".)  In most languages it seems to be just "cs" or "vb" or "js" but with VJSharp it is ".jsl" - what gives?  I don't want my files having 2 dots in the name, nor do I want them having none.  Is this a known bug?  Should I scan the FileExtension for a leading period and trim it if it exists?

Any advice?

Aaron F Stanton
Thursday, October 14, 2004

You could have a dig around using Lutz Roeder's Reflector.

I only have C# and VB loaded, so couldn't check the implementation of VJ#.

However, I can see in Microsoft.CSharp.CSharpCodeProvider there is a virtual property FileExtension, which returns the string "cs" (overriding the default behaviour, which is to return an empty string).

If you can find the implementation of the VJ# compiler, you can check what it returns, but I suspect it'd be ".jsl", i.e. it is a bug and the property shouldn't return the period (".").

As an aside, I find Reflector to be really useful and for a free tool it is excellent.

Nemesis
Friday, October 15, 2004

Found it now, and as I suspected, there is a bug in the implementation:

.method public hidebysig specialname virtual instance string get_FileExtension() cil managed
{
      // Code Size: 6 byte(s)
      .maxstack 8
      L_0000: ldstr ".jsl"
      L_0005: ret
}

Compared to the C# implementation:

.method public hidebysig specialname virtual instance string get_FileExtension() cil managed
{
      // Code Size: 6 byte(s)
      .maxstack 8
      L_0000: ldstr "cs"
      L_0005: ret
}

For anyone who hasn't already got Reflector, it can be downloaded for free here: http://www.aisto.com/roeder/dotnet/

Nemesis
Friday, October 15, 2004

Hi -

Thanks!  I had forgotten about Reflector.  This confirms what I had found out the hard way.  Sigh.  It would be nice to have some consistency from MS on this.  I guess a work-around is in order.

Thanks again!

Aaron F Stanton
Friday, October 15, 2004

No problem. Yeah, it would be nice if Microsoft would be consistent here, but the work-around idea is the best.

The alternative is to wait for them to fix it (don't hold your breath), or fix it yourself.

I notice that the VJSharpCodeProvider class is not sealed, so perhaps you could inherit it, then override the FileExtension property to return the expected value. Don't you just love .NET ;-)

Nemesis
Friday, October 15, 2004

*  Recent Topics

*  Fog Creek Home