Skip to content

Commit bf4c44f

Browse files
author
Kapil Borle
committed
Add argument checking to TextLines public methods
1 parent 9a9ae0b commit bf4c44f

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

Engine/TextLines.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ public TextLines()
3838
/// <param name="inputLines">An IEnumerable type that represent lines in a text.</param>
3939
public TextLines(IEnumerable<string> inputLines) : this()
4040
{
41-
if (inputLines == null)
42-
{
43-
throw new ArgumentNullException(nameof(inputLines));
44-
}
45-
41+
ThrowIfNull(inputLines, nameof(inputLines));
4642
if (inputLines.Any(line => line == null))
4743
{
4844
// todo localize
@@ -161,6 +157,7 @@ public int IndexOf(string item)
161157
public void Insert(int index, string item)
162158
{
163159
ValidateIndex(index);
160+
ThrowIfNull(item, nameof(item));
164161
SetLastAccessed(index, lines.AddBefore(GetNodeAt(index), item));
165162
Count++;
166163
}
@@ -323,5 +320,13 @@ private void GetClosestReference(
323320
searchDirection = 1;
324321
}
325322
}
323+
324+
private static void ThrowIfNull<T>(T param, string paramName)
325+
{
326+
if (param == null)
327+
{
328+
throw new ArgumentNullException(paramName);
329+
}
330+
}
326331
}
327332
}

0 commit comments

Comments
 (0)