-
Notifications
You must be signed in to change notification settings - Fork 0
Phase 4 (Waves 1–2): collection binding + validation engine #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
guy-lud
merged 18 commits into
master
from
gsd/phase-4-collection-validation-binding-pr
Jul 15, 2026
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
49b307c
test(04-01): add failing tests for List<T>-family conversion
guy-lud 342f827
feat(04-01): add List<T>-family converter with disjoint shape predicates
guy-lud 64a1e0b
test(04-01): add failing tests for empty-not-null collection defaults
guy-lud 648f4f5
feat(04-01): empty-not-null default for every collection shape
guy-lud d719213
test(04-02): add failing child-sequence bind tests for ConfigurationB…
guy-lud 7433bc4
feat(04-02): bind collections from IConfiguration child-section seque…
guy-lud 0497ab9
test(04-02): D-06 secret redaction on the child-sequence bind path
guy-lud 944f049
feat(04-03): sync validation contracts, context ctors, validator attr…
guy-lud 180317d
test(04-03): add failing tests for core-path settings validation
guy-lud f99d604
feat(04-03): run declared validators in the core populate path
guy-lud b1156bd
test(04-05): add failing AllowEmpty=false empty/whitespace rejection …
guy-lud 3f24f91
feat(04-05): reject empty/whitespace strings for AllowEmpty=false (VA…
guy-lud cc0d3f2
fix(04-02): single-pass child-sequence bind — reload-safe, drops empt…
guy-lud 779f0fc
refactor(04-05): check value==null once in PropertyConversion.Convert
guy-lud c393202
refactor(04-03): dispatch validators via ISettingValidation<T> DIM br…
guy-lud 53ee4a8
test(04-02): lock child-sequence element order + cover empty-element …
guy-lud d4ebe41
chore(04): strip internal review-ID tokens from code comments
guy-lud b049f8d
refactor(04): fold object validator onto [SettingsSection].ValidatorT…
guy-lud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
56 changes: 56 additions & 0 deletions
56
src/Core/ExistForAll.SimpleSettings/Conversion/ListTypeConverter.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| using System.Collections.Concurrent; | ||
| using System.Reflection; | ||
| using ExistForAll.SimpleSettings.Core.Reflection; | ||
|
|
||
| namespace ExistForAll.SimpleSettings.Conversion | ||
| { | ||
| // Handles the List<T> family (List/IList/ICollection/IReadOnlyList/IReadOnlyCollection<T>) by reusing the | ||
| // base array-build path and copying the result into a List<T>. Materialization uses a cached per-element | ||
| // delegate (built once, invoked on every populate) so the warm path carries no MakeGenericType/Activator | ||
| // reflection. | ||
| internal class ListTypeConverter : CollectionTypeConverter | ||
| { | ||
| private static readonly MethodInfo CreateListMethod = | ||
| typeof(ListTypeConverter).GetMethod(nameof(CreateList), BindingFlags.NonPublic | BindingFlags.Static)!; | ||
|
|
||
| private static readonly ConcurrentDictionary<Type, Func<Array, object>> ListFactories = new(); | ||
|
|
||
| public ListTypeConverter(SettingsOptions settingsOptions, TypeConvertersCollections converters) | ||
| : base(settingsOptions, converters) | ||
| { | ||
| } | ||
|
|
||
| public override bool CanConvert(Type settingsType) | ||
| { | ||
| return settingsType.IsListLike(); | ||
| } | ||
|
|
||
| protected override Type GetElementType(Type settingsType) | ||
| { | ||
| return settingsType.GetTypeInfo().GetGenericArguments()[0]; | ||
| } | ||
|
|
||
| public override object Convert(object value, Type settingsType) | ||
| { | ||
| var elementType = GetElementType(settingsType); | ||
| var builtArray = (Array)base.Convert(value, settingsType); | ||
| var factory = ListFactories.GetOrAdd(elementType, BuildFactory); | ||
|
|
||
| return factory(builtArray); | ||
| } | ||
|
|
||
| private static Func<Array, object> BuildFactory(Type elementType) | ||
| { | ||
| var closed = CreateListMethod.MakeGenericMethod(elementType); | ||
|
|
||
| return (Func<Array, object>)closed.CreateDelegate(typeof(Func<Array, object>)); | ||
| } | ||
|
|
||
| // The source is the freshly built T[] (ICollection<T>), so new List<T>(source) copies into a | ||
| // right-sized buffer rather than aliasing the array. | ||
| private static object CreateList<TElement>(Array source) | ||
| { | ||
| return new List<TElement>((TElement[])source); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
34 changes: 34 additions & 0 deletions
34
src/Core/ExistForAll.SimpleSettings/SettingsValidationException.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| using ExistForAll.SimpleSettings.Validations; | ||
|
|
||
| namespace ExistForAll.SimpleSettings | ||
| { | ||
| // Aggregates every ValidationError produced by the declared validators into one exception. Like the rest of | ||
| // the family it embeds NO bound value: the message is composed only from author-supplied ValidationError text | ||
| // (SettingsName + ErrorMessage), never from the settings values the validators inspected (which may be | ||
| // secrets). See D-12/S1 and SettingsPropertyValueException. The aggregate-and-throw is centralized in | ||
| // ThrowIfAny so the core populate path and the DI-resolved path share one thrown contract. | ||
| public class SettingsValidationException : SimpleSettingsException | ||
| { | ||
| public SettingsValidationException(IReadOnlyList<ValidationError> errors) | ||
| : base(Resources.SettingsValidationExceptionMessage(errors)) | ||
| { | ||
| Errors = errors; | ||
| } | ||
|
|
||
| public IReadOnlyList<ValidationError> Errors { get; } | ||
|
|
||
| // The single aggregate-and-throw entry point shared by the core populate path (Plan 03) and the | ||
| // DI-resolved runner (Plan 04): throws one aggregated exception when any error is present, otherwise | ||
| // returns. Centralizing it keeps the thrown contract (type + Errors + value-free message) identical | ||
| // across both paths. | ||
| public static void ThrowIfAny(IReadOnlyList<ValidationError> errors) | ||
| { | ||
| if (errors == null) throw new ArgumentNullException(nameof(errors)); | ||
|
|
||
| if (errors.Count == 0) | ||
| return; | ||
|
|
||
| throw new SettingsValidationException(errors); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.