ScoobyRom.DataFile.RomXml.ParseHexInt C# (CSharp) Method

ParseHexInt() static private method

Parses hex number e.g."0x123af". Prefix "0x" is required.
static private ParseHexInt ( string strToParse, XObject xObj ) : int
strToParse string
xObj XObject
return int
        internal static int ParseHexInt(string strToParse, XObject xObj)
        {
            const string HexPrefix = "0x";

            // Prefix "0x" required in RomRaider-format
            // but not allowed in int.Parse(...) even though using NumberStyles.HexNumber.
            int index0x = strToParse.IndexOf (HexPrefix);
            if (index0x < 0) {
                string message = "Prefix '" + HexPrefix + "' missing in XML item: " + xObj.ToString ();
                ThrowXmlExceptionWithLineInfo (message, null, xObj);
            }

            try {
                return int.Parse (strToParse.Substring (index0x + HexPrefix.Length), System.Globalization.NumberStyles.HexNumber, NumberFormatInfoInvariant);
            } catch (Exception ex) {
                ThrowParse (ex, xObj, "hex integer");
                throw;
            }
        }