Beispiel #1
0
        /// <summary>
        /// Parses the specified literal. Throws exceptions when angry
        /// </summary>
        /// <param name="literal">The literal.</param>
        /// <returns></returns>
        /// <exception cref="FormatException"></exception>
        private int ParseInt(string literal)
        {
            var v = IntParser.TryParse(literal);

            if (!v.HasValue)
            {
                throw new FormatException();
            }
            return(v.Value);
        }
Beispiel #2
0
        private void Parse(PhoneExcelData excelData, PhoneColumnNames column, int i)
        {
            switch (column)
            {
            case PhoneColumnNames.Name:
                currentPhone.Name = _nameParser.TryParse(excelData, i);
                break;

            case PhoneColumnNames.Price:
                currentPhone.Price = _priceParser.TryParse(excelData, i);
                break;

            case PhoneColumnNames.Description:
                currentPhone.Description = _descriptionParser.TryParse(excelData, i);
                break;

            case PhoneColumnNames.Manufacturer:
                currentPhone.Manufacturer = new ManufacturerDto
                {
                    Id = _manufacturerParser.TryParse(excelData, i)
                };
                break;

            case PhoneColumnNames.RAM:
                currentPhone.RAM = _ramParser.TryParse(excelData, i);
                break;

            case PhoneColumnNames.ROM:
                currentPhone.ROM = _romParser.TryParse(excelData, i);
                break;

            case PhoneColumnNames.CPU:
                currentPhone.CPU = _cpuParser.TryParse(excelData, i);
                break;

            case PhoneColumnNames.BatteryCapacity:
                currentPhone.BatteryCapacity = _batteryCapacityParser.TryParse(excelData, i);
                break;

            case PhoneColumnNames.ScreenDiagonal:
                currentPhone.ScreenDiagonal = _screenDiagonalParser.TryParse(excelData, i);
                break;

            case PhoneColumnNames.Camera:
                currentPhone.Camera = _cameraParser.TryParse(excelData, i);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(column), column, null);
            }
        }
Beispiel #3
0
        private void Parse(ElectronicBookExcelData excelData, ElectronicBookColumnNames column, int i)
        {
            switch (column)
            {
            case ElectronicBookColumnNames.Name:
                currentElectronicBook.Name = _nameParser.TryParse(excelData, i);
                break;

            case ElectronicBookColumnNames.Price:
                currentElectronicBook.Price = _priceParser.TryParse(excelData, i);
                break;

            case ElectronicBookColumnNames.Description:
                currentElectronicBook.Description = _descriptionParser.TryParse(excelData, i);
                break;

            case ElectronicBookColumnNames.Manufacturer:
                currentElectronicBook.Manufacturer = new ManufacturerDto
                {
                    Id = _manufacturerParser.TryParse(excelData, i)
                };
                break;

            case ElectronicBookColumnNames.ScreenDiagonal:
                currentElectronicBook.ScreenDiagonal = _screenDiagonalParser.TryParse(excelData, i);
                break;

            case ElectronicBookColumnNames.ScreenType:
                currentElectronicBook.ScreenType = new ScreenTypeDto
                {
                    Id = _screenTypeParser.TryParse(excelData, i)
                };
                break;

            case ElectronicBookColumnNames.BatteryCapacity:
                currentElectronicBook.BatteryCapacity = _batteryCapacityParser.TryParse(excelData, i);
                break;

            case ElectronicBookColumnNames.WorkingTime:
                currentElectronicBook.WorkingTime = _workingTimeParser.TryParse(excelData, i);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(column), column, null);
            }
        }
Beispiel #4
0
 public void Parse09()
 {
     Assert.AreEqual(null, IntParser.TryParse("09"));
 }
Beispiel #5
0
 public void ParseA()
 {
     Assert.AreEqual(null, IntParser.TryParse("A"));
 }
Beispiel #6
0
 public void Parse0Xff()
 {
     Assert.AreEqual(255, IntParser.TryParse("0Xff"));
 }
Beispiel #7
0
 public void Parse0xFF()
 {
     Assert.AreEqual(255, IntParser.TryParse("0xFF"));
 }
Beispiel #8
0
 public void Parse010()
 {
     Assert.AreEqual(8, IntParser.TryParse("010"));
 }
Beispiel #9
0
 public void Parse1234()
 {
     Assert.AreEqual(1234, IntParser.TryParse("1234"));
 }