diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Common/CommonExtensions.cs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs index 6f39d17f..9b6a3c6c 100644 --- a/src/slskd/Common/CommonExtensions.cs +++ b/src/slskd/Common/CommonExtensions.cs @@ -360,6 +360,17 @@ namespace slskd } /// <summary> + /// Casts the string to <typeparamref name="T"/>. + /// </summary> + /// <typeparam name="T">The Enum type to which to cast.</typeparam> + /// <param name="str">The string to cast.</param> + /// <returns>The cast enum</returns> + public static T ToEnum<T>(this string str) + { + return (T)Enum.Parse(typeof(T), str, ignoreCase: true); + } + + /// <summary> /// Deserializes this string from json to an object of type <typeparamref name="T"/>. /// </summary> /// <typeparam name="T">The type to which to deserialize the string.</typeparam> |
