// ReSharper disable MemberCanBePrivate.Global
namespace AIStudio.Tools.AssistantSessions;
///
/// Stores one typed value in an assistant session snapshot.
///
/// The captured value type.
public sealed record AssistantSessionSnapshotField : IAssistantSessionSnapshotField
{
///
/// Initializes a new typed snapshot field.
///
/// The captured value.
public AssistantSessionSnapshotField(T value)
{
this.Value = value;
}
///
/// Gets the captured value.
///
public T Value { get; }
///
public Type ValueType => typeof(T);
///
public bool TryRead(out TValue? value)
{
if (this.Value is TValue typedValue)
{
value = typedValue;
return true;
}
if (this.Value is null && default(TValue) is null)
{
value = default;
return true;
}
value = default;
return false;
}
}