@@ -103,6 +103,21 @@ public static void StartProfileOptimization(string CachePath = null)
103103 ProfileOptimization . SetProfileRoot ( CachePath ) ;
104104 ProfileOptimization . StartProfile ( "Profile" ) ;
105105 }
106+
107+
108+ /// <summary>
109+ /// Retrieves an enumeration value from a string representation. It requires the generic type to be an enum.
110+ /// </summary>
111+ /// <typeparam name="TEnum">The generic type must be an enumeration type to convert the string into its corresponding enum value.</typeparam>
112+ /// <param name="text">The string representation of the enumeration value to be converted.</param>
113+ /// <returns>The corresponding enumeration value of the specified type.</returns>
114+ /// <exception cref="InvalidOperationException">Thrown when the generic type parameter is not an enumeration.</exception>
115+ public static TEnum GetEnum < TEnum > ( string text ) where TEnum : struct
116+ {
117+ return ! typeof ( TEnum ) . GetTypeInfo ( ) . IsEnum
118+ ? throw new InvalidOperationException ( "Generic parameter 'TEnum' must be an enum." )
119+ : ( TEnum ) Enum . Parse ( typeof ( TEnum ) , text ) ;
120+ }
106121#endif
107122
108123 /// <summary>
@@ -151,19 +166,5 @@ public static string GetExecutablePathNative()
151166 InteropMethods . GetModuleFileName ( IntPtr . Zero , sb , MAX_PATH ) ;
152167 return sb . ToString ( ) ;
153168 }
154-
155- /// <summary>
156- /// Retrieves an enumeration value from a string representation. It requires the generic type to be an enum.
157- /// </summary>
158- /// <typeparam name="TEnum">The generic type must be an enumeration type to convert the string into its corresponding enum value.</typeparam>
159- /// <param name="text">The string representation of the enumeration value to be converted.</param>
160- /// <returns>The corresponding enumeration value of the specified type.</returns>
161- /// <exception cref="InvalidOperationException">Thrown when the generic type parameter is not an enumeration.</exception>
162- public static TEnum GetEnum < TEnum > ( string text ) where TEnum : struct
163- {
164- return ! typeof ( TEnum ) . GetTypeInfo ( ) . IsEnum
165- ? throw new InvalidOperationException ( "Generic parameter 'TEnum' must be an enum." )
166- : ( TEnum ) Enum . Parse ( typeof ( TEnum ) , text ) ;
167- }
168169}
169170
0 commit comments