feat: new ValueProvider improvements and source generator.

This commit is contained in:
redglow
2026-07-20 11:06:35 +02:00
parent 036e4af431
commit c540b99eb6
12 changed files with 79 additions and 37 deletions
+14 -6
View File
@@ -3,13 +3,14 @@ using System;
namespace GodotHostTest.AetherBind;
/// <summary>
/// An object that allows communication through scopes, by providing a couple getter/setter that can be injected in
/// different scopes.
/// An object that allows communication through scopes (or inside the scope itself) by providing a couple getter/setter that can be injected in different scopes (or the same scope).
/// </summary>
/// <typeparam name="T">The type that's been passed through scopes.</typeparam>
/// <seealso cref="BuilderExtensions.AddValueProvider" />
/// <seealso cref="BuilderExtensions.AddValueProvider{TValueType,TScope}" />
/// <seealso cref="BuilderExtensions.AddValueProvider{TValueType,TSourceScope,TDestinationScope}" />
public class ValueProvider<T>
{
private IValueGetter<T>? _getter;
private bool _isSet;
private T? _value;
@@ -20,9 +21,16 @@ public class ValueProvider<T>
public IValueSetter<T> Setter { get; }
public IValueGetter<T> Getter => !_isSet
? throw new InvalidOperationException($"Value of type {typeof(T)} has not been set yet.")
: new GetterImplementation(_value!);
public IValueGetter<T> Getter
{
get
{
_getter ??= !_isSet
? throw new InvalidOperationException($"Value of type {typeof(T)} has not been set yet.")
: new GetterImplementation(_value!);
return _getter;
}
}
private class SetterImplementation(ValueProvider<T> valueProvider) : IValueSetter<T>
{