-
Notifications
You must be signed in to change notification settings - Fork 104
feat: config validators #648
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
base: dev
Are you sure you want to change the base?
Conversation
Someone-193
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor docs things, I don't really understand how this fully works so I don't know if it'll work, so if it works according to you @VALERA771 and you fix any docs issues I found, I think it should be good to go
| // </copyright> | ||
| // ----------------------------------------------------------------------- | ||
|
|
||
| using System.Reflection; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to after "using System.Linq"
| foreach (PropertyInfo propertyInfo in config.GetType().GetProperties().Where(x => x.GetMethod != null && x.SetMethod != null)) | ||
| plugin.ValidateType(config, propertyInfo, ref validated); | ||
|
|
||
| Log.Info($"Config has successfully passed {validated} validations!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe only print this if validated is > 0 and also include the plugins name too? So like if a plugin has validation, print "MyPlugin's Config has passed 3 validations"
EXILED/Exiled.API/Features/Attributes/Validators/RangeAttribute.cs
Outdated
Show resolved
Hide resolved
| /// <summary> | ||
| /// Check if value is 0 or less. | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Property)] | ||
| public class NonPositiveAttribute : LessOrEqualAttribute | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="NonPositiveAttribute"/> class. | ||
| /// </summary> | ||
| public NonPositiveAttribute() | ||
| : base(0) | ||
| { | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call this NegativeAttribute or IsNegativeAttribute? NonPositive is a bit convoluted
| /// <summary> | ||
| /// Checks if value is 0 or greater. | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Property)] | ||
| public class NonNegativeAttribute : GreaterOrEqualAttribute | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="NonNegativeAttribute"/> class. | ||
| /// </summary> | ||
| public NonNegativeAttribute() | ||
| : base(0) | ||
| { | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call this PositiveAttribute or IsPositiveAttribute? NonNegative is a bit convoluted
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the minimum value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this be a maximum value if this attribute checks if a given value in a config is less than the value provided to the attribute?
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the minimum value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this be a maximum value if this attribute checks if a given value in a config is less than the value provided to the attribute?
|
Basically this PR introduces attributes that perform checks on config load. If check is not passed - default value is used. I'll fix docs and do some tests on week |
Co-authored-by: @Someone <[email protected]>
Co-authored-by: @Someone <[email protected]>
…e.cs Co-authored-by: @Someone <[email protected]>
Description
Describe the changes
Adds config validators alongside with some new features that wasn't presented in previos PRs
What is the current behavior? (You can also link to an open issue here)
What is the new behavior? (if this is a feature change)
Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
Other information:
Types of changes
Submission checklist
Patches (if there are any changes related to Harmony patches)
Other