Added documentation
This commit is contained in:
parent
416759c213
commit
35f271e12b
8 changed files with 441 additions and 1 deletions
44
README.md
44
README.md
|
|
@ -1,2 +1,44 @@
|
|||
# module-project-validator
|
||||
# Description
|
||||
|
||||
A tool to help validate data across scenes, prefabs and scriptable objects.
|
||||
|
||||

|
||||
|
||||
### Unity Windows
|
||||
|
||||

|
||||

|
||||
|
||||
## Attribute Validators
|
||||
|
||||
The field attrribute:
|
||||
```
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)]
|
||||
public sealed class RequiredAttribute : Attribute
|
||||
{
|
||||
private readonly EValidatorSeverity _severity;
|
||||
|
||||
public RequiredAttribute()
|
||||
{
|
||||
_severity = EValidatorSeverity.Error;
|
||||
}
|
||||
|
||||
public RequiredAttribute(EValidatorSeverity severity)
|
||||
{
|
||||
_severity = severity;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The validator implements `IAttributeValidator<T>`, where `T` is the attribute and will automatically be found by the validator.
|
||||
|
||||
```
|
||||
public sealed class Validator : IAttributeValidator<RequiredAttribute>
|
||||
{
|
||||
public ValidatorResult Validate(RequiredAttribute attribute, object value)
|
||||
{
|
||||
var isValid = value is UnityEngine.Object obj ? obj != null : value != null;
|
||||
return isValid ? ValidatorResult.Valid : ValidatorResult.Create(attribute._severity, "Value is Null");
|
||||
}
|
||||
}
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue