Systemi.ComponentModel.AnnotationsExecute.NET
2.2.9
dotnet add package Systemi.ComponentModel.AnnotationsExecute.NET --version 2.2.9
NuGet\Install-Package Systemi.ComponentModel.AnnotationsExecute.NET -Version 2.2.9
<PackageReference Include="Systemi.ComponentModel.AnnotationsExecute.NET" Version="2.2.9" />
<PackageVersion Include="Systemi.ComponentModel.AnnotationsExecute.NET" Version="2.2.9" />
<PackageReference Include="Systemi.ComponentModel.AnnotationsExecute.NET" />
paket add Systemi.ComponentModel.AnnotationsExecute.NET --version 2.2.9
#r "nuget: Systemi.ComponentModel.AnnotationsExecute.NET, 2.2.9"
#:package Systemi.ComponentModel.AnnotationsExecute.NET@2.2.9
#addin nuget:?package=Systemi.ComponentModel.AnnotationsExecute.NET&version=2.2.9
#tool nuget:?package=Systemi.ComponentModel.AnnotationsExecute.NET&version=2.2.9
System.ComponentModel.AnnotationsEx
Provides extension methods for System.ComponentModel.DataAnnotations attributes, adding support for custom validation logic and enhanced error messages.
Provides attributes that are used to define metadata for objects used as data sources.
Commonly Used Types: System.ComponentModel.DataAnnotations.ValidationResult System.ComponentModel.DataAnnotations.IValidatableObject System.ComponentModel.DataAnnotations.ValidationAttribute System.ComponentModel.DataAnnotations.RequiredAttribute System.ComponentModel.DataAnnotations.StringLengthAttribute System.ComponentModel.DataAnnotations.DisplayAttribute System.ComponentModel.DataAnnotations.RegularExpressionAttribute System.ComponentModel.DataAnnotations.DataTypeAttribute System.ComponentModel.DataAnnotations.RangeAttribute System.ComponentModel.DataAnnotations.KeyAttribute
Usage
RequiredExAttribute
Makes a property required based on the value of another property.
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class RequiredExAttribute : RequiredAttribute
{
public string DependentProperty { get; set; }
public object TargetValue { get; set; }
public RequiredExAttribute(string dependentProperty, object targetValue)
{
DependentProperty = dependentProperty;
TargetValue = targetValue;
}
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (validationContext == null)
{
throw new ArgumentNullException(nameof(validationContext));
}
PropertyInfo dependentPropertyInfo = validationContext.ObjectType.GetProperty(DependentProperty);
if (dependentPropertyInfo == null)
{
return new ValidationResult($"Dependent property '{DependentProperty}' not found on type '{validationContext.ObjectType.Name}'.");
}
object dependentPropertyValue = dependentPropertyInfo.GetValue(validationContext.ObjectInstance, null);
if (Equals(dependentPropertyValue, TargetValue))
{
return base.IsValid(value, validationContext);
}
return ValidationResult.Success;
}
}
▌StringLengthExAttribute
Ensures a string property's length does not exceed a maximum if the property is not null or empty.
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class StringLengthExAttribute : StringLengthAttribute
{
public StringLengthExAttribute(int maximumLength) : base(maximumLength)
{
}
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (value == null || string.IsNullOrEmpty(value.ToString()))
{
return ValidationResult.Success;
}
return base.IsValid(value, validationContext);
}
}
▌Validate Extension Method
Provides a simple way to validate an object and get a list of validation errors.
public static class ValidationExtensions
{
public static List<ValidationResult> Validate(this object obj)
{
var results = new List<ValidationResult>();
var context = new ValidationContext(obj, serviceProvider: null, items: null);
Validator.TryValidateObject(obj, context, results, validateAllProperties: true);
return results;
}
}
▌RegexExAttribute Validates a property against a regular expression pattern, but only if the value is not null or empty.
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class RegexExAttribute : ValidationAttribute
{
private readonly Regex _regex;
public RegexExAttribute(string pattern)
{
_regex = new Regex(pattern);
}
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (value == null || string.IsNullOrEmpty(value?.ToString()))
{
return ValidationResult.Success;
}
if (!_regex.IsMatch(value.ToString()))
{
return new ValidationResult(ErrorMessage);
}
return ValidationResult.Success;
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net is compatible. net48 is compatible. net481 was computed. |
-
.NETFramework 4.8
- EasyCaptcha.Wpf (>= 0.9.0.3)
- Microsoft.CSharp (>= 4.7.0)
- Microsoft.EntityFrameworkCore.SqlServer (>= 3.1.32)
- MSTest.TestFramework (>= 3.8.3)
- System.Buffers (>= 4.5.1)
- System.Data.SqlClient (>= 4.9.0)
- System.Diagnostics.DiagnosticSource (>= 4.7.1)
- System.Memory (>= 4.5.4)
- System.Numerics.Vectors (>= 4.5.0)
- System.Runtime.CompilerServices.Unsafe (>= 4.7.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
2.2.9 | 138 | 5/27/2025 |
2.2.8 | 141 | 5/27/2025 |
2.2.7 | 141 | 5/27/2025 |
2.2.6 | 140 | 5/27/2025 |
2.2.5 | 146 | 5/25/2025 |
2.2.4 | 138 | 5/25/2025 |
2.2.3.9 | 153 | 5/17/2025 |
2.2.3.8 | 173 | 5/16/2025 |
2.2.3.7 | 220 | 5/12/2025 |
2.2.3.6 | 205 | 5/12/2025 |
2.2.3.5 | 208 | 5/12/2025 |
2.2.3.4 | 190 | 5/11/2025 |
2.2.3.3 | 183 | 5/11/2025 |
2.2.3.2 | 186 | 5/11/2025 |
2.2.3.1 | 132 | 5/11/2025 |
2.2.3 | 127 | 5/11/2025 |
1.2.1 | 130 | 5/11/2025 |
1.2.0 | 132 | 5/11/2025 |
1.0.0 | 127 | 5/11/2025 |
Added extension methods for custom validation attributes