入力として文字列のみを除外する COM オブジェクトのラッパーを作成したため、OOP の適切な実践として、ビルドと呼び出しが簡単になるように文字列を関数にラップしました。
誰かが次のコードを実行するためのより良い方法を考えられるかどうか疑問に思っていました.
Public Function OpenTable(ByVal TablePath As String, Optional ByVal OpenAs As String = Nothing, _
Optional ByVal Hide As Boolean = False, Optional ByVal AsReadOnly As Boolean = False, _
Optional ByVal Interactive As Boolean = True, Optional ByVal Password As String = Nothing, _
Optional ByVal NoIndex As Boolean = False, Optional ByVal ViewAutomatic As Boolean = True) As TableInfo
If String.IsNullOrEmpty(TablePath) Then
Throw New ArgumentNullException("TablePath", "TablePath cannot be null or empty")
End If
Dim Builder = New StringBuilder("Open Table ")
Builder.AppendFormat("{0}{1}{2}", ControlChars.Quote, TablePath, ControlChars.Quote)
If (Not String.IsNullOrEmpty(OpenAs)) Then Builder.AppendFormat(" as {0} ", OpenAs)
If (Hide) Then Builder.Append(" Hide ")
If (AsReadOnly) Then Builder.Append(" ReadOnly ")
If (Interactive) Then Builder.Append(" Interactive ")
If (Not String.IsNullOrEmpty(Password)) Then Builder.AppendFormat(" Password {0} ", Password)
If (NoIndex) Then Builder.Append(" NoIndex ")
If (ViewAutomatic) Then Builder.Append(" View Automatic ")
MyComApp.Do(Builder.ToString)
Dim FileInfo = New IO.FileInfo(TablePath)
Return New TableInfo(FileInfo.Name.Substring(0, InStrRev(FileInfo.Name, ".") - 1))
End Function
関数が取らなければならない引数の量は、私の最大の心配事です。これはそれほど悪くはありませんが、将来もっと多くの引数を取る必要がある他の関数がいくつかあるので、主に大きな引数関数を構築するためのより良い方法を探しています.