feat: automatic injection of elements in scene.

This commit is contained in:
redglow
2026-07-17 15:14:40 +02:00
parent 659baff30c
commit 5ad3af84b2
15 changed files with 86 additions and 219 deletions
+33
View File
@@ -0,0 +1,33 @@
using System.Collections.Generic;
namespace GodotHostTest.GodotDI;
public static class EnumerableExtensions
{
public enum SingleFailureReason
{
LessThanOne,
MoreThanOne
}
public static T? Single<T>(this IEnumerable<T> enumerable, out SingleFailureReason? failureReason)
where T : class
{
using var enumerator = enumerable.GetEnumerator();
if (!enumerator.MoveNext())
{
failureReason = SingleFailureReason.LessThanOne;
return null;
}
var value = enumerator.Current;
if (enumerator.MoveNext())
{
failureReason = SingleFailureReason.MoreThanOne;
return null;
}
failureReason = null;
return value;
}
}