Skip to content

Commit 7d00f7b

Browse files
author
Kapil Borle
committed
Add argument checks for Formatter.Format method
1 parent 768e734 commit 7d00f7b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Engine/Formatter.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections;
23
using System.Management.Automation;
34

@@ -22,7 +23,11 @@ public static string Format<TCmdlet>(
2223
Range range,
2324
TCmdlet cmdlet) where TCmdlet : PSCmdlet, IOutputWriter
2425
{
25-
// todo add argument check
26+
// todo implement notnull attribute for such a check
27+
ValidateNotNull(scriptDefinition, "scriptDefinition");
28+
ValidateNotNull(settings, "settings");
29+
ValidateNotNull(cmdlet, "cmdlet");
30+
2631
Helper.Instance = new Helper(cmdlet.SessionState.InvokeCommand, cmdlet);
2732
Helper.Instance.Initialize();
2833

@@ -55,6 +60,14 @@ public static string Format<TCmdlet>(
5560
return text.ToString();
5661
}
5762

63+
private static void ValidateNotNull<T>(T obj, string name)
64+
{
65+
if (obj == null)
66+
{
67+
throw new ArgumentNullException(name);
68+
}
69+
}
70+
5871
private static Settings GetCurrentSettings(Settings settings, string rule)
5972
{
6073
return new Settings(new Hashtable()

0 commit comments

Comments
 (0)