Zhomfr.Validation.Rules.Files
0.6.0
dotnet add package Zhomfr.Validation.Rules.Files --version 0.6.0
NuGet\Install-Package Zhomfr.Validation.Rules.Files -Version 0.6.0
<PackageReference Include="Zhomfr.Validation.Rules.Files" Version="0.6.0" />
<PackageVersion Include="Zhomfr.Validation.Rules.Files" Version="0.6.0" />
<PackageReference Include="Zhomfr.Validation.Rules.Files" />
paket add Zhomfr.Validation.Rules.Files --version 0.6.0
#r "nuget: Zhomfr.Validation.Rules.Files, 0.6.0"
#:package Zhomfr.Validation.Rules.Files@0.6.0
#addin nuget:?package=Zhomfr.Validation.Rules.Files&version=0.6.0
#tool nuget:?package=Zhomfr.Validation.Rules.Files&version=0.6.0
Validation Rules for Files
⚠️ Warning: Active Development (< 1.0.0)
Prior to the release of stable version
1.0.0, this library follows SemVer for initial development. This means breaking changes may occur even in minor releases (0.x).We strongly recommend pinning the package version in your
.csprojto avoid unexpected build errors.
A powerful, intuitive collection of custom validation attributes built directly on top of the standard .NET
System.ComponentModel.DataAnnotations infrastructure. Designed to eliminate boilerplate code, this library brings a
rich set of production-ready validation rules—inspired by robust ecosystem standards (like Laravel's validation
features)
— allowing you to validate models with SmartFiles cleanly using declarative attributes without reinventing the wheel.
Key Features
- Standard DataAnnotations Integration: Seamlessly works with ASP.NET Core and standard
Validatormethods out of the box. - Rich Set of Built-in Rules: Covers frequent validation scenarios that are missing from standard .NET, preventing you from writing repetitive custom validators over and over again.
- Intuitive Declarative Syntax: Clean and expressive attributes to keep your domain models and DTOs readable and maintainable.
- Customizable Error Messages: Fully supports localized and custom error message templates via standard
ErrorMessageproperties.
📦 Installation
Install package:
dotnet add package Zhomfr.Validation.Rules.Files
After add namespace in using section:
using Zhomfr.Validation.Rules.Files;
Available Methods
<table> <tr valign="top"> <td>
</td> <td>
</td> <td>
</td> </tr> </table>
🛠️ Features and Examples
FileBetween
Validates that the file size (in bytes) falls within the specified inclusive range.
public class Dto
{
[FileBetween(3, 5)]
public SmartFile SomeFileInvalid = new ("http://example.com" ,"some_filename.txt"); // ValidationError
[FileBetween(3, 5)]
public string SomeFileValid = "test"; // Success
}
FileDimensions
Validates the dimensions (width and height) of an image file. Supports both exact match and range-based validation.
public class Dto
{
[FileDimensions(128, 128)]
public SmartFile SomeFile1;
[FileDimensions(240, 512, 380, 720)]
public string SomeFile2;
}
FileEncoding
Validates that the file content matches the specified character encoding. Equivalent to Laravel's 'encoding' rule (uses strict decoder validation).
public class Dto
{
[FileEncoding("ASCII")]
public SmartFile SomeFile;
}
FileExtension
The file under validation must have a MIME type corresponding to one of the listed extensions.
public class Dto
{
[FileExtension("jpg", "bmp", "png")]
public SmartFile SomeFile;
}
FileImage
The file under validation must be an image (bmp, gif, ico, jpeg, png, wbmp, webp).
public class Dto
{
[FileImage()]
public SmartFile SomeImageFile;
[FileImage(true)]
public SmartFile SomeSvgFile;
}
FileMax
Validates that the file size (in bytes) does not exceed the specified maximum limit.
public class Dto
{
[FileMax(4_194_304)]
public SmartFile SomeFile;
}
FileMime
The file under validation must match one of the given MIME types.
public class Dto
{
[FileMime("video/avi", "video/mpeg", "video/quicktime")]
public SmartFile SomeFile;
}
FileMin
Validates that the file size (in bytes) does not below the specified minimum limit.
public class Dto
{
[FileMin(4_194_304)]
public SmartFile SomeFile;
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- SkiaSharp (>= 4.153.1)
- SkiaSharp.NativeAssets.Linux (>= 4.153.1)
- Zhomfr.Helpers.SmartFile (>= 0.6.0)
- Zhomfr.Validation.Rules.Abstractions (>= 0.6.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.