Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[csharp][generichost] fix syslib1045, use GeneratedRegex for .net7+ #20695

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using System.Runtime.CompilerServices;
/// <summary>
/// Utility functions providing some benefit to API client consumers.
/// </summary>
{{>visibility}} static class ClientUtils
{{>visibility}} static {{#net70OrLater}}partial {{/net70OrLater}}class ClientUtils
{
{{#useCompareNetObjects}}
/// <summary>
Expand Down Expand Up @@ -143,17 +143,6 @@ using System.Runtime.CompilerServices;
}
}

/// <summary>
/// Sanitize filename by removing the path
/// </summary>
/// <param name="filename">Filename</param>
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

/// <summary>
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
/// If parameter is a list, join the list with ",".
Expand Down Expand Up @@ -325,7 +314,13 @@ using System.Runtime.CompilerServices;
/// <summary>
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
/// </summary>
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
{{#net70OrLater}}
[GeneratedRegex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$")]
private static partial Regex JsonRegex();
{{/net70OrLater}}
{{^net70OrLater}}
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
{{/net70OrLater}}

/// <summary>
/// Check if the given MIME is a JSON MIME.
Expand All @@ -341,7 +336,7 @@ using System.Runtime.CompilerServices;
{
if (string.IsNullOrWhiteSpace(mime)) return false;

return JsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json");
return {{#net70OrLater}}JsonRegex(){{/net70OrLater}}{{^net70OrLater}}JsonRegex{{/net70OrLater}}.IsMatch(mime) || mime.Equals("application/json-patch+json");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Org.OpenAPITools.Client
/// <summary>
/// Utility functions providing some benefit to API client consumers.
/// </summary>
public static class ClientUtils
public static partial class ClientUtils
{

/// <summary>
Expand Down Expand Up @@ -109,17 +109,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
}
}

/// <summary>
/// Sanitize filename by removing the path
/// </summary>
/// <param name="filename">Filename</param>
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

/// <summary>
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
/// If parameter is a list, join the list with ",".
Expand Down Expand Up @@ -260,7 +249,8 @@ public static byte[] ReadAsBytes(Stream inputStream)
/// <summary>
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
/// </summary>
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
[GeneratedRegex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$")]
private static partial Regex JsonRegex();

/// <summary>
/// Check if the given MIME is a JSON MIME.
Expand All @@ -276,7 +266,7 @@ public static bool IsJsonMime(string mime)
{
if (string.IsNullOrWhiteSpace(mime)) return false;

return JsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json");
return JsonRegex().IsMatch(mime) || mime.Equals("application/json-patch+json");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
}
}

/// <summary>
/// Sanitize filename by removing the path
/// </summary>
/// <param name="filename">Filename</param>
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

/// <summary>
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
/// If parameter is a list, join the list with ",".
Expand Down Expand Up @@ -245,7 +234,7 @@ public static string SelectHeaderAccept(string[] accepts)
/// <summary>
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
/// </summary>
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");

/// <summary>
/// Check if the given MIME is a JSON MIME.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
}
}

/// <summary>
/// Sanitize filename by removing the path
/// </summary>
/// <param name="filename">Filename</param>
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

/// <summary>
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
/// If parameter is a list, join the list with ",".
Expand Down Expand Up @@ -245,7 +234,7 @@ public static string SelectHeaderAccept(string[] accepts)
/// <summary>
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
/// </summary>
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");

/// <summary>
/// Check if the given MIME is a JSON MIME.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
}
}

/// <summary>
/// Sanitize filename by removing the path
/// </summary>
/// <param name="filename">Filename</param>
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

/// <summary>
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
/// If parameter is a list, join the list with ",".
Expand Down Expand Up @@ -230,7 +219,7 @@ public static string SelectHeaderAccept(string[] accepts)
/// <summary>
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
/// </summary>
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");

/// <summary>
/// Check if the given MIME is a JSON MIME.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
}
}

/// <summary>
/// Sanitize filename by removing the path
/// </summary>
/// <param name="filename">Filename</param>
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

/// <summary>
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
/// If parameter is a list, join the list with ",".
Expand Down Expand Up @@ -345,7 +334,7 @@ public static string SelectHeaderAccept(string[] accepts)
/// <summary>
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
/// </summary>
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");

/// <summary>
/// Check if the given MIME is a JSON MIME.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
}
}

/// <summary>
/// Sanitize filename by removing the path
/// </summary>
/// <param name="filename">Filename</param>
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

/// <summary>
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
/// If parameter is a list, join the list with ",".
Expand Down Expand Up @@ -245,7 +234,7 @@ public static string SelectHeaderAccept(string[] accepts)
/// <summary>
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
/// </summary>
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");

/// <summary>
/// Check if the given MIME is a JSON MIME.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
}
}

/// <summary>
/// Sanitize filename by removing the path
/// </summary>
/// <param name="filename">Filename</param>
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

/// <summary>
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
/// If parameter is a list, join the list with ",".
Expand Down Expand Up @@ -349,7 +338,7 @@ public static string SelectHeaderAccept(string[] accepts)
/// <summary>
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
/// </summary>
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");

/// <summary>
/// Check if the given MIME is a JSON MIME.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
}
}

/// <summary>
/// Sanitize filename by removing the path
/// </summary>
/// <param name="filename">Filename</param>
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

/// <summary>
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
/// If parameter is a list, join the list with ",".
Expand Down Expand Up @@ -230,7 +219,7 @@ public static string SelectHeaderAccept(string[] accepts)
/// <summary>
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
/// </summary>
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");

/// <summary>
/// Check if the given MIME is a JSON MIME.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
}
}

/// <summary>
/// Sanitize filename by removing the path
/// </summary>
/// <param name="filename">Filename</param>
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

/// <summary>
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
/// If parameter is a list, join the list with ",".
Expand Down Expand Up @@ -245,7 +234,7 @@ public static string SelectHeaderAccept(string[] accepts)
/// <summary>
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
/// </summary>
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");

/// <summary>
/// Check if the given MIME is a JSON MIME.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
}
}

/// <summary>
/// Sanitize filename by removing the path
/// </summary>
/// <param name="filename">Filename</param>
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

/// <summary>
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
/// If parameter is a list, join the list with ",".
Expand Down Expand Up @@ -245,7 +234,7 @@ public static string SelectHeaderAccept(string[] accepts)
/// <summary>
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
/// </summary>
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");

/// <summary>
/// Check if the given MIME is a JSON MIME.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
}
}

/// <summary>
/// Sanitize filename by removing the path
/// </summary>
/// <param name="filename">Filename</param>
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

/// <summary>
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
/// If parameter is a list, join the list with ",".
Expand Down Expand Up @@ -230,7 +219,7 @@ public static string SelectHeaderAccept(string[] accepts)
/// <summary>
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
/// </summary>
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");

/// <summary>
/// Check if the given MIME is a JSON MIME.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,6 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
}
}

/// <summary>
/// Sanitize filename by removing the path
/// </summary>
/// <param name="filename">Filename</param>
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

/// <summary>
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
/// If parameter is a list, join the list with ",".
Expand Down Expand Up @@ -345,7 +334,7 @@ public static string SelectHeaderAccept(string[] accepts)
/// <summary>
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
/// </summary>
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
private static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");

/// <summary>
/// Check if the given MIME is a JSON MIME.
Expand Down
Loading
Loading