This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
using System.Linq.Expressions; | |
// I loved this when I found here: https://codereview.stackexchange.com/questions/178106/simple-object-validator | |
namespace Tools.Validate.Objects // could be something else | |
{ | |
public class Validation | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var model = new Test() { }; | |
var validator = new Validator<Test>(); | |
var result = new Validator<Test>() | |
.AddRule(t => t.Name, new ValidatorNameRule()) | |
.Validate(model); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IValidator<in T> { | |
} | |
public class CompositeValidator<T> : IValidator<T> { | |
public CompositeValidator(params IValidator<T>[] validators) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Generic interface for Validators | |
public interface IValidator<T> | |
{ | |
IEnumerable<ValidationResult> Validate(T businessEntity); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web.Configuration; | |
using System.Web.Security; | |
namespace Validation | |
{ | |
public interface IValidator <T> | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ValidatorHandler<TRequest, TResponse> | |
: IRequestHandler<TRequest, TResponse> | |
where TRequest : IRequest<TResponse> | |
{ | |
private readonly IRequestHandler<TRequest, TResponse> _inner; | |
private readonly IValidator<TRequest> _validator; | |
public ValidatorHandler(IRequestHandler<TRequest, TResponse> inner, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RegsiterCommandValidator : IValidator<RegisterCommand> | |
{ | |
private readonly IValidationResult _validationResult; | |
private readonly IDbContext _context; | |
public RegsiterCommandValidator(IValidationResult validationResult, IDbContext context) | |
{ | |
_validationResult = validationResult; | |
_context = context; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Options; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace WebApp | |
{ | |
public class ShowAllServicesMiddleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//License: MIT | |
//using System.Xml; | |
//using System.Xml.Schema; | |
public static List<ValidationEventArgs> ValidateXmlWithXsd(string xmlPath, string xsdPath) | |
{ | |
XmlSchemaSet s = new XmlSchemaSet(); | |
var args = new List<ValidationEventArgs>(); | |
using (XmlReader reader = XmlReader.Create(xsdPath)) | |
{ | |
//These validations will be from reading the xsd itself |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Xml; | |
using System.Xml.Schema; | |
using System.Xml.XPath; | |
namespace XSD_fun | |
{ | |
class Program | |
{ |
OlderNewer