ParameterValidator Class
Provides functionality for validating parameters, emulating the behavior of ASP.NET MVC's System.ComponentModel.DataAnnotations.RequiredAttribute. This class implements the IParameterValidator interface to offer standard parameter validation routines, enabling its use in core application code where model binding and MVC validation attributes are not directly applicable.
public class ParameterValidator : Abblix.Oidc.Server.Common.Interfaces.IParameterValidatorInheritance System.Object → ParameterValidator
Implements IParameterValidator
Remarks
Use this class to enforce parameter requirements in service layers, domain models, or other parts of the application where you want to ensure that inputs are not null without relying on MVC's model binding. This is especially useful in scenarios where data validation needs to occur outside of web controllers, ensuring consistency in validation logic across different layers of an application.
Methods
ParameterValidator.Required<T>(T, string) Method
Validates that a parameter is not null, emulating the enforcement of the System.ComponentModel.DataAnnotations.RequiredAttribute in ASP.NET MVC. This method provides a straightforward way to ensure parameters meet their required conditions, throwing a descriptive exception if they are found to be null.
public void Required<T>(T? value, string name)
where T : class;Type parameters
T
The type of the parameter to validate.
Parameters
value T
The parameter value to validate. The method checks if this value is null.
name System.String
The name of the parameter, which is used in constructing the exception message if the parameter is found to be null. This enhances the debuggability by specifying which parameter failed validation.
Implements Required<T>(T, string)
Exceptions
System.ArgumentNullException
Thrown if the parameter value is null, indicating that a required
parameter was not provided.
Remarks
This method simplifies the task of validating mandatory method parameters, ensuring that null values are caught early in the execution flow. By leveraging this method, developers can avoid repetitive null checks and focus on the core logic of their methods.