Skip to content

Commit

Permalink
Make members of ConnectionStringBuilder readonly as per recommendation
Browse files Browse the repository at this point in the history
  • Loading branch information
mburumaxwell committed May 16, 2024
1 parent 363500d commit fc9bed4
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/Tingle.Extensions.Primitives/ConnectionStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public ConnectionStringBuilder(char segmentsSeparator = DefaultSegmentsSeparator
/// <typeparam name="T">the type of item to be returned</typeparam>
/// <param name="key">the key identifying the segment</param>
/// <returns></returns>
public T? GetValue<T>(string key)
public readonly T? GetValue<T>(string key)
{
if (TryGetValue(key, out var value) && !string.IsNullOrWhiteSpace(value))
{
Expand Down Expand Up @@ -244,7 +244,7 @@ private static KeyValuePair<string, string> ExtractSegment(string segment, char
private const string SegmentNameHostname = "Hostname";

/// <summary>Gets the value for <c>Key</c> used in authentication.</summary>
public string? GetKey() => GetValue<string>(SegmentNameKey);
public readonly string? GetKey() => GetValue<string>(SegmentNameKey);

/// <summary>Sets value for <c>Key</c> used in authentication.</summary>
/// <param name="key"></param>
Expand All @@ -255,17 +255,17 @@ public ConnectionStringBuilder WithKey(string key)
}

/// <summary>Gets the value for <c>Scheme</c> used in making requests.</summary>
public string? GetScheme() => GetValue<string>(SegmentNameScheme);
public readonly string? GetScheme() => GetValue<string>(SegmentNameScheme);

/// <summary>Gets value indicating if the <c>Scheme</c> for making requests is set to <paramref name="scheme"/>.</summary>
/// <param name="scheme"></param>
public bool IsScheme(string scheme) => string.Equals(scheme, GetScheme());
public readonly bool IsScheme(string scheme) => string.Equals(scheme, GetScheme());

/// <summary>Gets value indicating if the <c>Scheme</c> for making requests is set to <c>https</c>.</summary>
public bool IsHttpsScheme() => IsScheme(Uri.UriSchemeHttps);
public readonly bool IsHttpsScheme() => IsScheme(Uri.UriSchemeHttps);

/// <summary>Gets value indicating if the <c>Scheme</c> for making requests is set to <c>http</c>.</summary>
public bool IsHttpScheme() => IsScheme(Uri.UriSchemeHttp);
public readonly bool IsHttpScheme() => IsScheme(Uri.UriSchemeHttp);

/// <summary>Sets value for <c>Scheme</c> used in making requests.</summary>
/// <param name="scheme"></param>
Expand All @@ -284,7 +284,7 @@ public ConnectionStringBuilder WithHttpScheme()
=> WithScheme(Uri.UriSchemeHttp);

/// <summary>Gets the value for <c>Hostname</c> (usually the FQDN with the port, if needed) used in making the requests.</summary>
public string? GetHostname() => GetValue<string>(SegmentNameHostname);
public readonly string? GetHostname() => GetValue<string>(SegmentNameHostname);

/// <summary>Sets the value for <c>Hostname</c> (usually the FQDN with the port, if needed) used in making the requests.</summary>
/// <param name="hostname"></param>
Expand Down Expand Up @@ -340,10 +340,10 @@ public override readonly string ToString()
}

/// <inheritdoc/>
public override bool Equals(object? obj) => obj is ConnectionStringBuilder builder && Equals(builder);
public override readonly bool Equals(object? obj) => obj is ConnectionStringBuilder builder && Equals(builder);

/// <inheritdoc/>
public bool Equals(ConnectionStringBuilder other) => string.Equals(ToString(), other.ToString());
public readonly bool Equals(ConnectionStringBuilder other) => string.Equals(ToString(), other.ToString());

/// <inheritdoc/>
public override readonly int GetHashCode() => HashCode.Combine(segments, segmentsSeparator, valueSeparator);
Expand Down Expand Up @@ -400,7 +400,7 @@ public static implicit operator ConnectionStringBuilder(string connectionString)
readonly long IConvertible.ToInt64(IFormatProvider? provider) => throw new InvalidCastException();
readonly sbyte IConvertible.ToSByte(IFormatProvider? provider) => throw new InvalidCastException();
readonly float IConvertible.ToSingle(IFormatProvider? provider) => throw new InvalidCastException();
string IConvertible.ToString(IFormatProvider? provider) => ToString();
readonly string IConvertible.ToString(IFormatProvider? provider) => ToString();

readonly object IConvertible.ToType(Type conversionType, IFormatProvider? provider)
{
Expand Down

0 comments on commit fc9bed4

Please sign in to comment.