VB.Net to C# conversion bugs#42
Conversation
|
hello, thanks for your interest in improving the code converter. In order to allow us to accept contributions from you, please sign the Joint Copyright Assignment (see https://github.com/icsharpcode/SharpDevelop/wiki/Joining-the-Team). After you have signed and sent the JCA, I will look into merging the pull-request... Thanks :) |
|
Hi Thanks for a quick reply. I am sending you signed JCA. Cheers,
|
VB.Net to C# conversion bugs
SharpDevelop Version : 4.3.1.0-00000000
1st Bug: VB.Net to C# converted LINQ syntax
VB.Net:
Should convert to C#:
But it converts to:
PThere are two problems with this conversion:
Following test demonstrates expected output:
To fix this bug apply patch #1 (properly handle VB.Net to CS LINQ where and select output). This patch adds white space before where and implements TrackedVisitQueryExpressionSelectVBClause to output select part.
2nd Bug: VB.Net XML Axis Properties
Visual Basic XML Axis Properties aka VB .NET LINQ-to-XML http://msdn.microsoft.com/en-us/library/bb384769(v=vs.90).aspx
When converting from VB.Net specific way of querying XML files you end up with empty or extremely confusing C# result.
Take for an example following snippet:
which queries someXml to find all descendants named sometag and return that in form of IEnumerable.
Currently conversion to C# looks like this:
where we would expect something like this:
Same goes for .<> (Elements) and .@ (Attributes) syntax.
To replicate this problem in current #develop code you can use following three tests:
To partially fix this bug you can apply patch #2 (handle VB.Net Axis LINQ syntax to CS conversion with tests) which includes and handles all three tests cases.
The reason why I mentioned partially fixed this problem is in a way VB.Net quetly handles different cases of elements and attributes syntax. While it is perfectly valid to use following syntax in VB.Net:
It actually translates slightly differently to C#:
Following two tests replicate this scenario:
To fix attribute set syntax apply patch #3 (handle VB.Net to CS conversion set attribute Axis syntax; replace assignment with call) over patch #2. As you can see from the patch we actually replace assignment expression with call expression, they way this is done is probably not the cleanest, however it did the job for my limited set of cases.