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>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ImageContent"/> class.
|
/// Initializes a new instance of the <see cref="ImageContent"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -28,8 +34,7 @@ public class ImageContent : Content
|
|||||||
/// <returns>A new instance of the <see cref="ImageContent"/> class.</returns>
|
/// <returns>A new instance of the <see cref="ImageContent"/> class.</returns>
|
||||||
public ImageContent(string mediaType, string data) : base(ContentType.Image)
|
public ImageContent(string mediaType, string data) : base(ContentType.Image)
|
||||||
{
|
{
|
||||||
ArgumentValidator.ThrowIfNull(mediaType, nameof(mediaType));
|
Validate(mediaType, data);
|
||||||
ArgumentValidator.ThrowIfNull(data, nameof(data));
|
|
||||||
|
|
||||||
Source = new(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>
|
/// <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)
|
public ImageContent(string mediaType, string data, CacheControl cacheControl) : base(ContentType.Image, cacheControl)
|
||||||
{
|
{
|
||||||
ArgumentValidator.ThrowIfNull(mediaType, nameof(mediaType));
|
Validate(mediaType, data);
|
||||||
ArgumentValidator.ThrowIfNull(data, nameof(data));
|
|
||||||
|
|
||||||
Source = new(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>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="TextContent"/> class.
|
/// Initializes a new instance of the <see cref="TextContent"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -27,7 +32,7 @@ public class TextContent : Content
|
|||||||
/// <returns>A new instance of the <see cref="TextContent"/> class.</returns>
|
/// <returns>A new instance of the <see cref="TextContent"/> class.</returns>
|
||||||
public TextContent(string text) : base(ContentType.Text)
|
public TextContent(string text) : base(ContentType.Text)
|
||||||
{
|
{
|
||||||
ArgumentValidator.ThrowIfNull(text, nameof(text));
|
Validate(text);
|
||||||
|
|
||||||
Text = text;
|
Text = text;
|
||||||
}
|
}
|
||||||
@@ -41,7 +46,7 @@ public class TextContent : Content
|
|||||||
/// <exception cref="ArgumentNullException">Thrown when the text or cache control is null.</exception>
|
/// <exception cref="ArgumentNullException">Thrown when the text or cache control is null.</exception>
|
||||||
public TextContent(string text, CacheControl cacheControl) : base(ContentType.Text, cacheControl)
|
public TextContent(string text, CacheControl cacheControl) : base(ContentType.Text, cacheControl)
|
||||||
{
|
{
|
||||||
ArgumentValidator.ThrowIfNull(text, nameof(text));
|
Validate(text);
|
||||||
|
|
||||||
Text = text;
|
Text = text;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user