Skip to content

Commit

Permalink
Refactor and enhance codebase for .NET 9.0 upgrade
Browse files Browse the repository at this point in the history
Updated .editorconfig to disable specific naming rule warnings.
Refactored exception classes to include remarks and simplify constructors.
Changed return type of GetEnumMemberValue to nullable string.
Refactored StringExtensions to use var for local variables.
Expanded CountryCodeHelper to map three-digit country codes.
Removed new() constraint from GetAsync<T> in INhlApiHttpClient.
Made HttpClient property nullable in INhlApiHttpClient.
Refactored NhlApiHttpClient constructor to use property initializers.
Added null checks and exception handling in GetAsync<T>.
Replaced ServicePointManager settings with property initializers.
Updated HttpClient usages to handle potential null values.
Replaced object with Lock for thread synchronization.
Added #pragma directives to suppress nullable warnings.
Updated TryGetAsync<T> in ICachingService to return nullable type.
Simplified initialization of ConcurrentDictionary in CachingService.
Updated NhlApiAsyncHelper to use simplified TaskFactory initialization.
Updated model classes to use required keyword for properties.
Targeted .NET 9.0 and incremented version to 3.7.0 in project file.
Removed redundant using directives and added necessary ones.
Simplified initialization of static fields in various classes.
Added CultureInfo.InvariantCulture to string operations.
Refactored tests to improve consistency and readability.
Added InvalidTeamAbbreviationException for error handling.
  • Loading branch information
Afischbacher committed Feb 24, 2025
1 parent 056cdf8 commit a7c7ee6
Show file tree
Hide file tree
Showing 94 changed files with 1,928 additions and 1,155 deletions.
8 changes: 7 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,10 @@ dotnet_naming_rule.parameters_rule.severity = warning
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
##########################################
##########################################

# CA1707: Identifiers should not contain underscores
dotnet_diagnostic.CA1707.severity = none

# IDE1006: Remove warning for underscores
dotnet_diagnostic.IDE1006.severity = none
12 changes: 4 additions & 8 deletions Nhl.Api.Common/Exceptions/InvalidPlayerPositionException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ namespace Nhl.Api.Common.Exceptions;
/// <summary>
/// An exception for when a request is made to the Nhl.Api and the player/goalie position is invalid
/// </summary>
public class InvalidPlayerPositionException : Exception
/// <remarks>
/// An exception for when a request is made to the Nhl.Api and the player/goalie position is invalid
/// </remarks>
public class InvalidPlayerPositionException(string message) : Exception(message)
{
/// <summary>
/// An exception for when a request is made to the Nhl.Api and the player/goalie position is invalid
/// </summary>
public InvalidPlayerPositionException(string message) : base(message)
{

}
}
12 changes: 4 additions & 8 deletions Nhl.Api.Common/Exceptions/InvalidSeasonException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ namespace Nhl.Api.Common.Exceptions;
/// <summary>
/// An exception when the season year entered is not a valid NHL season
/// </summary>
public class InvalidSeasonException : Exception
/// <remarks>
/// An exception when the season year entered is not a valid NHL season
/// </remarks>
public class InvalidSeasonException(string message) : Exception(message)
{
/// <summary>
/// An exception when the season year entered is not a valid NHL season
/// </summary>
public InvalidSeasonException(string message) : base(message)
{

}
}
14 changes: 14 additions & 0 deletions Nhl.Api.Common/Exceptions/InvalidTeamAbbreviationException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace Nhl.Api.Common.Exceptions;

/// <summary>
/// This exception is thrown when an invalid team abbreviation is used
/// </summary>
public class InvalidTeamAbbreviationException(string message) : Exception
{
/// <summary>
/// The exception message
/// </summary>
public override string Message => message;
}
12 changes: 4 additions & 8 deletions Nhl.Api.Common/Exceptions/NhlApiRequestException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ namespace Nhl.Api.Common.Exceptions;
/// <summary>
/// An exception for a failed Nhl.Api HTTP request
/// </summary>
public class NhlApiRequestException : Exception
/// <remarks>
/// An exception for a failed Nhl.Api HTTP request
/// </remarks>
public class NhlApiRequestException(string message) : Exception(message)
{
/// <summary>
/// An exception for a failed Nhl.Api HTTP request
/// </summary>
public NhlApiRequestException(string message) : base(message)
{

}
}
2 changes: 1 addition & 1 deletion Nhl.Api.Common/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class EnumExtensions
/// <typeparam name="T">The enumeration type</typeparam>
/// <param name="value">The value of the enumerations</param>
/// <returns>The string value of the enumeration based on the attribute <see cref="EnumMemberAttribute"/></returns>
public static string GetEnumMemberValue<T>(this T value) where T : Enum => typeof(T)
public static string? GetEnumMemberValue<T>(this T value) where T : Enum => typeof(T)
.GetTypeInfo()
.DeclaredMembers
.SingleOrDefault(x => x.Name == value.ToString())
Expand Down
6 changes: 3 additions & 3 deletions Nhl.Api.Common/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public static class StringExtensions
public static string ReplaceNonAsciiWithAscii(this string input)
{
// Define a regular expression pattern for non-ASCII characters
string pattern = @"[^\x00-\x7F]";
var pattern = @"[^\x00-\x7F]";

// Replace non-ASCII characters with their ASCII equivalents
string output = Regex.Replace(input, pattern, (match) =>
var output = Regex.Replace(input, pattern, (match) =>
{
char c = match.Value[0];
var c = match.Value[0];
return c switch
{
'À' or 'Á' or 'Â' or 'Ã' or 'Ä' => "A",
Expand Down
Loading

0 comments on commit a7c7ee6

Please sign in to comment.