generated from Nexus-Mods/NexusMods.App.Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from Nexus-Mods/struct-readonly-model
Swap ReadModels over to readonly structs
- Loading branch information
Showing
9 changed files
with
207 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/NexusMods.MnemonicDB.Abstractions/IndexSegments/ValueEntities.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using NexusMods.MnemonicDB.Abstractions.Models; | ||
|
||
namespace NexusMods.MnemonicDB.Abstractions.IndexSegments; | ||
|
||
/// <summary> | ||
/// A wrapper around Values that auto-creates the given ReadModel on-the-fly | ||
/// </summary> | ||
public readonly struct ValueEntities<TModel> : IReadOnlyCollection<TModel> | ||
where TModel : IReadOnlyModel<TModel> | ||
{ | ||
private readonly Values<EntityId, ulong> _values; | ||
|
||
/// <summary> | ||
/// The database the models are read from | ||
/// </summary> | ||
private IDb Db { get; } | ||
|
||
/// <summary> | ||
/// Creates a new ValueEntities, from the given values, database, and entity id | ||
/// </summary> | ||
public ValueEntities(Values<EntityId, ulong> values, IDb db) | ||
{ | ||
_values = values; | ||
Db = db; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IEnumerator<TModel> GetEnumerator() | ||
{ | ||
foreach (var value in _values) | ||
{ | ||
yield return TModel.Create(Db, value); | ||
} | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
|
||
|
||
/// <inheritdoc /> | ||
public int Count => _values.Count; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
src/NexusMods.MnemonicDB.Abstractions/Models/IReadOnlyConcreteModel.cs
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
src/NexusMods.MnemonicDB.Abstractions/Models/IReadOnlyModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace NexusMods.MnemonicDB.Abstractions.Models; | ||
|
||
/// <summary> | ||
/// Base interface for all read-only models | ||
/// </summary> | ||
public interface IReadOnlyModel : IHasEntityIdAndDb, IReadOnlyCollection<IReadDatom> | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Typed version of IReadOnlyModel, that has a static Create method | ||
/// </summary> | ||
public interface IReadOnlyModel<out TModel> : IReadOnlyModel | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of the model with the given id | ||
/// </summary> | ||
public static abstract TModel Create(IDb db, EntityId id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters