Added component validators
This commit is contained in:
parent
35f271e12b
commit
d7145ad772
30 changed files with 448 additions and 200 deletions
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b550bfeed6d6bb840972d41daa80bbd3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 752bd3df42129e14cadaf285192455f4
|
||||
10
Runtime/Interfaces/IComponentValidator.cs
Normal file
10
Runtime/Interfaces/IComponentValidator.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.ProjectValidator
|
||||
{
|
||||
public interface IComponentValidator<in T> where T : Component
|
||||
{
|
||||
void Validate(T component, List<ValidatorResult> results);
|
||||
}
|
||||
}
|
||||
3
Runtime/Interfaces/IComponentValidator.cs.meta
Normal file
3
Runtime/Interfaces/IComponentValidator.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 48d9acd22b7744faa4b826f26311b5b3
|
||||
timeCreated: 1779123421
|
||||
Loading…
Add table
Add a link
Reference in a new issue