Skip to content

Commit

Permalink
fix: Fixed missing xml doc for PathBuilder.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Sep 20, 2024
1 parent 7262bfe commit 6bbd968
Show file tree
Hide file tree
Showing 46 changed files with 4,508 additions and 40 deletions.
118 changes: 98 additions & 20 deletions src/libs/AutoSDK/Sources/Sources.PathBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ public static string GeneratePathBuilder(
namespace {settings.Namespace}
{{
/// <summary>
/// A helper class to build URL paths with optional and required parameters.
/// </summary>
public class PathBuilder
{{
private readonly global::System.Text.StringBuilder _stringBuilder =
new global::System.Text.StringBuilder(capacity: 256);
private bool _firstParameter = true;
/// <summary>
/// Initializes a new instance of the <see cref=""PathBuilder""/> class.
/// </summary>
/// <param name=""path"">The base path for the URL.</param>
/// <param name=""baseUri"">The base URI to prepend to the path, if any.</param>
public PathBuilder(
string path,
global::System.Uri? baseUri = null)
Expand All @@ -29,10 +37,16 @@ public PathBuilder(
{{
_stringBuilder.Append(baseUri.AbsoluteUri.TrimEnd('/'));
}}
_stringBuilder.Append(path);
}}
/// <summary>
/// Adds a required parameter to the URL.
/// </summary>
/// <param name=""name"">The name of the parameter.</param>
/// <param name=""value"">The value of the parameter.</param>
/// <returns>The current <see cref=""PathBuilder""/> instance.</returns>
public PathBuilder AddRequiredParameter(
string name,
string value)
Expand All @@ -50,10 +64,18 @@ public PathBuilder AddRequiredParameter(
_stringBuilder.Append(global::System.Uri.EscapeDataString(name));
_stringBuilder.Append('=');
_stringBuilder.Append(global::System.Uri.EscapeDataString(value));
return this;
}}
/// <summary>
/// Adds a required parameter with multiple values to the URL.
/// </summary>
/// <param name=""name"">The name of the parameter.</param>
/// <param name=""value"">The values of the parameter.</param>
/// <param name=""delimiter"">The delimiter to use between values.</param>
/// <param name=""explode"">Whether to explode the values into separate parameters.</param>
/// <returns>The current <see cref=""PathBuilder""/> instance.</returns>
public PathBuilder AddRequiredParameter(
string name,
global::System.Collections.Generic.IEnumerable<string> value,
Expand All @@ -69,12 +91,22 @@ public PathBuilder AddRequiredParameter(
return this;
}}
AddRequiredParameter(name, string.Join(delimiter, value));
return this;
}}
/// <summary>
/// Adds a required parameter with multiple values to the URL, using a selector function.
/// </summary>
/// <typeparam name=""T"">The type of the values.</typeparam>
/// <param name=""name"">The name of the parameter.</param>
/// <param name=""value"">The values of the parameter.</param>
/// <param name=""selector"">The function to select the string representation of each value.</param>
/// <param name=""delimiter"">The delimiter to use between values.</param>
/// <param name=""explode"">Whether to explode the values into separate parameters.</param>
/// <returns>The current <see cref=""PathBuilder""/> instance.</returns>
public PathBuilder AddRequiredParameter<T>(
string name,
global::System.Collections.Generic.IEnumerable<T> value,
Expand All @@ -83,10 +115,16 @@ public PathBuilder AddRequiredParameter<T>(
bool explode = false)
{{
AddRequiredParameter(name, value.Select(selector).ToArray(), delimiter, explode);
return this;
}}
/// <summary>
/// Adds an optional parameter to the URL.
/// </summary>
/// <param name=""name"">The name of the parameter.</param>
/// <param name=""value"">The value of the parameter, or null if not present.</param>
/// <returns>The current <see cref=""PathBuilder""/> instance.</returns>
public PathBuilder AddOptionalParameter(
string name,
string? value)
Expand All @@ -95,10 +133,18 @@ public PathBuilder AddOptionalParameter(
{{
AddRequiredParameter(name, value);
}}
return this;
}}
/// <summary>
/// Adds an optional parameter with multiple values to the URL.
/// </summary>
/// <param name=""name"">The name of the parameter.</param>
/// <param name=""value"">The values of the parameter, or null if not present.</param>
/// <param name=""delimiter"">The delimiter to use between values.</param>
/// <param name=""explode"">Whether to explode the values into separate parameters.</param>
/// <returns>The current <see cref=""PathBuilder""/> instance.</returns>
public PathBuilder AddOptionalParameter(
string name,
global::System.Collections.Generic.IEnumerable<string>? value,
Expand All @@ -109,10 +155,20 @@ public PathBuilder AddOptionalParameter(
{{
AddRequiredParameter(name, value, delimiter, explode);
}}
return this;
}}
/// <summary>
/// Adds an optional parameter with multiple values to the URL, using a selector function.
/// </summary>
/// <typeparam name=""T"">The type of the values.</typeparam>
/// <param name=""name"">The name of the parameter.</param>
/// <param name=""value"">The values of the parameter, or null if not present.</param>
/// <param name=""selector"">The function to select the string representation of each value.</param>
/// <param name=""delimiter"">The delimiter to use between values.</param>
/// <param name=""explode"">Whether to explode the values into separate parameters.</param>
/// <returns>The current <see cref=""PathBuilder""/> instance.</returns>
public PathBuilder AddOptionalParameter<T>(
string name,
global::System.Collections.Generic.IEnumerable<T>? value,
Expand All @@ -124,10 +180,19 @@ public PathBuilder AddOptionalParameter<T>(
{{
AddRequiredParameter(name, value.Select(selector).ToArray(), delimiter, explode);
}}
return this;
}}
/// <summary>
/// Adds a required parameter to the URL, using a formattable value.
/// </summary>
/// <typeparam name=""T"">The type of the value.</typeparam>
/// <param name=""name"">The name of the parameter.</param>
/// <param name=""value"">The value of the parameter.</param>
/// <param name=""format"">The format string.</param>
/// <param name=""formatProvider"">The format provider.</param>
/// <returns>The current <see cref=""PathBuilder""/> instance.</returns>
public PathBuilder AddRequiredParameter<T>(
string name,
T value,
Expand All @@ -136,10 +201,19 @@ public PathBuilder AddRequiredParameter<T>(
where T : global::System.IFormattable
{{
AddRequiredParameter(name, value.ToString(format, formatProvider));
return this;
}}
/// <summary>
/// Adds an optional parameter to the URL, using a formattable value.
/// </summary>
/// <typeparam name=""T"">The type of the value.</typeparam>
/// <param name=""name"">The name of the parameter.</param>
/// <param name=""value"">The value of the parameter, or null if not present.</param>
/// <param name=""format"">The format string.</param>
/// <param name=""formatProvider"">The format provider.</param>
/// <returns>The current <see cref=""PathBuilder""/> instance.</returns>
public PathBuilder AddOptionalParameter<T>(
string name,
T? value,
Expand All @@ -151,10 +225,14 @@ public PathBuilder AddOptionalParameter<T>(
{{
AddOptionalParameter(name, value.ToString(format, formatProvider));
}}
return this;
}}
/// <summary>
/// Returns the constructed URL as a string.
/// </summary>
/// <returns>The constructed URL.</returns>
public override string ToString() => _stringBuilder.ToString();
}}
}}".RemoveBlankLinesWhereOnlyWhitespaces();
Expand Down
Loading

0 comments on commit 6bbd968

Please sign in to comment.