fix: reuse validation logic in constructors
This commit is contained in:
@@ -19,6 +19,12 @@ public class ImageContent : Content
|
||||
{
|
||||
}
|
||||
|
||||
private void Validate(string mediaType, string data)
|
||||
{
|
||||
ArgumentValidator.ThrowIfNull(mediaType, nameof(mediaType));
|
||||
ArgumentValidator.ThrowIfNull(data, nameof(data));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ImageContent"/> class.
|
||||
/// </summary>
|
||||
@@ -28,8 +34,7 @@ public class ImageContent : Content
|
||||
/// <returns>A new instance of the <see cref="ImageContent"/> class.</returns>
|
||||
public ImageContent(string mediaType, string data) : base(ContentType.Image)
|
||||
{
|
||||
ArgumentValidator.ThrowIfNull(mediaType, nameof(mediaType));
|
||||
ArgumentValidator.ThrowIfNull(data, nameof(data));
|
||||
Validate(mediaType, data);
|
||||
|
||||
Source = new(mediaType, data);
|
||||
}
|
||||
@@ -44,8 +49,7 @@ public class ImageContent : Content
|
||||
/// <exception cref="ArgumentNullException">Thrown when the media type, data, or cache control is null.</exception>
|
||||
public ImageContent(string mediaType, string data, CacheControl cacheControl) : base(ContentType.Image, cacheControl)
|
||||
{
|
||||
ArgumentValidator.ThrowIfNull(mediaType, nameof(mediaType));
|
||||
ArgumentValidator.ThrowIfNull(data, nameof(data));
|
||||
Validate(mediaType, data);
|
||||
|
||||
Source = new(mediaType, data);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user