<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Signum.Utilities.Reflection;
using System.ComponentModel;
using System.Reflection;
using System.Collections.Concurrent;

namespace Signum.Utilities
{
    public static class EnumExtensions
    {
        public static T ToEnum<T>(this string str) where T : struct
        {
            return (T)Enum.Parse(typeof(T), str);
        }

        public static T ToEnum<T>(this string str, bool ignoreCase) where T : struct
        {
            return (T)Enum.Parse(typeof(T), str, ignoreCase);
        }

        public static T[] GetValues<T>()
        {<commit_msg>add TryToEnum<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Signum.Utilities.Reflection;
using System.ComponentModel;
using System.Reflection;
using System.Collections.Concurrent;

namespace Signum.Utilities
{
    public static class EnumExtensions
    {
        public static T ToEnum<T>(this string str) where T : struct
        {
            return (T)Enum.Parse(typeof(T), str);
        }

        public static T ToEnum<T>(this string str, bool ignoreCase) where T : struct
        {
            return (T)Enum.Parse(typeof(T), str, ignoreCase);
        }

        public static T? TryToEnum<T>(this string str) where T : struct
        {
            T result; 
            return Enum.TryParse(str, out result) ? result : (T?)null;
        }

        public static T? TryToEnum<T>(this string str, bool ignoreCase) where T : struct
        {
            T result;
            return Enum.TryParse(str, ignoreCase, out result) ? result : (T?)null;
        }

        public static T[] GetValues<T>()
        {
{'fraction_non_alphanumeric': 0.09851088201603665, 'fraction_numerical': 0.0, 'mean_word_length': 2.5221774193548385, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6023390', 'n_tokens_mistral': 486, 'n_tokens_neox': 486, 'n_words': 144}