我有以下代碼,我的老闆要我減少代碼行來做這個工作。在這個vb.net代碼中可以減少代碼行嗎?
Private Function getClientSheetNames(Optional ByVal type As String = "all") As List(Of String)
If type = "extra" Then
Return clientExtraSheetNames
End If
Dim prev, curr As New List(Of String)
For Each name In clientMonthlySheetNames
curr.Add(name + " (" + currMonth + ")")
Next name
If type = "currMonth" Then
Return curr
End If
For i = 1 To clientMonthlySheetNames.Count - 1
prev.Add(clientMonthlySheetNames(i) + " (" + prevMonth + ")")
Next
If type = "prevMonth" Then
Return prev
End If
If type = "monthly" Then
Return curr.Union(prev).ToList
End If
Return clientExtraSheetNames.Union(curr.Union(prev)).ToList
End Function
Private Function getDevSheetNames(Optional ByVal type As String = "all") As List(Of String)
If type = "extra" Then
Return devExtraSheetNames
End If
Dim sheetNames, prev, curr As New List(Of String)
For Each name In devMonthlySheetNames
curr.Add(name + " (" + currMonth + ")")
Next name
If type = "currMonth" Then
Return curr
End If
For Each name In devMonthlySheetNames
prev.Add(name + " (" + prevMonth + ")")
Next name
If type = "prevMonth" Then
Return prev
End If
If type = "monthly" Then
Return curr.Union(prev).ToList
End If
sheetNames.Add(devExtraSheetNames(0))
sheetNames.AddRange(curr.Union(prev).ToList)
sheetNames.AddRange(devExtraSheetNames.GetRange(1, devExtraSheetNames.Count - 1))
Return sheetNames
End Function
我無法弄清楚如何切割線條並具有相同的功能!
是否有任何vb.net構造可以通過更好的實現來減少loc?
我可以從getClientSheetNames和getDevSheetNames調用一個新的函數來實現代碼resue嗎?
我可以在可能的新函數中引入多態嗎?
任何性能改進都非常值得歡迎!
請幫忙!!
「我的僱主希望我減少代碼以完成這項工作。」 - 爲什麼? –
嗯,我不知道!他認爲我做了一個非常糟糕的實現,所以如果我減少LOC,我會改進邏輯。 –
改善邏輯與減少代碼行數有些不同(也是更重要的)要求(儘管有時是相關的) –