dotnet-validation-patterns

Implement .NET validation using DataAnnotations, IValidatableObject, and IValidateOptions.

1|Updated Feb 22, 2026
One-click install
npx skills add https://github.com/rudironsoni/dotnet-agent-harness --skill dotnet-validation-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-validation-patterns
Source: https://github.com/rudironsoni/dotnet-agent-harness/tree/main/.rulesync/skills/dotnet-validation-patterns
Command: npx skills add https://github.com/rudironsoni/dotnet-agent-harness --skill dotnet-validation-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you implement robust data validation in your .NET applications using built-in features, ensuring data integrity and preventing invalid states without relying on external libraries for common scenarios.

Core Features & Use Cases

  • Declarative Validation: Leverage DataAnnotations for property-level checks like [Required], [Range], and [StringLength].
  • Cross-Property Validation: Implement IValidatableObject for complex rules spanning multiple properties within a single object.
  • Options Validation: Securely validate application configuration using IValidateOptions<T> at startup.
  • Custom Attributes: Create reusable, domain-specific validation logic.
  • Use Case: Validate a user registration form, ensuring all required fields are present, email formats are correct, and password complexity rules are met before processing.

Quick Start

Use the dotnet-validation-patterns skill to generate C# code demonstrating how to validate a CreateProductRequest model using DataAnnotations.

Frequently Asked Questions about dotnet-validation-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I validate .NET configuration options at startup?

Validate .NET configuration options at startup by implementing the IValidateOptions<T> interface. This mechanism ensures your application configuration data integrity is checked securely during initialization, preventing invalid states from running.

What is the best way to perform cross-property validation in C#?

The best way to perform cross-property validation in C# is implementing IValidatableObject. This interface enables complex validation rules spanning multiple properties within a single object, ensuring data integrity without external dependencies.

How do I use DataAnnotations for declarative model validation in C#?

Use DataAnnotations for declarative model validation in C# by adding attributes like [Required], [Range], and [StringLength] to your properties. This approach enforces property-level checks for your models automatically.

Can I validate objects programmatically using .NET built-in features?

Yes, you can validate objects programmatically in .NET by using the Validator.TryValidateObject method. This approach executes validation logic against your models and retrieves validation results without relying on external libraries.

Do I need external libraries like FluentValidation for common .NET validation scenarios?

You do not need external libraries for common .NET validation scenarios. Built-in features like DataAnnotations, IValidatableObject, and custom ValidationAttribute authoring provide robust data integrity for models and configurations without extra dependencies.

How do I create a custom ValidationAttribute for domain-specific rules in .NET?

Create a custom ValidationAttribute in .NET by authoring a class that inherits from ValidationAttribute. This allows you to implement reusable, domain-specific validation logic tailored to your application requirements.