@@ -18,7 +18,7 @@ internal enum TransportProtocol
1818
1919internal sealed class ConnectionStringBuilder
2020{
21- private readonly Dictionary < string , string > _parts = new Dictionary < string , string > ( StringComparer . Ordinal ) ;
21+ private readonly Dictionary < string , string > parts = new Dictionary < string , string > ( StringComparer . Ordinal ) ;
2222
2323 public ConnectionStringBuilder ( string connectionString )
2424 {
@@ -52,10 +52,10 @@ public ConnectionStringBuilder(string connectionString)
5252 throw new ArgumentException ( "Connection string cannot contain empty keys or values." ) ;
5353 }
5454
55- this . _parts [ key ] = value ;
55+ this . parts [ key ] = value ;
5656 }
5757
58- if ( this . _parts . Count == 0 )
58+ if ( this . parts . Count == 0 )
5959 {
6060 throw new ArgumentNullException ( nameof ( connectionString ) , $ "{ nameof ( connectionString ) } is invalid.") ;
6161 }
@@ -64,25 +64,25 @@ public ConnectionStringBuilder(string connectionString)
6464 public string EtwSession
6565 {
6666 get => this . ThrowIfNotExists < string > ( nameof ( this . EtwSession ) ) ;
67- set => this . _parts [ nameof ( this . EtwSession ) ] = value ;
67+ set => this . parts [ nameof ( this . EtwSession ) ] = value ;
6868 }
6969
7070 public string PrivatePreviewEnableTraceLoggingDynamic
7171 {
7272 get => this . ThrowIfNotExists < string > ( nameof ( this . PrivatePreviewEnableTraceLoggingDynamic ) ) ;
73- set => this . _parts [ nameof ( this . PrivatePreviewEnableTraceLoggingDynamic ) ] = value ;
73+ set => this . parts [ nameof ( this . PrivatePreviewEnableTraceLoggingDynamic ) ] = value ;
7474 }
7575
7676 public string PrivatePreviewEnableOtlpProtobufEncoding
7777 {
78- get => this . _parts . TryGetValue ( nameof ( this . PrivatePreviewEnableOtlpProtobufEncoding ) , out var value ) ? value : null ;
79- set => this . _parts [ nameof ( this . PrivatePreviewEnableOtlpProtobufEncoding ) ] = value ;
78+ get => this . parts . TryGetValue ( nameof ( this . PrivatePreviewEnableOtlpProtobufEncoding ) , out var value ) ? value : null ;
79+ set => this . parts [ nameof ( this . PrivatePreviewEnableOtlpProtobufEncoding ) ] = value ;
8080 }
8181
8282 public string Endpoint
8383 {
8484 get => this . ThrowIfNotExists < string > ( nameof ( this . Endpoint ) ) ;
85- set => this . _parts [ nameof ( this . Endpoint ) ] = value ;
85+ set => this . parts [ nameof ( this . Endpoint ) ] = value ;
8686 }
8787
8888 public TransportProtocol Protocol
@@ -92,9 +92,9 @@ public TransportProtocol Protocol
9292 try
9393 {
9494 // Checking Etw first, since it's preferred for Windows and enables fail fast on Linux
95- if ( this . _parts . ContainsKey ( nameof ( this . EtwSession ) ) )
95+ if ( this . parts . ContainsKey ( nameof ( this . EtwSession ) ) )
9696 {
97- _ = this . _parts . TryGetValue ( nameof ( this . PrivatePreviewEnableTraceLoggingDynamic ) , out var privatePreviewEnableTraceLoggingDynamic ) ;
97+ _ = this . parts . TryGetValue ( nameof ( this . PrivatePreviewEnableTraceLoggingDynamic ) , out var privatePreviewEnableTraceLoggingDynamic ) ;
9898 if ( privatePreviewEnableTraceLoggingDynamic != null && privatePreviewEnableTraceLoggingDynamic . Equals ( bool . TrueString , StringComparison . OrdinalIgnoreCase ) )
9999 {
100100 return TransportProtocol . EtwTld ;
@@ -103,7 +103,7 @@ public TransportProtocol Protocol
103103 return TransportProtocol . Etw ;
104104 }
105105
106- if ( ! this . _parts . ContainsKey ( nameof ( this . Endpoint ) ) )
106+ if ( ! this . parts . ContainsKey ( nameof ( this . Endpoint ) ) )
107107 {
108108 return TransportProtocol . Unspecified ;
109109 }
@@ -123,41 +123,11 @@ public TransportProtocol Protocol
123123 }
124124 }
125125
126- /// <summary>
127- /// Replace first charater of string if it matches with <paramref name="oldChar"/> with <paramref name="newChar"/>.
128- /// </summary>
129- /// <param name="str">String to be updated.</param>
130- /// <param name="oldChar">Old character to be replaced.</param>
131- /// <param name="newChar">New character to be replaced with.</param>
132- /// <returns>Updated string.</returns>
133- internal static string ReplaceFirstChar ( string str , char oldChar , char newChar )
134- {
135- if ( str . Length > 0 && str [ 0 ] == oldChar )
136- {
137- return $ "{ newChar } { str . Substring ( 1 ) } ";
138- }
139-
140- return str ;
141- }
142-
143- public string ParseUnixDomainSocketPath ( )
144- {
145- try
146- {
147- var endpoint = new Uri ( this . Endpoint ) ;
148- return ReplaceFirstChar ( endpoint . AbsolutePath , '@' , '\0 ' ) ;
149- }
150- catch ( UriFormatException ex )
151- {
152- throw new ArgumentException ( $ "{ nameof ( this . Endpoint ) } value is malformed.", ex ) ;
153- }
154- }
155-
156126 public int TimeoutMilliseconds
157127 {
158128 get
159129 {
160- if ( ! this . _parts . TryGetValue ( nameof ( this . TimeoutMilliseconds ) , out string value ) )
130+ if ( ! this . parts . TryGetValue ( nameof ( this . TimeoutMilliseconds ) , out string value ) )
161131 {
162132 return UnixDomainSocketDataTransport . DefaultTimeoutMilliseconds ;
163133 }
@@ -186,7 +156,7 @@ public int TimeoutMilliseconds
186156 ex ) ;
187157 }
188158 }
189- set => this . _parts [ nameof ( this . TimeoutMilliseconds ) ] = value . ToString ( CultureInfo . InvariantCulture ) ;
159+ set => this . parts [ nameof ( this . TimeoutMilliseconds ) ] = value . ToString ( CultureInfo . InvariantCulture ) ;
190160 }
191161
192162 public string Host
@@ -229,32 +199,62 @@ public int Port
229199 public string Account
230200 {
231201 get => this . ThrowIfNotExists < string > ( nameof ( this . Account ) ) ;
232- set => this . _parts [ nameof ( this . Account ) ] = value ;
202+ set => this . parts [ nameof ( this . Account ) ] = value ;
233203 }
234204
235205 public string Namespace
236206 {
237207 get => this . ThrowIfNotExists < string > ( nameof ( this . Namespace ) ) ;
238- set => this . _parts [ nameof ( this . Namespace ) ] = value ;
208+ set => this . parts [ nameof ( this . Namespace ) ] = value ;
239209 }
240210
241211 public bool DisableMetricNameValidation
242212 {
243213 get
244214 {
245- if ( ! this . _parts . TryGetValue ( nameof ( this . DisableMetricNameValidation ) , out var value ) )
215+ if ( ! this . parts . TryGetValue ( nameof ( this . DisableMetricNameValidation ) , out var value ) )
246216 {
247217 return false ;
248218 }
249219
250220 return string . Equals ( bool . TrueString , value , StringComparison . OrdinalIgnoreCase ) ;
251221 }
252- set => this . _parts [ nameof ( this . DisableMetricNameValidation ) ] = value ? bool . TrueString : bool . FalseString ;
222+ set => this . parts [ nameof ( this . DisableMetricNameValidation ) ] = value ? bool . TrueString : bool . FalseString ;
223+ }
224+
225+ public string ParseUnixDomainSocketPath ( )
226+ {
227+ try
228+ {
229+ var endpoint = new Uri ( this . Endpoint ) ;
230+ return ReplaceFirstChar ( endpoint . AbsolutePath , '@' , '\0 ' ) ;
231+ }
232+ catch ( UriFormatException ex )
233+ {
234+ throw new ArgumentException ( $ "{ nameof ( this . Endpoint ) } value is malformed.", ex ) ;
235+ }
236+ }
237+
238+ /// <summary>
239+ /// Replace first charater of string if it matches with <paramref name="oldChar"/> with <paramref name="newChar"/>.
240+ /// </summary>
241+ /// <param name="str">String to be updated.</param>
242+ /// <param name="oldChar">Old character to be replaced.</param>
243+ /// <param name="newChar">New character to be replaced with.</param>
244+ /// <returns>Updated string.</returns>
245+ internal static string ReplaceFirstChar ( string str , char oldChar , char newChar )
246+ {
247+ if ( str . Length > 0 && str [ 0 ] == oldChar )
248+ {
249+ return $ "{ newChar } { str . Substring ( 1 ) } ";
250+ }
251+
252+ return str ;
253253 }
254254
255255 private T ThrowIfNotExists < T > ( string name )
256256 {
257- if ( ! this . _parts . TryGetValue ( name , out var value ) )
257+ if ( ! this . parts . TryGetValue ( name , out var value ) )
258258 {
259259 throw new ArgumentException ( $ "'{ name } ' value is missing in connection string.") ;
260260 }
0 commit comments