CodeImp.Gluon.Configuration.ParseNumber C# (CSharp) Метод

ParseNumber() приватный Метод

private ParseNumber ( string &file, string &data, int &pos, int &line ) : object
file string
data string
pos int
line int
Результат object
        private object ParseNumber(ref string file, ref string data, ref int pos, ref int line)
        {
            string val = "";

            while((pos < data.Length) && !cpErrorResult)
            {
                // Get current character
                char c = data[pos++];

                // Check if number ends here
                if((c == ';') || (c == ',') || (c == ')'))
                {
                    // One byte back, because this
                    // is also the end of the assignment
                    pos--;

                    // Floating point?
                    if(val.IndexOf("f") > -1)
                    {
                        float fval = 0;

                        // Convert to float (remove the f first)
                        try { fval = System.Convert.ToSingle(val.Trim().Replace("f", ""), CultureInfo.InvariantCulture); }
                        catch(System.FormatException)
                        {
                            // ERROR: Invalid value in assignment
                            RaiseError(file, line, ERROR_VALUEINVALID);
                            return null;
                        }
                        return fval;
                    }
                    else
                    {
                        int ival = 0;
                        long lval = 0;

                        // Convert to int
                        try
                        {
                            // Convert to value
                            ival = System.Convert.ToInt32(val.Trim(), CultureInfo.InvariantCulture);
                            return ival;
                        }
                        catch(System.OverflowException)
                        {
                            // Too large for Int32, try Int64
                            try
                            {
                                // Convert to value
                                lval = System.Convert.ToInt64(val.Trim(), CultureInfo.InvariantCulture);
                                return lval;
                            }
                            catch(System.OverflowException)
                            {
                                // Too large for Int64, return error
                                RaiseError(file, line, ERROR_VALUETOOBIG);
                                return null;
                            }
                            catch(System.FormatException)
                            {
                                // ERROR: Invalid value in assignment
                                RaiseError(file, line, ERROR_VALUEINVALID);
                                return null;
                            }
                        }
                        catch(System.FormatException)
                        {
                            // ERROR: Invalid value in assignment
                            RaiseError(file, line, ERROR_VALUEINVALID);
                            return null;
                        }
                    }
                }
                // Check for new line
                else if(c == '\n')
                {
                    // Count the new line
                    line++;
                }
                // Everything else is part of the value
                else
                {
                    val += c.ToString(CultureInfo.InvariantCulture);
                }
            }

            RaiseError(file, line, ERROR_UNEXPECTED_END);
            return null;
        }