Added component validators

This commit is contained in:
Anders Ejlersen 2026-05-18 20:37:05 +02:00
parent 35f271e12b
commit d7145ad772
30 changed files with 448 additions and 200 deletions

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: b550bfeed6d6bb840972d41daa80bbd3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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");
}
}
}
}

View file

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 752bd3df42129e14cadaf285192455f4

View 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);
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 48d9acd22b7744faa4b826f26311b5b3
timeCreated: 1779123421