Last active
March 11, 2018 17:39
-
-
Save mk3008/03b423c6942599465510 to your computer and use it in GitHub Desktop.
区切り文字を追加するStringBuilder拡張メソッドとその例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Imports System.Runtime.CompilerServices | |
| Imports System.Text | |
| Public Module IDbCommandExtension | |
| ''' <summary> | |
| ''' DBコマンドの情報を返します | |
| ''' </summary> | |
| ''' <param name="source"></param> | |
| ''' <returns></returns> | |
| ''' <remarks></remarks> | |
| <Extension()> | |
| Public Function ToInfoString(source As IDbCommand) As String | |
| 'CommandText Info | |
| Dim s As New StringBuilder | |
| s.Append(source.CommandText) | |
| If source.Parameters.Count = 0 Then | |
| Return s.ToString | |
| End If | |
| s.AppendLine() | |
| 'Parameter Info | |
| Dim prms As New StringBuilder | |
| For Each item As IDataParameter In source.Parameters | |
| prms.AppendDelimiter(", ").AppendFormat("{0}={1}", item.ParameterName, item.Value.ToString) | |
| Next | |
| s.AppendFormat("--{0}", prms.ToString) | |
| Return s.ToString | |
| End Function | |
| End Module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Imports System.Runtime.CompilerServices | |
| Imports System.Text | |
| Public Module StringBuilderExtension | |
| ''' <summary> | |
| ''' 区切り文字を追加します。文字が存在しない場合は追加しません | |
| ''' </summary> | |
| ''' <param name="source"></param> | |
| ''' <param name="delimiter"></param> | |
| ''' <returns></returns> | |
| ''' <remarks></remarks> | |
| <Extension()> | |
| Public Function AppendDelimiter(source As StringBuilder, delimiter As String) As StringBuilder | |
| If source.Length <> 0 Then | |
| source.Append(delimiter) | |
| End If | |
| Return source | |
| End Function | |
| ''' <summary> | |
| ''' デコレートします | |
| ''' </summary> | |
| ''' <param name="source"></param> | |
| ''' <param name="format">{0}に現在値が入ります。</param> | |
| ''' <returns></returns> | |
| ''' <remarks><code>s.Decorate("({0})")</code></remarks> | |
| <Extension()> | |
| Public Function Decorate(ByRef source As StringBuilder, format As String) As StringBuilder | |
| Dim s As New StringBuilder | |
| s.AppendFormat(format, source.ToString) | |
| source = s | |
| Return source | |
| End Function | |
| End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment