diff --git a/src/ConfigFactory.Core/ConfigModule.cs b/src/ConfigFactory.Core/ConfigModule.cs index 1376aa1..7c89954 100644 --- a/src/ConfigFactory.Core/ConfigModule.cs +++ b/src/ConfigFactory.Core/ConfigModule.cs @@ -1,5 +1,4 @@ using CommunityToolkit.Mvvm.ComponentModel; -using ConfigFactory.Core.Attributes; using ConfigFactory.Core.Components; using ConfigFactory.Core.Models; using System.Linq.Expressions; @@ -92,11 +91,11 @@ public void Save() 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) + public bool Validate(out string? message, out ConfigProperty target) { foreach ((var name, (var validate, var errorMessage)) in Validators) { target = Properties[name]; - PropertyInfo propertyInfo = target.info!; + PropertyInfo propertyInfo = target.Property; if (validate(propertyInfo.GetValue(this)) is bool isValid) { ValidationInterface?.SetValidationColor(propertyInfo, isValid ? SuccessColor : FailureColor); @@ -107,7 +106,7 @@ public bool Validate(out string? message, out (PropertyInfo? info, ConfigAttribu } } - target = (null, null); + target = new(); message = "Validation Successful"; return true; } diff --git a/src/ConfigFactory.Core/IConfigModule.cs b/src/ConfigFactory.Core/IConfigModule.cs index 131d782..a84a20d 100644 --- a/src/ConfigFactory.Core/IConfigModule.cs +++ b/src/ConfigFactory.Core/IConfigModule.cs @@ -1,7 +1,5 @@ -using ConfigFactory.Core.Attributes; -using ConfigFactory.Core.Components; +using ConfigFactory.Core.Components; using ConfigFactory.Core.Models; -using System.Reflection; namespace ConfigFactory.Core; @@ -50,5 +48,5 @@ public interface IConfigModule public virtual bool Validate(out string? message) => Validate(out message, out _); /// - public bool Validate(out string? message, out (PropertyInfo? info, ConfigAttribute? attribute) target); + public bool Validate(out string? message, out ConfigProperty target); } diff --git a/src/ConfigFactory.Core/Models/ConfigProperties.cs b/src/ConfigFactory.Core/Models/ConfigProperties.cs index f4bc631..f86ad44 100644 --- a/src/ConfigFactory.Core/Models/ConfigProperties.cs +++ b/src/ConfigFactory.Core/Models/ConfigProperties.cs @@ -3,7 +3,7 @@ namespace ConfigFactory.Core.Models; -public class ConfigProperties : Dictionary +public class ConfigProperties : Dictionary { public static ConfigProperties Generate() { @@ -33,7 +33,7 @@ public ConfigProperties() { } private ConfigProperties(IEnumerable<(PropertyInfo info, ConfigAttribute? attribute)> map) { foreach ((var info, var attribute) in map) { - Add(info.Name, (info, attribute!)); + Add(info.Name, new(info, attribute!)); } } } diff --git a/src/ConfigFactory.Core/Models/ConfigProperty.cs b/src/ConfigFactory.Core/Models/ConfigProperty.cs new file mode 100644 index 0000000..33495aa --- /dev/null +++ b/src/ConfigFactory.Core/Models/ConfigProperty.cs @@ -0,0 +1,22 @@ +using ConfigFactory.Core.Attributes; +using System.Reflection; + +namespace ConfigFactory.Core.Models; + +public readonly struct ConfigProperty +{ + public PropertyInfo Property { get; } + public ConfigAttribute Attribute { get; } + + public void Deconstruct(out PropertyInfo property, out ConfigAttribute attribute) + { + property = Property; + attribute = Attribute; + } + + public ConfigProperty(PropertyInfo property, ConfigAttribute attribute) + { + Property = property; + Attribute = attribute; + } +}