System.Enum.Parse C# (CSharp) Method

Parse() private method

private Parse ( Type enumType, String value ) : Object
enumType Type
value String
return Object
        public static Object Parse(Type enumType, String value)
        {
            return Parse(enumType, value, false);
        }

Same methods

Enum::Parse ( Type enumType, String value, bool ignoreCase ) : Object

Usage Example

        public static List <IEnumValue> GetEnumValues(Type type)
        {
            if (type is null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (type.IsEnum)
            {
                List <IEnumValue> Values = new List <IEnumValue>();

                foreach (string Name in Enum.GetNames(type))
                {
                    Values.Add(
                        new EnumValue()
                    {
                        Value = Convert.ChangeType(
                            Enum.Parse(type, Name),
                            Enum.GetUnderlyingType(type)
                            ).ToString(),
                        Label = Name
                    });
                }

                return(Values);
            }
            else
            {
                return(null);
            }
        }
All Usage Examples Of System.Enum::Parse