Enhance FileAttachment properties for clarity and performance by using read-only auto-properties and adding IsImage check

This commit is contained in:
Thorsten Sommer 2025-12-29 12:22:27 +01:00
parent ddb1677bc5
commit a75be1163b
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -11,20 +11,37 @@ namespace AIStudio.Chat;
/// <param name="FileSizeBytes">The size of the file in bytes.</param>
public readonly record struct FileAttachment(FileAttachmentType Type, string FileName, string FilePath, long FileSizeBytes)
{
/// <summary>
/// Gets a value indicating whether the file still exists on the file system.
/// </summary>
public bool Exists => File.Exists(this.FilePath);
/// <summary>
/// Gets a value indicating whether the file type is forbidden and should not be attached.
/// </summary>
public bool IsForbidden => this.Type == FileAttachmentType.FORBIDDEN;
/// <remarks>
/// The state is determined once during construction and does not change.
/// </remarks>
public bool IsForbidden { get; } = Type == FileAttachmentType.FORBIDDEN;
/// <summary>
/// Gets a value indicating whether the file type is valid and allowed to be attached.
/// </summary>
public bool IsValid => this.Type != FileAttachmentType.FORBIDDEN;
/// <remarks>
/// The state is determined once during construction and does not change.
/// </remarks>
public bool IsValid { get; } = Type != FileAttachmentType.FORBIDDEN;
/// <summary>
/// Gets a value indicating whether the file type is an image.
/// </summary>
/// <remarks>
/// The state is determined once during construction and does not change.
/// </remarks>
public bool IsImage { get; } = Type == FileAttachmentType.IMAGE;
/// <summary>
/// Gets a value indicating whether the file still exists on the file system.
/// </summary>
/// <remarks>
/// This property checks the file system each time it is accessed.
/// </remarks>
public bool Exists => File.Exists(this.FilePath);
/// <summary>
/// Creates a FileAttachment from a file path by automatically determining the type,