I'm really trying to follow the DRY principle. Do I have a sub that looks like this?
Private Sub DoSupplyModel
OutputLine("ITEM SUMMARIES")
Dim ItemSumms As New SupplyModel.ItemSummaries(_currentSupplyModel, _excelRows)
ItemSumms.FillRows()
OutputLine("")
OutputLine("NUMBERED INVENTORIES")
Dim numInvs As New SupplyModel.NumberedInventories(_currentSupplyModel, _excelRows)
numInvs.FillRows()
OutputLine("")
End Sub
I would like to roll them into one method using generics. For recording, ItemSummaries and NumberedInventories are produced from the same base class DataBuilderBase.
I can not understand the syntax that will allow me to do ItemSumms.FillRows and numInvs .FillRows in the method.
FillRows is declared as Public Overridable Sub FillRowsin the base class.
Thanks in advance.
EDIT
Here is my end result
Private Sub DoSupplyModels()
DoSupplyModelType("ITEM SUMMARIES",New DataBlocks(_currentSupplyModel,_excelRows)
DoSupplyModelType("DATA BLOCKS",New DataBlocks(_currentSupplyModel,_excelRows)
End Sub
Private Sub DoSupplyModelType(ByVal outputDescription As String, ByVal type As DataBuilderBase)
OutputLine(outputDescription)
type.FillRows()
OutputLine("")
End Sub
But to answer my question ... I could do it ...
Private Sub DoSupplyModels()
DoSupplyModelType(Of Projections)("ITEM SUMMARIES")
DoSupplyModelType(Of DataBlocks)("DATA BLOCKS")
End Sub
Private Sub DoSupplyModelType(Of T as DataBuilderBase)(ByVal outputDescription As String, ByVal type As T)
OutputLine(outputDescription)
Dim type as New DataBuilderBase (_currentSupplyModel,_excelRows)
type.FillRows()
OutputLine("")
End Sub
Is it correct?
Set
source
share