-
-
Save kekoa-/dfdbafbcfa2bea6d44582bd2e56b682c to your computer and use it in GitHub Desktop.
StringBuilder extension method to add delimiter and example
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> | |
| ''' Return DB command information | |
| ''' </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> | |
| ''' Add delimiter. If the character does not exist, it will not be added | |
| ''' </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> | |
| ''' Decorate | |
| ''' </summary> | |
| ''' <param name="source"></param> | |
| ''' <param name = "format"> {0} contains the current value. </ 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