Opc.Ua.XmlDecoder.ReadEnumerated C# (CSharp) Method

ReadEnumerated() public method

Reads an enumerated value from the stream.
public ReadEnumerated ( string fieldName, System enumType ) : Enum
fieldName string
enumType System
return System.Enum
        public Enum ReadEnumerated(string fieldName, System.Type enumType)
        {         
            Enum value = (Enum)Enum.GetValues(enumType).GetValue(0);
            
            if (BeginField(fieldName, true))
            {
                string xml = ReadString();

                if (!String.IsNullOrEmpty(xml))
                {
                    int index = xml.LastIndexOf('_');

                    if (index != -1)
                    {
                        int numericValue = Convert.ToInt32(xml.Substring(index + 1), CultureInfo.InvariantCulture);
                        value = (Enum)Enum.ToObject(enumType, numericValue);
                    }
                    else
                    {
                        value = (Enum)Enum.Parse(enumType, xml, false);
                    }
                }
                                
                EndField(fieldName);
            }

            return value;
        }