From 4f768f5dad4be1112b2c41fecd5cc947cf846974 Mon Sep 17 00:00:00 2001 From: ArchLeaders Date: Tue, 11 Jul 2023 09:30:08 -0700 Subject: [PATCH] Extend output overloads --- src/ConfigFactory.Core/ConfigModule.cs | 9 +++++++-- src/ConfigFactory.Core/IConfigModule.cs | 14 +++++++++++--- src/ConfigFactory/ConfigFactory.cs | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/ConfigFactory.Core/ConfigModule.cs b/src/ConfigFactory.Core/ConfigModule.cs index a41ac1f..1376aa1 100644 --- a/src/ConfigFactory.Core/ConfigModule.cs +++ b/src/ConfigFactory.Core/ConfigModule.cs @@ -1,4 +1,5 @@ using CommunityToolkit.Mvvm.ComponentModel; +using ConfigFactory.Core.Attributes; using ConfigFactory.Core.Components; using ConfigFactory.Core.Models; using System.Linq.Expressions; @@ -89,10 +90,13 @@ public void Save() JsonSerializer.Serialize(fs, (T)this); } - public bool Validate(out string? message) + public bool Validate() => Validate(out _, out _); + public bool Validate(out string? message) => Validate(out message, out _); + public bool Validate(out string? message, out (PropertyInfo? info, ConfigAttribute? attribute) target) { foreach ((var name, (var validate, var errorMessage)) in Validators) { - PropertyInfo propertyInfo = Properties[name].info; + target = Properties[name]; + PropertyInfo propertyInfo = target.info!; if (validate(propertyInfo.GetValue(this)) is bool isValid) { ValidationInterface?.SetValidationColor(propertyInfo, isValid ? SuccessColor : FailureColor); @@ -103,6 +107,7 @@ public bool Validate(out string? message) } } + target = (null, null); message = "Validation Successful"; return true; } diff --git a/src/ConfigFactory.Core/IConfigModule.cs b/src/ConfigFactory.Core/IConfigModule.cs index 1d36d3c..131d782 100644 --- a/src/ConfigFactory.Core/IConfigModule.cs +++ b/src/ConfigFactory.Core/IConfigModule.cs @@ -1,5 +1,7 @@ -using ConfigFactory.Core.Components; +using ConfigFactory.Core.Attributes; +using ConfigFactory.Core.Components; using ConfigFactory.Core.Models; +using System.Reflection; namespace ConfigFactory.Core; @@ -37,10 +39,16 @@ public interface IConfigModule public void Save(); /// - /// Validates the properties and sends the invalid error message to the output + /// Validates each property registered in the collection /// /// /// if the validation was successful; if the validation failed /// - public bool Validate(out string? message); + public virtual bool Validate() => Validate(out _, out _); + + /// + public virtual bool Validate(out string? message) => Validate(out message, out _); + + /// + public bool Validate(out string? message, out (PropertyInfo? info, ConfigAttribute? attribute) target); } diff --git a/src/ConfigFactory/ConfigFactory.cs b/src/ConfigFactory/ConfigFactory.cs index fe06761..36c4e4c 100644 --- a/src/ConfigFactory/ConfigFactory.cs +++ b/src/ConfigFactory/ConfigFactory.cs @@ -58,7 +58,7 @@ public static ConfigPageModel Append(this ConfigPageModel configPageModel, IConf } module.ValidationInterface = new ValidationInterface(configPageModel); - module.Validate(out _); + module.Validate(); return configPageModel; }