EXILED
EXILED copied to clipboard
Config validators
Description
This PR offers attributes for validating config values. It supports making own validators (just make a new attribute that implements IValidator)
[LessThan(10)]
[GreaterThan(1)]
[NonNegative]
[NonPositive]
[PossibleValues<RoleTypeId>(RoleTypeId.ClassD, RoleTypeId.Scientist)]
public SomeType SomeValue { get; set; }
Changes
- Update C# version to 11 (attribute with generic type)
- New interface IValidator with validate method
- Default validators: GreaterThan, LessThan, NonNegative, NotPositive, PossibleValues
- Log how many validations are passed
Related suggestions
- https://discord.com/channels/656673194693885975/663978314683252777/1149086332405170299
Tasks
- [ ] Make sure it works
What’s still needed to do?
[PossibleValues<RoleTypeId>()]
Does this authorize all value from RoleTypeId ?
I’ll do a test now while I’m awake.
[PossibleValues<RoleTypeId>()]
Does this authorize all value from RoleTypeId ?
~~I can't test it since I am unable to build a Exiled.Loader.dll bc of Visual Studio being dumb. But I will keep trying.~~ It works. Might have minor issues.
@NaoUnderscore Is this PR 'Do Not Merge'?
After testing, here are the issues I have noted:
- YamlDotNet 13.7.1 is required.
- ~~Validator throws 2 errors instead of the intentional 1 error.~~ Fixed
More notes may be added as we discover more issues.
The docs are lacking.
The docs are lacking.
We'll work on some documentation asap.