Add and remove reaction from a content

This commit is contained in:
Dominic Villemure
2024-08-24 18:39:09 -04:00
parent 63dc032aa4
commit 588be7941c
17 changed files with 660 additions and 45 deletions

View File

@@ -0,0 +1,34 @@
namespace Hutopy.Web.Extensions;
public static class EnumExtensions
{
/// <summary>
/// Converts a string to the specified enum type.
/// </summary>
/// <typeparam name="TEnum">The type of the enum to convert to. Must be an enum.</typeparam>
/// <param name="value">The string value to convert.</param>
/// <param name="ignoreCase">Specifies whether the string comparison should ignore case. Default is true.</param>
/// <returns>
/// The corresponding enum value if the conversion is successful; otherwise, null if the string
/// cannot be converted to the specified enum type.
/// </returns>
public static TEnum? ToEnum<TEnum>(this string value, bool ignoreCase = true) where TEnum : struct
{
if (Enum.TryParse(value, ignoreCase, out TEnum result))
{
return result;
}
return null;
}
/// <summary>
/// Converts an enum value to its string representation.
/// </summary>
/// <typeparam name="TEnum">The type of the enum.</typeparam>
/// <param name="enumValue">The enum value to convert.</param>
/// <returns>The string representation of the enum value.</returns>
public static string FromEnum<TEnum>(this TEnum enumValue) where TEnum : struct, Enum
{
return enumValue.ToString();
}
}