Overall; fixed design of IState.cs and IReadOnlyState.cs, and fixed namespaces in Beam.Abstractions to remove all references of Beam.Abstract.

This commit is contained in:
qwsdcvghyu89
2025-09-26 14:21:38 +10:00
parent 67c6a46b09
commit db9bdecea6
20 changed files with 42 additions and 41 deletions
+10 -13
View File
@@ -1,25 +1,22 @@
using System.Text.Json.Serialization;
using Beam.Abstractions;
namespace Beam.Models {
public readonly struct ImmutableState {
readonly string[] state;
public readonly struct ImmutableState : IReadOnlyState {
private readonly string[] state;
[JsonConstructor]
public ImmutableState(string[] state) {
this.state = state ?? [];
public ImmutableState(params IEnumerable<string> state) {
this.state = state.ToArray();
}
public string[] State => state ?? [];
public readonly Span<string> AsSpan() => state ?? [];
public ReadOnlySpan<string> GetState() => this.state;
public readonly State Copy()
=> new((string[])(state ?? []).Clone());
public readonly string this[Index i] {
get => state[i];
}
IState IReadOnlyState.Copy()
=> Copy();
public readonly string this[Index i] => state[i];
public static implicit operator State(ImmutableState state)
=> state.Copy();
}
+6 -3
View File
@@ -3,18 +3,21 @@
namespace Beam.Models {
public class State(string[] state) : IState {
string[] state = state;
public string[] GetState() => state;
public void SetState(string[] state) => this.state = state;
public IReadOnlyState AsReadOnly() => new ImmutableState(this.state);
public State Copy()
=> new((string[])state.Clone());
IReadOnlyState IReadOnlyState.Copy()
=> Copy();
IState IState.Copy()
=> Copy();
public static implicit operator ImmutableState(State state) => new ImmutableState(state.GetState());
public string this[Index i] {
get => state[i];
set => state[i] = value;