Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

VB.Net to C# conversion bugs#42

Merged
siegfriedpammer merged 3 commits intoicsharpcode:masterfrom
sharpmonkey:master
Jul 6, 2013
Merged

VB.Net to C# conversion bugs#42
siegfriedpammer merged 3 commits intoicsharpcode:masterfrom
sharpmonkey:master

Conversation

@sharpmonkey
Copy link
Copy Markdown
Contributor

SharpDevelop Version : 4.3.1.0-00000000

1st Bug: VB.Net to C# converted LINQ syntax

VB.Net:

Dim value = From value In values Where value = ""someValue"" Select value

Should convert to C#:

var value = from value in values where value == ""someValue"" select value;

But it converts to:

var value = from value in valueswhere value == ""someValue""value;

PThere are two problems with this conversion:

  • no space between where and enumerable
  • missing select statement

Following test demonstrates expected output:

[Test]
public void LinqQueryWhereSelect()
{
    TestStatement(@"Dim value = From value In values Where value = ""someValue"" Select value",
                  @"var value = from value in values where value == ""someValue"" select value;");
}

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:

Dim someDescendants = someXml...<sometag>

which queries someXml to find all descendants named sometag and return that in form of IEnumerable.

Currently conversion to C# looks like this:

var someDescendants = someXml;

where we would expect something like this:

var someDescendants = someXml.Descendants("sometag");

Same goes for .<> (Elements) and .@ (Attributes) syntax.

To replicate this problem in current #develop code you can use following three tests:

[Test]
public void XmlLINQDescendants()
{
    TestStatement(@"Dim element = someXml...<somename>",
                  @"var element = someXml.Descendants(""somename"");");
}
[Test]
public void XmlLINQElements()
{
    TestStatement(@"Dim element = someXml.<somename>",
                  @"var element = someXml.Elements(""somename"");");
}
[Test]
public void XmlLINQAttribute()
{
    TestStatement(@"Dim value = someXml.@attr",
                  @"var value = someXml.Attribute(""attr"").Value;");
}

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:

someElement.@someattribute = 8 ' we are setting someattribute value to 8

It actually translates slightly differently to C#:

someElement.SetAttributeValue("someattribute", 8); // here we have method call instead of property set

Following two tests replicate this scenario:

[Test]
public void XmlLINQAttributeSetConstant()
{
    TestStatement(@"someElement.@someAttr = 8",
                  @"someElement.SetAttributeValue(""someAttr"", 8);");
}
[Test]
public void XmlLINQAttributeSetExpression()
{
    TestStatement(@"someElement.@someAttr = string.Format(""{0}"", 19)",
                  @"someElement.SetAttributeValue(""someAttr"", string.Format(""{0}"", 19));");
}

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.

@siegfriedpammer
Copy link
Copy Markdown
Member

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 :)

@sharpmonkey
Copy link
Copy Markdown
Contributor Author

Hi

Thanks for a quick reply. I am sending you signed JCA.

Cheers,
Greg
On 25/06/2013 5:40 AM, "Siegfried Oleg Pammer" notifications@github.com
wrote:

hello, thanks for your interest in improving the code converter. In order
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 :)


Reply to this email directly or view it on GitHub.

siegfriedpammer added a commit that referenced this pull request Jul 6, 2013
VB.Net to C# conversion bugs
@siegfriedpammer siegfriedpammer merged commit 4f1262e into icsharpcode:master Jul 6, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants