fix: reuse validation logic in constructors

This commit is contained in:
Stevan Freeborn
2024-08-17 17:51:32 -05:00
parent 35adac9fa0
commit 987fbe9742
2 changed files with 16 additions and 7 deletions
+8 -3
View File
@@ -19,6 +19,11 @@ public class TextContent : Content
{
}
private void Validate(string text)
{
ArgumentValidator.ThrowIfNull(text, nameof(text));
}
/// <summary>
/// Initializes a new instance of the <see cref="TextContent"/> class.
/// </summary>
@@ -27,7 +32,7 @@ public class TextContent : Content
/// <returns>A new instance of the <see cref="TextContent"/> class.</returns>
public TextContent(string text) : base(ContentType.Text)
{
ArgumentValidator.ThrowIfNull(text, nameof(text));
Validate(text);
Text = text;
}
@@ -41,8 +46,8 @@ public class TextContent : Content
/// <exception cref="ArgumentNullException">Thrown when the text or cache control is null.</exception>
public TextContent(string text, CacheControl cacheControl) : base(ContentType.Text, cacheControl)
{
ArgumentValidator.ThrowIfNull(text, nameof(text));
Validate(text);
Text = text;
}
}