Blame on me for old vb code net 10 completely not CLS

Today I’m converting a project written in VB to C#, since it is composed by simple classes that manages reporting in RTF, I supposed that this will be a simple process. This project uses a RTF library I wrote in Visual Basic in 2002, that was simply compiled for.NET 2.0 some times ago.

The problem is that the library is really not CLS compliant and when I converted this project, (that contains 54 classes) I got ~ 2000 compilation errors. This because the library uses a lot of not CLS features, and converting library to C# caused me a lot of troubles.

First, I used indexed properties with parameter, something like this.

T.RowProperty(0).BackgroundColor = &H808080

This is a property called RowProperty that require an Integer parameter, clearly when the project was converted in C# the result is this one :)

b.RowProperty[0].BackgroundColor = 0x808080;

That is not valid code, it raises the error

Property, indexer, or event 'RowProperty' is not supported by the language; try directly calling accessor method 'Nablasoft.RTF.RTFTableGenerator.get_RowProperty(int)

The quickest solution is to do a search and replace, and many thanks to visual studio that supports find and replace with regular expressions. image

This permits to me to change every occurrence of.RowProperty[index] with.get_RowProperty(index). There are also a lot of failing call to method with default parameter, not supported in C# 3.5…

This remind me that every Assembly MUst always be marked with the CLSCompliantAttribute and make sure that it is CLS compliant to avoid problem using it with different languages :(