🔍 Analyzers
EasyValidate Analyzers
Compile-time analyzers to help you write better validation code with real-time feedback and best practices enforcement
19
Total Analyzers
14
Errors
5
Warnings
0
Info
12
Code Fixers
Chain Validation: 4Conditional Validation: 5Context: 1Design: 3Inheritance: 2Setup: 1Type Safety: 1Usage: 2
Error
EASY001Attribute Must Inherit From System.Attribute
Validation attribute must inherit from System.Attribute. Custom validation attributes must properly extend the attribute hierarchy.
InheritanceExample
// ❌ Wrong - not inheriting from Attribute
public class MyValidator { }
// ✅ Correct - inherit from a validation base class
public class MyValidator : StringValidationAttributeBase { }
ErrorFix Available
EASY002Attribute Must Have Proper AttributeUsage
Validation attribute must have proper AttributeUsage attribute configured for properties, fields, or parameters.
DesignExample
// ❌ Wrong - missing AttributeUsage
public class MyAttribute : Attribute { }
// ✅ Correct - proper AttributeUsage
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
public class MyAttribute : StringValidationAttributeBase { }
ErrorFix Available
EASY003Validation Attribute Must Implement IValidationAttribute<T>
Validation attribute must implement IValidationAttribute<T> to be recognized by the source generator.
DesignExample
// ❌ Wrong - not implementing interface
public class MyAttribute : Attribute { }
// ✅ Correct - implementing via base class
public class MyAttribute : StringValidationAttributeBase
{
public override AttributeResult Validate(string propertyName, string value)
{
// validation logic
}
}
Error
EASY004DivisibleBy Divisor Cannot Be Zero
The divisor passed to 'DivisibleByAttribute' cannot be zero as it would cause a division by zero error.
UsageExample
// ❌ Wrong - divisor is zero
[DivisibleBy(0)]
public int Value { get; set; }
// ✅ Correct - valid divisor
[DivisibleBy(5)]
public int Value { get; set; }
Error
EASY005PowerOf Value Must Be Greater Than One
The value passed to 'PowerOfAttribute' must be greater than 1 for meaningful power validation.
UsageExample
// ❌ Wrong - base is 1 or less
[PowerOf(1)]
public int Value { get; set; }
// ✅ Correct - base greater than 1
[PowerOf(2)] // Values: 2, 4, 8, 16, etc.
public int Value { get; set; }
Error
EASY006Collection Element Type Mismatch
The element passed to collection attributes must match the property's element type.
Type SafetyExample
// ❌ Wrong - string element for int collection
[ContainsElement("test")]
public List<int> Numbers { get; set; }
// ✅ Correct - matching element type
[ContainsElement(42)]
public List<int> Numbers { get; set; }
WarningFix Available
EASY007Duplicate Chain Name
Multiple validation attributes with the same chain name found on a single member. Each chain should have unique attributes.
Chain ValidationExample
// ❌ Wrong - duplicate NotNull in same chain
[NotNull(Chain = "mychain")]
[NotNull(Chain = "mychain")] // Duplicate!
public string Name { get; set; }
// ✅ Correct - unique attributes per chain
[NotNull(Chain = "mychain")]
[NotEmpty(Chain = "mychain")]
public string Name { get; set; }
WarningFix Available
EASY008Validation Chain Needs Reordering
Validation chain attributes need reordering to ensure proper type flow between transforming validators.
Chain ValidationExample
// ⚠️ May need reordering
[NotEmpty]
[NotNull] // Should come first
public string? Name { get; set; }
// ✅ Correct order
[NotNull] // First: handles null
[NotEmpty] // Then: handles empty string
public string? Name { get; set; }
WarningFix Available
EASY009Chain Needs NotNull Injection
Validation chain needs NotNull attribute injection to handle nullable types properly.
Chain ValidationExample
// ⚠️ Missing NotNull for nullable type
[NotEmpty]
public string? Name { get; set; } // Can be null!
// ✅ Correct - NotNull handles null case
[NotNull]
[NotEmpty]
public string? Name { get; set; }
Error
EASY010Incompatible Chain Types
Validation chain has incompatible types. The output type of one validator doesn't match the input type of the next.
Chain ValidationExample
// ❌ Wrong - Numeric outputs double, NotEmpty expects string
[Numeric] // Validates string is numeric, may transform
[NotEmpty] // Expects string input
public string? Value { get; set; }
// ✅ Correct - compatible types
[NotNull]
[NotEmpty]
public string? Value { get; set; }
ErrorFix Available
EASY011Conditional Method Is Missing
The conditional method specified in ConditionalMethod property is missing from the containing class.
Conditional ValidationExample
// ❌ Wrong - method doesn't exist
[NotNull(ConditionalMethod = "ShouldValidate")]
public string? Name { get; set; }
// Missing: private bool ShouldValidate(...) method
// ✅ Correct - method exists
[NotNull(ConditionalMethod = nameof(ShouldValidate))]
public string? Name { get; set; }
private bool ShouldValidate(IChainResult result) => true;
ErrorFix Available
EASY012Conditional Method Invalid Parameter Count
Conditional method must accept exactly zero or one parameter of type IChainResult.
Conditional ValidationExample
// ❌ Wrong - too many parameters
private bool ShouldValidate(IChainResult result, string extra) => true;
// ✅ Correct - zero or one IChainResult parameter
private bool ShouldValidate() => true;
private bool ShouldValidate(IChainResult result) => true;
ErrorFix Available
EASY013Conditional Method Parameter Type Mismatch
Conditional method's first parameter must be of type IChainResult.
Conditional ValidationExample
// ❌ Wrong - wrong parameter type
private bool ShouldValidate(string value) => true;
// ✅ Correct - IChainResult parameter
private bool ShouldValidate(IChainResult result) => true;
ErrorFix Available
EASY014Conditional Method Return Type Mismatch
Conditional method must return bool or ValueTask<bool>.
Conditional ValidationExample
// ❌ Wrong - wrong return type
private string ShouldValidate() => "true";
// ✅ Correct return types
private bool ShouldValidate() => true;
private ValueTask<bool> ShouldValidateAsync() => new(true);
ErrorFix Available
EASY015Invalid Conditional Method Name
Conditional method name is not a valid C# method identifier.
Conditional ValidationExample
// ❌ Wrong - invalid method name
[NotNull(ConditionalMethod = "123Invalid")]
// ✅ Correct - valid C# identifier
[NotNull(ConditionalMethod = nameof(ShouldValidate))]
ErrorFix Available
EASY016Missing Required Validation Type
Class is missing required validation type(s) - must implement IGenerate interface.
SetupExample
// ❌ Wrong - missing IGenerate
public partial class User
{
[NotNull]
public string? Name { get; set; }
}
// ✅ Correct - implements IGenerate
public partial class User : IGenerate
{
[NotNull]
public string? Name { get; set; }
}
Warning
EASY017ValidationContext Property Diagnostic
Issues with ValidationContext property configuration in custom attributes.
ContextExample
// ValidationContext property should be init-only
[ValidationContext]
public MyModel? Context { get; init; } // ✅ Correct
WarningFix Available
EASY018Public Method Can Cause Confusion
Public method with validation attributes can cause confusion in validation processing. Consider making it private or internal.
DesignExample
// ⚠️ Warning - public method with validation
public void Process([NotNull] string? value) { }
// ✅ Better - internal or private
internal void Process([NotNull] string? value) { }
Error
EASY019Conflicting Base Class Inheritance
Containing class inherits another class and is required to inherit a specific base class for validation.
InheritanceExample
// ❌ Conflict - can't inherit two classes
public class MyClass : SomeOtherBase, IGenerate { }
// When validator requires specific base class