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.
- Loading branch information
Showing
5 changed files
with
59 additions
and
4 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
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
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