Zhomfr.Validation.Rules.Abstractions 0.7.0

dotnet add package Zhomfr.Validation.Rules.Abstractions --version 0.7.0
                    
NuGet\Install-Package Zhomfr.Validation.Rules.Abstractions -Version 0.7.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Zhomfr.Validation.Rules.Abstractions" Version="0.7.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zhomfr.Validation.Rules.Abstractions" Version="0.7.0" />
                    
Directory.Packages.props
<PackageReference Include="Zhomfr.Validation.Rules.Abstractions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Zhomfr.Validation.Rules.Abstractions --version 0.7.0
                    
#r "nuget: Zhomfr.Validation.Rules.Abstractions, 0.7.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Zhomfr.Validation.Rules.Abstractions@0.7.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Zhomfr.Validation.Rules.Abstractions&version=0.7.0
                    
Install as a Cake Addin
#tool nuget:?package=Zhomfr.Validation.Rules.Abstractions&version=0.7.0
                    
Install as a Cake Tool

Validation Rule Abstractions

NuGet Status NuGet Downloads

⚠️ 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 .csproj to avoid unexpected build errors.

A lightweight, extensible foundational library for building custom validation rules in .NET. It provides a robust base class with essential infrastructure, property access helpers, and a dedicated set of validation exceptions to build clean and predictable validation pipelines.

Key Features

  • Base Rule Infrastructure: Standardized core logic for defining custom, reusable validation rules.
  • Property Value Extraction: Effortlessly extract object property values by name using built-in helper methods.
  • Display Name Resolution: Automatically retrieve human-readable property names from attributes (such as [Display(Name = "...")]).
  • Null-Safe Evaluation: Designed to return positive results on null inputs, ensuring Required rules can properly manage presence validation without unexpected side effects.
  • Error Message Formatting: Built-in template formatting for consistent and customizable error output.
  • Validation Exception Hierarchy: A comprehensive set of domain-specific validation exceptions for robust error handling.

📦 Installation

Install package:

dotnet add package Zhomfr.Validation.Rules.Abstractions

Zhomfr.Validation.Rules.Abstractions

AbstractRule

Zhomfr.Validation.Rules.Abstractions.Errors

UnsupportedTypeException

ValuesHasDifferentTypesException

AbstractRule

Namespace: Zhomfr.Validation.Rules.Abstractions

public abstract class AbstractRule : System.ComponentModel.DataAnnotations.ValidationAttribute

Inheritance Object → Attribute → ValidationAttribute → AbstractRule<br> Attributes NullableContextAttribute, NullableAttribute, AttributeUsageAttribute

Properties

MessageArgs

Arguments for error message.

protected List<object> MessageArgs { get; }
Property Value

List<Object><br>

ErrorMessageString

protected string ErrorMessageString { get; }
Property Value

String<br>

RequiresValidationContext

public virtual bool RequiresValidationContext { get; }
Property Value

Boolean<br>

ErrorMessage

public string? ErrorMessage { get; set; }
Property Value

String<br>

ErrorMessageResourceName

public string? ErrorMessageResourceName { get; set; }
Property Value

String<br>

ErrorMessageResourceType

public Type? ErrorMessageResourceType { get; set; }
Property Value

Type<br>

TypeId

public virtual object TypeId { get; }
Property Value

Object<br>

Constructors

AbstractRule ()

protected AbstractRule()

Methods

CheckCondition (Object, ValidationContext)

Checks the validation condition for the specified value.

protected abstract bool CheckCondition(object value, ValidationContext context)
Parameters

value Object<br> The value to validate.

context ValidationContext<br> The validation context.

Returns

Boolean<br> True if the condition is met; otherwise, false.

Exceptions

UnsupportedTypeException<br> Thrown when the rule cannot process the data type.

Exception<br> Any other exceptions thrown by the logic.

FormatedMessage (String, Object)

Formats the error message using the display name, message arguments, and value.

protected virtual string FormatedMessage(string displayName, object value)
Parameters

displayName String<br> The display name of the field being validated.

value Object<br> The value that failed validation.

Returns

String<br> The formatted error message string.

IsValid (Object, ValidationContext)

protected override ValidationResult? IsValid(object? value, ValidationContext context)
Parameters

value Object?<br>

context ValidationContext<br>

Returns

ValidationResult?<br>

Exceptions

UnsupportedTypeException<br> Thrown when the rule cannot process the data type.

Exception<br> Any other exceptions thrown by the logic.

ThrowIfFieldsHasDifferentTypes (Object, Object)

Check if validated fields has same types.

protected static void ThrowIfFieldsHasDifferentTypes(object value, object anotherValue)
Parameters

value Object<br> Current value.

anotherValue Object<br> Value of another field.

Exceptions

ValuesHasDifferentTypesException<br> If fields has different types/

GetFieldValue<T> (String, ValidationContext)

Get field value by name.

protected static T GetFieldValue<T>(string fieldName, ValidationContext context)
Type Parameters

T<br> Expected type of value.

Parameters

fieldName String<br> Field name.

context ValidationContext<br> Validation context.

Returns

T<br> Value of field.

Exceptions

MissingFieldException<br> Then field or property not exists in type.

GetDisplayNameForProperty (String, ValidationContext)

Return display name by field name.

protected static string GetDisplayNameForProperty(string fieldName, ValidationContext context)
Parameters

fieldName String<br> Name of field.

context ValidationContext<br> Validation context.

Returns

String<br> Return display name of field.

Exceptions

MissingFieldException<br> Then field or property not exists in type.

AddListAsOneArgumentToMessageArgs (Object[])

Add attribute argument to error message argument like one argument.

protected void AddListAsOneArgumentToMessageArgs(Object[] args)
Parameters

args Object[]<br> Arguments what need add.

UnsupportedTypeException

Namespace: Zhomfr.Validation.Rules.Abstractions.Errors

Exception what indicate what rule can't process type of value.

public class UnsupportedTypeException : System.Exception, System.Runtime.Serialization.ISerializable

Inheritance Object → Exception → UnsupportedTypeException<br> Implements ISerializable

Properties

TargetSite

public MethodBase? TargetSite { get; }
Property Value

MethodBase<br>

Message

public virtual string Message { get; }
Property Value

String<br>

Data

public virtual IDictionary Data { get; }
Property Value

IDictionary<br>

InnerException

public Exception? InnerException { get; }
Property Value

Exception<br>

public virtual string? HelpLink { get; set; }
Property Value

String<br>

Source

public virtual string? Source { get; set; }
Property Value

String<br>

HResult

public int HResult { get; set; }
Property Value

Int32<br>

StackTrace

public virtual string? StackTrace { get; }
Property Value

String<br>

Constructors

UnsupportedTypeException (Type)

Exception what indicate what rule can't process type of value.

public UnsupportedTypeException(Type type)
Parameters

type Type<br> Type of value what can't be processed.

Events

SerializeObjectState

Caution

BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.


protected event EventHandler<SafeSerializationEventArgs>? SerializeObjectState;

ValuesHasDifferentTypesException

Namespace: Zhomfr.Validation.Rules.Abstractions.Errors

Exception what indicates what 2 fields what validated has different type when rule expect same types.

public class ValuesHasDifferentTypesException : System.Exception, System.Runtime.Serialization.ISerializable

Inheritance Object → Exception → ValuesHasDifferentTypesException<br> Implements ISerializable

Properties

TargetSite

public MethodBase? TargetSite { get; }
Property Value

MethodBase<br>

Message

public virtual string Message { get; }
Property Value

String<br>

Data

public virtual IDictionary Data { get; }
Property Value

IDictionary<br>

InnerException

public Exception? InnerException { get; }
Property Value

Exception<br>

public virtual string? HelpLink { get; set; }
Property Value

String<br>

Source

public virtual string? Source { get; set; }
Property Value

String<br>

HResult

public int HResult { get; set; }
Property Value

Int32<br>

StackTrace

public virtual string? StackTrace { get; }
Property Value

String<br>

Constructors

ValuesHasDifferentTypesException (String)

Exception what indicates what 2 fields what validated has different type when rule expect same types.

public ValuesHasDifferentTypesException(string message = "The validated values has different types.")
Parameters

message String<br> Custom error message.

Events

SerializeObjectState

Caution

BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.


protected event EventHandler<SafeSerializationEventArgs>? SerializeObjectState;
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Zhomfr.Validation.Rules.Abstractions:

Package Downloads
Zhomfr.Validation.Rules

A powerful, intuitive collection of custom validation attributes built directly on top of the standard .NET System.ComponentModel.DataAnnotations infrastructure.

Zhomfr.Validation.Rules.Database

A powerful, intuitive collection of custom validation attributes built directly on top of the standard .NET System.ComponentModel.DataAnnotations infrastructure.

Zhomfr.Validation.Rules.Files

A powerful, intuitive collection of custom validation attributes built directly on top of the standard .NET System.ComponentModel.DataAnnotations infrastructure.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.7.0 38 10/26/2026
0.6.0 70 10/24/2026
0.5.0 64 10/23/2026
0.4.1 49 10/23/2026
0.4.0 60 10/22/2026
0.3.0 53 10/22/2026
0.2.1 57 10/21/2026
0.2.0 54 10/21/2026