VB -> C#: injected base breaks overrides
See original GitHub issueInput 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.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
c# - How to break Execution of an override method from it's ...
One option would be to put all your actual OnNavigatedTo code in a separate method that is called by the base class OnNavigateTo....
Read more >Overrides - Visual Basic
In this article Specifies that a property or procedure overrides an identically named property or procedure inherited from a base class.
Read more >C# static code analysis: Overriding members should do ...
This rule ignores overrides of Equals and GetHashCode . NOTE: In some cases it might be dangerous to add or remove empty overrides,...
Read more >C# static code analysis | clumsy: Overriding members ...
Overriding a method just to call the same method from the base class without performing any other actions is useless and misleading. The...
Read more >Overrides of Method() should call base.Method()
Typically overrides of a base method, should refine or complete the behavior of the base method. If the base method is not called,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
Thanks, that’s great!