29 lines
657 B
C#
29 lines
657 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Diagnostics;
|
|
|
|
namespace OnlineSalesAutoCrop.CoreAPI.Models.Global
|
|
{
|
|
public static class SettingsExtensions
|
|
{
|
|
public static bool IsValid<T>(this T data)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(data);
|
|
|
|
var validationResult = new List<ValidationResult>();
|
|
var result = Validator.TryValidateObject(data, new ValidationContext(data), validationResult, false);
|
|
|
|
if (!result)
|
|
{
|
|
foreach (var item in validationResult)
|
|
{
|
|
Debug.WriteLine($"ERROR::{item.MemberNames}:{item.ErrorMessage}");
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|