Added initial version 0.1.0
This commit is contained in:
parent
6aa4cb8596
commit
416759c213
64 changed files with 2181 additions and 0 deletions
29
Runtime/Attributes/RequiredAttribute.cs
Normal file
29
Runtime/Attributes/RequiredAttribute.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
|
||||
namespace Module.ProjectValidator
|
||||
{
|
||||
[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;
|
||||
}
|
||||
|
||||
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