Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VB -> C#: Handles with differing case is not converted #854

Closed
jrmoreno1 opened this issue Mar 25, 2022 · 0 comments
Closed

VB -> C#: Handles with differing case is not converted #854

jrmoreno1 opened this issue Mar 25, 2022 · 0 comments
Labels
VB -> C# Specific to VB -> C# conversion

Comments

@jrmoreno1
Copy link
Contributor

jrmoreno1 commented Mar 25, 2022

VB.Net input code

Public Class VBIsCaseInsensitive
    Inherits System.Web.UI.Page

    Private Sub btnOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
    End Sub
End Class

Partial Public Class VBIsCaseInsensitive
    Protected WithEvents btnOk As Global.System.Web.UI.WebControls.Button
End Class

Erroneous output

class _failedMemberConversionMarker1
{
}
#error Cannot convert ClassBlockSyntax - see comment for details
/* Cannot convert ClassBlockSyntax, CONVERSION ERROR: An item with the same key has already been added. Key: btnOk in 'Public Class VBIsCaseInsens...' at character 203
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey](TSource[] source, Func`2 keySelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer)
   at ICSharpCode.CodeConverter.CSharp.HandledEventsAnalysis..ctor(CommonConversions commonConversions, INamedTypeSymbol type, IEnumerable`1 csharpEventContainerToHandlingMethods) in D:\GitWorkspace\CodeConverter\CodeConverter\CSharp\HandledEventsAnalysis.cs:line 35
   at ICSharpCode.CodeConverter.CSharp.HandledEventsAnalyzer.AnalyzeAsync() in D:\GitWorkspace\CodeConverter\CodeConverter\CSharp\HandledEventsAnalyzer.cs:line 58
   at ICSharpCode.CodeConverter.CSharp.DeclarationNodeVisitor.GetMethodWithHandlesAsync(TypeBlockSyntax parentType, IMethodSymbol designerGeneratedInitializeComponentOrNull) in D:\GitWorkspace\CodeConverter\CodeConverter\CSharp\DeclarationNodeVisitor.cs:line 637
   at ICSharpCode.CodeConverter.CSharp.DeclarationNodeVisitor.ConvertMembersAsync(TypeBlockSyntax parentType) in D:\GitWorkspace\CodeConverter\CodeConverter\CSharp\DeclarationNodeVisitor.cs:line 216
   at ICSharpCode.CodeConverter.CSharp.DeclarationNodeVisitor.VisitClassBlock(ClassBlockSyntax node) in D:\GitWorkspace\CodeConverter\CodeConverter\CSharp\DeclarationNodeVisitor.cs:line 328
   at ICSharpCode.CodeConverter.CSharp.CommentConvertingVisitorWrapper.ConvertHandledAsync[T](VisualBasicSyntaxNode vbNode, SourceTriviaMapKind sourceTriviaMap) in D:\GitWorkspace\CodeConverter\CodeConverter\CSharp\CommentConvertingVisitorWrapper.cs:line 48

Input:

Public Class VBIsCaseInsensitive
    Inherits Global.System.Web.UI.Page

    Private Sub btnOk_Click(ByVal sender As Object, ByVal e As Global.System.EventArgs) Handles btnOK.Click
    End Sub
End Class

 */
class _failedMemberConversionMarker2
{
}
#error Cannot convert ClassBlockSyntax - see comment for details
/* Cannot convert ClassBlockSyntax, CONVERSION ERROR: An item with the same key has already been added. Key: btnOk in 'Partial Public Class VBIsCa...' at character 408
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey](TSource[] source, Func`2 keySelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer)
   at ICSharpCode.CodeConverter.CSharp.HandledEventsAnalysis..ctor(CommonConversions commonConversions, INamedTypeSymbol type, IEnumerable`1 csharpEventContainerToHandlingMethods) in D:\GitWorkspace\CodeConverter\CodeConverter\CSharp\HandledEventsAnalysis.cs:line 35
   at ICSharpCode.CodeConverter.CSharp.HandledEventsAnalyzer.AnalyzeAsync() in D:\GitWorkspace\CodeConverter\CodeConverter\CSharp\HandledEventsAnalyzer.cs:line 58
   at ICSharpCode.CodeConverter.CSharp.DeclarationNodeVisitor.GetMethodWithHandlesAsync(TypeBlockSyntax parentType, IMethodSymbol designerGeneratedInitializeComponentOrNull) in D:\GitWorkspace\CodeConverter\CodeConverter\CSharp\DeclarationNodeVisitor.cs:line 637
   at ICSharpCode.CodeConverter.CSharp.DeclarationNodeVisitor.ConvertMembersAsync(TypeBlockSyntax parentType) in D:\GitWorkspace\CodeConverter\CodeConverter\CSharp\DeclarationNodeVisitor.cs:line 216
   at ICSharpCode.CodeConverter.CSharp.DeclarationNodeVisitor.VisitClassBlock(ClassBlockSyntax node) in D:\GitWorkspace\CodeConverter\CodeConverter\CSharp\DeclarationNodeVisitor.cs:line 328
   at ICSharpCode.CodeConverter.CSharp.CommentConvertingVisitorWrapper.ConvertHandledAsync[T](VisualBasicSyntaxNode vbNode, SourceTriviaMapKind sourceTriviaMap) in D:\GitWorkspace\CodeConverter\CodeConverter\CSharp\CommentConvertingVisitorWrapper.cs:line 48

Expected output

using System;
using System.Runtime.CompilerServices;

public partial class VBIsCaseInsensitive : System.Web.UI.Page
{
    private void btnOk_Click(object sender, EventArgs e)
    {
    }
}

public partial class VBIsCaseInsensitive
{
    private Global.System.Web.UI.WebControls.Button _btnOk;

    protected virtual Global.System.Web.UI.WebControls.Button btnOk
    {
        [MethodImpl(MethodImplOptions.Synchronized)]
        get
        {
            return _btnOk;
        }

        [MethodImpl(MethodImplOptions.Synchronized)]
        set
        {
            if (_btnOk != null)
            {
                _btnOk.Click -= btnOk_Click;
            }

            _btnOk = value;
            if (_btnOk != null)
            {
                _btnOk.Click += btnOk_Click;
            }
        }
    }
}

Details

  • [codeconverter.icsharpcode.net]/VS extension / both
  • Never saw it working.
  • If the Handles clause has the same case as the declaration, it works as expected.
@jrmoreno1 jrmoreno1 added the VB -> C# Specific to VB -> C# conversion label Mar 25, 2022
jrmoreno1 added a commit to jrmoreno1/CodeConverter that referenced this issue Mar 26, 2022
…ase for property with event, use semantic model to get official name of the property
GrahamTheCoder added a commit that referenced this issue Mar 26, 2022
Issue #854: Fix conversion error when Handle clause property differs by case from actual property
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

1 participant