Add some simplifications for argument null exception handling

This commit is contained in:
Adrian Conlon
2024-10-06 13:24:04 +01:00
parent fa353d062c
commit ffe559d792
5 changed files with 7 additions and 21 deletions

View File

@@ -5,6 +5,7 @@ namespace Fuse
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
public class Lines
@@ -24,6 +25,7 @@ namespace Fuse
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
Debug.Assert(line != null);
var ignored = line.StartsWith(";", StringComparison.OrdinalIgnoreCase);
if (!ignored)
{

View File

@@ -17,21 +17,14 @@ namespace Fuse
public void Parse(string line)
{
if (string.IsNullOrWhiteSpace(line))
{
throw new ArgumentNullException(nameof(line));
}
ArgumentNullException.ThrowIfNullOrWhiteSpace(line);
var tokens = line.Split(new char[] { ' ', '\t' });
this.Parse(tokens);
}
public void Parse(string[] tokens)
{
if (tokens == null)
{
throw new ArgumentNullException(nameof(tokens));
}
ArgumentNullException.ThrowIfNull(tokens);
this.Address = Convert.ToUInt16(tokens[0], 16);

View File

@@ -23,10 +23,7 @@ namespace Fuse
public bool TryParse(Lines lines)
{
if (lines == null)
{
throw new ArgumentNullException(nameof(lines));
}
ArgumentNullException.ThrowIfNull(lines);
while (!lines.EndOfFile && string.IsNullOrWhiteSpace(this.Description))
{

View File

@@ -19,10 +19,7 @@ namespace Fuse
public bool TryParse(Lines lines)
{
if (lines == null)
{
throw new ArgumentNullException(nameof(lines));
}
ArgumentNullException.ThrowIfNull(lines);
while (!lines.EndOfFile && string.IsNullOrEmpty(this.Description))
{

View File

@@ -37,10 +37,7 @@ namespace Fuse
public bool TryParse(Lines lines)
{
if (lines == null)
{
throw new ArgumentNullException(nameof(lines));
}
ArgumentNullException.ThrowIfNull(lines);
var returned = this.TryParseLine(lines.ReadLine());
if (!returned)