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#: injected base breaks overrides #600

Closed
Thieum opened this issue Jul 29, 2020 · 5 comments
Closed

VB -> C#: injected base breaks overrides #600

Thieum opened this issue Jul 29, 2020 · 5 comments
Labels
VB -> C# Specific to VB -> C# conversion

Comments

@Thieum
Copy link

Thieum commented Jul 29, 2020

Input code

Private Sub FillAll()
         Clear()
         If Query IsNot Nothing AndAlso Not String.IsNullOrWhiteSpace(Query.CommandText) Then
            ValidateHelper()
            Try
               Using reader = _Helper.ExecuteReader(Query)
                  Dim fieldNames As New List(Of String)
                  For index = 0 To reader.FieldCount - 1
                     fieldNames.Add(reader.GetName(index))
                  Next
                  While reader.Read
                     Dim entity = BuildNewEntity() 
                     entity.InitializeData(reader, fieldNames)
                     AddNewEntity(entity)
                  End While
               End Using
            Catch ex As Exception
               Throw New DataAccessObjectException(SeikaORMClasses.ErrorOnFillAll, ex, Query, Nothing)
            End Try
         End If
      End Sub

BuildNewEntity is defined as this in the parent object:

        protected internal virtual T BuildNewEntity()
        {
            return new T();
        }

A child object redefines BuildNewEntity:

        protected override TestSEntity BuildNewEntity()
        {
            return new TestSEntity(_BusinessCache);
        }

Erroneous output

        private void FillAll()
        {
            Clear();
            if (Query is object && !string.IsNullOrWhiteSpace(Query.CommandText))
            {
                ValidateHelper();
                try
                {
                    using (var reader = _Helper.ExecuteReader(Query))
                    {
                        var fieldNames = new List<string>();
                        for (int index = 0, loopTo = reader.FieldCount - 1; index <= loopTo; index++)
                            fieldNames.Add(reader.GetName(index));
                        while (reader.Read())
                        {
                            var entity = base.BuildNewEntity(); 
                            entity.InitializeData(reader, fieldNames);
                            AddNewEntity(entity);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new DataAccessObjectException(SeikaORMClasses.ErrorOnFillAll, ex, Query, null);
                }
            }
        }

Expected output

        private void FillAll()
        {
            Clear();
            if (Query is object && !string.IsNullOrWhiteSpace(Query.CommandText))
            {
                ValidateHelper();
                try
                {
                    using (var reader = _Helper.ExecuteReader(Query))
                    {
                        var fieldNames = new List<string>();
                        for (int index = 0, loopTo = reader.FieldCount - 1; index <= loopTo; index++)
                            fieldNames.Add(reader.GetName(index));
                        while (reader.Read())
                        {
                            var entity = BuildNewEntity(); 
                            entity.InitializeData(reader, fieldNames);
                            AddNewEntity(entity);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new DataAccessObjectException(SeikaORMClasses.ErrorOnFillAll, ex, Query, null);
                }
            }
        }

Details

  • VS Extension v81.6.0

base should not be introduced when not needed - it will break the behavior silently when override is involved.

@Thieum Thieum added the VB -> C# Specific to VB -> C# conversion label Jul 29, 2020
@GrahamTheCoder
Copy link
Member

Thanks for this. I'm not immediately sure how that "base" call got there. I'll try to investigate this weekend.

Thieum added a commit to Thieum/VbnetToCSharpSuperfluousBase that referenced this issue Jul 30, 2020
@Thieum
Copy link
Author

Thieum commented Jul 30, 2020

@GrahamTheCoder I've setup a complete example at https://github.com/Thieum/VbnetToCSharpSuperfluousBase as it involves multiple assemblies and my first example could have been a pain to rework in a simpler example.

@GrahamTheCoder
Copy link
Member

Thanks, that's great!

@GrahamTheCoder
Copy link
Member

This is caused by a bug in the Roslyn library - one that I've actually had to work around before for a slightly different case.
I'll find a way to workaround this one, and then hopefully actually get around to PRing the fix to Roslyn too.

@Thieum
Copy link
Author

Thieum commented Aug 5, 2020

@GrahamTheCoder Thanks a lot !

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

2 participants