Feature: add partial per-property get/set hooks for clean runtime value coercion#102
Conversation
|
|
Agent-Logs-Url: https://github.com/dapplo/Dapplo.Ini/sessions/9c652096-503a-4a5f-a5f6-b4e1d5c8866f Co-authored-by: Lakritzator <708125+Lakritzator@users.noreply.github.com>
|
@copilot That only takes care on the before save / after load, not while running the application. I used to write my own set property, check the value in there and limit / change it if there was an issue with it. Then report it back via a notify change event, so the UI represents the correct value. How would be do this? |
Agent-Logs-Url: https://github.com/dapplo/Dapplo.Ini/sessions/72aa143c-b604-4706-8de9-a5e21085e361 Co-authored-by: Lakritzator <708125+Lakritzator@users.noreply.github.com>
Good point — I added a live in-app coercion pattern to the Validation docs: subscribe to |
|
@copilot that is a really ugly solution, I do not like that at all. How can we support this in a cleaner way, by providing a real solution. Is it possible to have the library consumer provide the a set (and probably get?) in a partial class, with a clear API to pass the corrected value to the framework? |
…oercion Agent-Logs-Url: https://github.com/dapplo/Dapplo.Ini/sessions/6bf10ec0-6c2e-42f6-b28e-9240bd7af85b Co-authored-by: Lakritzator <708125+Lakritzator@users.noreply.github.com>
Implemented a first-class solution in |
|
@copilot If I understand it correctly, if the OnSet method isn't implemented, the compiler leaves them out? The is no performance impact? |
Yes — for the generated |
Description
This PR now goes beyond documentation clarifications and adds a first-class runtime coercion API to generated section classes.
IDataValidation<TSelf>reports validation errors and does not mutate values.On<Property>Set(ref T value)On<Property>Get(ref T value)On<Property>Setruns inside the generated setter before equality checks, persistence updates, validation, and change notifications, allowing clean value correction/coercion in consumer partial classes.On<Property>Getallows optional read-time value transformation.docs/wiki/Validation.mdto replace the event-subscription workaround with the new partial-hook API for live runtime coercion.IAfterLoad<TSelf>,IBeforeSave<TSelf>) as safety-net normalization for load/save paths.tests/Dapplo.Ini.Tests/NotifyPropertyChangedTests.csto verify:PropertyChangedbehavior remains correct,Type of change
Documentation
Check all that apply:
README.md— feature bullet list, table of contents, relevant section(s), and Registry API reference table updateddocs/wiki/Home.md— new wiki page added to the table (if a new page was created)docs/wiki/*.mdpage(s) updated (e.g.Loading-Configuration.md,Registry-API.md,Singleton-and-DI.md)docs/wiki/<Feature>.mdpage created for significant new featuresTests
dotnet test tests/Dapplo.Ini.Tests/)Checklist