icsharpcode / CodeConverter

Convert code from C# to VB.NET and vice versa using Roslyn
https://icsharpcode.github.io/CodeConverter/
MIT License
826 stars 216 forks source link

VB -> C#: Statics with same name in getter and setter cause a CONVERSION ERROR #1054

Closed TymurGubayev closed 2 months ago

TymurGubayev commented 10 months ago

VB.Net input code

    Public Property Prop As String
        Get
            Static b As Boolean
            b = False
        End Get

        Set(ByVal s As String)
            Static b As Boolean
            b = False
        End Set
    End Property

Erroneous output

#error Cannot convert ClassBlockSyntax - see comment for details
    /* Cannot convert ClassBlockSyntax, CONVERSION ERROR: An item with the same key has already been added. in 'Public Class TestStaticsInS...' at character 0
       at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
       at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
       at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
       at ICSharpCode.CodeConverter.CSharp.PerScopeState.<CreateVbStaticFieldsAsync>d__20.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at ICSharpCode.CodeConverter.CSharp.DeclarationNodeVisitor.<>c__DisplayClass40_0.<<ConvertMembersAsync>b__1>d.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at ICSharpCode.CodeConverter.Common.AsyncEnumerableTaskExtensions.<SelectAsync>d__3`2.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at ICSharpCode.CodeConverter.Common.AsyncEnumerableTaskExtensions.<SelectManyAsync>d__0`2.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at ICSharpCode.CodeConverter.CSharp.DeclarationNodeVisitor.<ConvertMembersAsync>d__40.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at ICSharpCode.CodeConverter.CSharp.DeclarationNodeVisitor.<VisitClassBlock>d__46.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at ICSharpCode.CodeConverter.CSharp.CommentConvertingVisitorWrapper.<ConvertHandledAsync>d__12`1.MoveNext()
...
*/

Expected output

f.e. prefix accessor type:

        private bool _get_Prop_b;
        private bool _set_Prop_b;
        public string Prop
        {
            get
            {
                _get_Prop_b = false;
                return default;
            }

            set
            {
                _set_Prop_b = false;
            }
        }

Details

TymurGubayev commented 2 months ago

fixed in #1124