EXILED icon indicating copy to clipboard operation
EXILED copied to clipboard

Config validators

Open VladTheCow opened this issue 1 year ago • 10 comments

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

VladTheCow avatar Sep 07 '23 18:09 VladTheCow

What’s still needed to do?

iamalexrouse avatar Jan 26 '24 05:01 iamalexrouse

[PossibleValues<RoleTypeId>()]

Does this authorize all value from RoleTypeId ?

louis1706 avatar Jan 26 '24 09:01 louis1706

I’ll do a test now while I’m awake.

iamalexrouse avatar Feb 04 '24 13:02 iamalexrouse

[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.

iamalexrouse avatar Feb 04 '24 15:02 iamalexrouse

@NaoUnderscore Is this PR 'Do Not Merge'?

iamalexrouse avatar Feb 22 '24 10:02 iamalexrouse

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.

iamalexrouse avatar May 18 '24 11:05 iamalexrouse

The docs are lacking.

moddedmcplayer avatar May 18 '24 16:05 moddedmcplayer

The docs are lacking.

We'll work on some documentation asap.

iamalexrouse avatar May 19 '24 02:05 iamalexrouse

ALEXWARELLC

Check your fork's PRs.

moddedmcplayer avatar May 19 '24 10:05 moddedmcplayer

ALEXWARELLC

Check your fork's PRs.

Take a look at my review

VladTheCow avatar May 19 '24 11:05 VladTheCow