From 523ece5b03e4eb5ff298da7257239a728ea1aab4 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 10 Sep 2022 17:37:50 -0500 Subject: add ToEnum --- src/slskd/Common/CommonExtensions.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') 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 @@ -359,6 +359,17 @@ namespace slskd obj.GetType().GetGenericTypeDefinition().IsAssignableFrom(typeof(Dictionary<,>)); } + /// + /// Casts the string to . + /// + /// The Enum type to which to cast. + /// The string to cast. + /// The cast enum + public static T ToEnum(this string str) + { + return (T)Enum.Parse(typeof(T), str, ignoreCase: true); + } + /// /// Deserializes this string from json to an object of type . /// -- cgit v1.2.3