@IanK is there a way to know which kind of file you have at the outset ?
Interfaces &/or subclasses might be a better option
For instance, to read the Xojo project files since there are 3 formats there might be a general ProjectReaderClass
Based on reading the first few bytes of the file you can tell which subclass you need , crate that and invoke its ReadProject method and it does the right thing
IF you can know that at the outset then thats one way to handle this
We do know pretty much very early on. However, the two files are virtually identical in layout. There are columns added and removed between the two. Extra rows for additional data etc. Maintaining two separate code bases for the two file types would be pretty annoying and dangerous. I am certainly attempting to avoid creating two completely separate reading methods. It is far simpler to add the odd:
if FileFormat = 1 then
' Deal with this column
end if
Type sections within the one routine. Our enums where column or row indices but now we need a flexible way of using them based on the type of file we are working with for this run.
The problem comes from it being an xlsx file. Basically a big chunk of xml and having to read it sequentially, spotting column and row numbers as you go. Depending on the file the row and column numbers with the correct data change somewhat. Thus the prior Enums. The struct system I came up with effectively allows me to keep the reader code structure but change the row numbers to suite. It also allows me to have column letter based structures ie string based enums, sort of.
Which I did. I created a structure and a shared property and filled it with a shared method. I can then access the members as if they were an enumeration.
Not tested, just for concept, but seem to fit the use of classes carrying named values and lists of them:
Class PolyEnum
// Just the base class
End Class
Class Table1 Inherits PolyEnum
Const lineKindX = 12
Const lineKindY = 27
Shared Function ListOfLines() As Integer()
Return Array ( lineKindX, lineKindY )
End Function
End Class
Class Table2 Inherits PolyEnum
Const lineKindX = 12
Const lineKindY = 33
Shared Function ListOfLines() As Integer()
Return Array ( lineKindX, lineKindY )
End Function
End Class
Class Table3 Inherits PolyEnum
Const lineKindX = 12
Const lineKindY = 27
Const lineKindZ = 44
Shared Function ListOfLines() As Integer()
Return Array ( lineKindX, lineKindY, lineKindZ )
End Function
End Class
// Dummy example of processing a PolyEnum subclass
Sub ProcessTable(tableLines As PolyEnum)
Var lines() As Integer
Select case tableLines
Case IsA Table1
Var t As Table1 = Table1(tableLines)
lines = t.ListOfLines
For Each i As Integer in lines
Select Case i
Case t.lineKindX
//
Case t.lineKindY
//
End
Next
Case IsA Table2
Var t As Table2 = Table2(tableLines)
lines = t.ListOfLines
For Each i As Integer in lines
Select Case i
Case t.lineKindX
//
Case t.lineKindY
//
// Case t.lineKindZ : Z does not exists here
//
End
Next
Case IsA Table3
Var t As Table3 = Table3(tableLines)
lines = t.ListOfLines
For Each i As Integer in lines
Select Case i
Case t.lineKindX
//
Case t.lineKindY
//
Case t.lineKindZ
//
End
Next
End
End Sub