Azavea.NijPredictivePolicing.Common.Data.FixedWidthField.GetFieldObject C# (CSharp) Method

GetFieldObject() public method

Gets the parsed object for this field from a row and updates the current position, as determined by Type.
public GetFieldObject ( string row, int &currentPos ) : object
row string The row to read from
currentPos int The current position in the row
return object
        public object GetFieldObject(string row, ref int currentPos)
        {
            try
            {
                string data = GetFieldData(row, ref currentPos);
                object result = null;
                switch (this.Type)
                {
                    case FixedWidthTypes.NULL:
                        break;

                    case FixedWidthTypes.STRING:
                        result = data;
                        break;

                    case FixedWidthTypes.INT:
                        result = int.Parse(data);
                        break;

                    case FixedWidthTypes.LONG:
                        result = long.Parse(data);
                        break;

                    case FixedWidthTypes.FLOAT:
                        result = float.Parse(data);
                        break;

                    case FixedWidthTypes.DOUBLE:
                        result = double.Parse(data);
                        break;

                    case FixedWidthTypes.DECIMAL:
                        result = decimal.Parse(data);
                        break;

                    case FixedWidthTypes.DATETIME:
                        result = DateTime.Parse(data);
                        break;

                    default:
                        throw new NotImplementedException("Invalid value for Type");
                }

                return result;
            }
            catch (Exception ex)
            {
                if (Strict)
                    throw ex;
                else
                    return DefaultValue;
            }
        }