다음 코드에서 거의 동일한 두 개의 Select Cases가 있으며 모든 경우가 거의 동일합니다. 그들은 서로 다른 매개 변수를 사용하여 오버로드 된 생성자를 사용하기 때문에 단일 함수에 넣을 수있는 방법을 찾아 낼 수 없습니다. 모두에서이 작업을 수행 할 수있는 방법은 (이상적으로 엄격한 제네릭 또는 반사 및 옵션을 사용하지 않고?) 거기에반복적 인 선택 선택
Sub Main() 'for testing, this currently converts csv to csv
inputPath = Environment.GetCommandLineArgs(1)
inputType = Environment.GetCommandLineArgs(2).ToUpper
outputPath = Environment.GetCommandLineArgs(3)
outputType = Environment.GetCommandLineArgs(4).ToUpper
'Grab Input
Select Case inputType
Case "CSV"
inputSpreadSheet = New CSV(inputPath)
Case "XLS"
inputSpreadSheet = New XLS(inputPath)
Case "XLSX"
Throw New NotImplementedException()
Case "PIPE"
Throw New NotImplementedException()
Case Else
Throw New Exception(inputType & " Is not a valid input type.")
End Select
'Convert Input to Intermediate Format
intermediateSpreadSheet = inputSpreadSheet.ToIntermediate()
'Convert Intermediate to output Format
Select Case outputType
Case "CSV"
outputSpreadSheet = New CSV(intermediateSpreadSheet)
Case "XLS"
outputSpreadSheet = New XLS(intermediateSpreadSheet)
Case "XLSX"
Throw New NotImplementedException()
Case "PIPE"
Throw New NotImplementedException()
Case Else
Throw New Exception(outputType & " Is not a valid output type.")
End Select
'Generate output file
outputSpreadSheet.Export(outputPath)
End Sub
생성자의 매개 변수가 각각의 선택 블록의 서로 다른 유형의 때문에, 나는 어떤 방법을 알고 그들을 결합하기.
실제로는 반복적이지 않으며, 2 가지 다른 것들을 테스트하고 다른 결과를 생성합니다. – Plutonix