Added initial version 0.1.0

This commit is contained in:
Anders Ejlersen 2026-05-17 22:12:04 +02:00
parent 6aa4cb8596
commit 416759c213
64 changed files with 2181 additions and 0 deletions

View file

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using UnityEngine;
namespace Module.ProjectValidator.Editor
{
internal sealed class ValidatorList
{
private readonly Dictionary<Type, object> _validators = new();
public void Add(Type type)
{
if (type.IsInterface || type.IsAbstract)
return;
var typeValidator = type.GetInterfaces().FirstOrDefault(typeInterface => typeInterface.IsGenericType && typeInterface.GetGenericTypeDefinition() == typeof(IAttributeValidator<>));
var attType = typeValidator?.GetGenericArguments()[0];
if (attType == null)
return;
try
{
var instance = FormatterServices.GetUninitializedObject(type);
_validators.Add(attType, instance);
}
catch (Exception e)
{
Debug.LogException(e);
}
}
public bool TryGetValue(Type type, out object validatorInstance)
{
return _validators.TryGetValue(type, out validatorInstance);
}
}
}