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
6 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/NexusMods.MnemonicDB.Abstractions/Attributes/Float32Attribute.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,17 @@ | ||
using JetBrains.Annotations; | ||
using NexusMods.MnemonicDB.Abstractions.ValueSerializers; | ||
|
||
namespace NexusMods.MnemonicDB.Abstractions.Attributes; | ||
|
||
/// <summary> | ||
/// An attribute that holds a float32 value. | ||
/// </summary> | ||
[PublicAPI] | ||
public sealed class Float32Attribute(string ns, string name) : ScalarAttribute<float, float, Float32Serializer>(ns, name) | ||
{ | ||
/// <inheritdoc /> | ||
protected override float ToLowLevel(float value) => value; | ||
|
||
/// <inheritdoc /> | ||
protected override float FromLowLevel(float value, AttributeResolver resolver) => value; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/NexusMods.MnemonicDB.Abstractions/Attributes/Float64Attribute.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,17 @@ | ||
using JetBrains.Annotations; | ||
using NexusMods.MnemonicDB.Abstractions.ValueSerializers; | ||
|
||
namespace NexusMods.MnemonicDB.Abstractions.Attributes; | ||
|
||
/// <summary> | ||
/// An attribute that holds a float64 value. | ||
/// </summary> | ||
[PublicAPI] | ||
public sealed class Float64Attribute(string ns, string name) : ScalarAttribute<double, double, Float64Serializer>(ns, name) | ||
{ | ||
/// <inheritdoc /> | ||
protected override double ToLowLevel(double value) => value; | ||
|
||
/// <inheritdoc /> | ||
protected override double FromLowLevel(double value, AttributeResolver resolver) => value; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/NexusMods.MnemonicDB.Abstractions/Attributes/Int128Attribute.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,18 @@ | ||
using System; | ||
using JetBrains.Annotations; | ||
using NexusMods.MnemonicDB.Abstractions.ValueSerializers; | ||
|
||
namespace NexusMods.MnemonicDB.Abstractions.Attributes; | ||
|
||
/// <summary> | ||
/// An attribute that holds an int128 value. | ||
/// </summary> | ||
[PublicAPI] | ||
public sealed class Int128Attribute(string ns, string name) : ScalarAttribute<Int128, Int128, Int128Serializer>(ns, name) | ||
{ | ||
/// <inheritdoc /> | ||
protected override Int128 ToLowLevel(Int128 value) => value; | ||
|
||
/// <inheritdoc /> | ||
protected override Int128 FromLowLevel(Int128 value, AttributeResolver resolver) => value; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/NexusMods.MnemonicDB.Abstractions/Attributes/UInt128Attribute.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,18 @@ | ||
using System; | ||
using JetBrains.Annotations; | ||
using NexusMods.MnemonicDB.Abstractions.ValueSerializers; | ||
|
||
namespace NexusMods.MnemonicDB.Abstractions.Attributes; | ||
|
||
/// <summary> | ||
/// An attribute that holds an uint128 value. | ||
/// </summary> | ||
[PublicAPI] | ||
public sealed class UInt128Attribute(string ns, string name) : ScalarAttribute<UInt128, UInt128, UInt128Serializer>(ns, name) | ||
{ | ||
/// <inheritdoc /> | ||
protected override UInt128 ToLowLevel(UInt128 value) => value; | ||
|
||
/// <inheritdoc /> | ||
protected override UInt128 FromLowLevel(UInt128 value, AttributeResolver resolver) => value; | ||
} |
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,27 @@ | ||
using System; | ||
using System.Linq; | ||
using JetBrains.Annotations; | ||
using NexusMods.MnemonicDB.Abstractions.BuiltInEntities; | ||
using NexusMods.MnemonicDB.Abstractions.Models; | ||
|
||
namespace NexusMods.MnemonicDB.Abstractions; | ||
|
||
/// <summary> | ||
/// Extension methods for entities. | ||
/// </summary> | ||
[PublicAPI] | ||
public static class EntityExtensions | ||
{ | ||
/// <summary> | ||
/// Gets the timestamp of the transaction that created the model. | ||
/// </summary> | ||
public static DateTimeOffset GetCreatedAt<T>(this T model, DateTimeOffset defaultValue = default) | ||
where T : IReadOnlyModel<T> | ||
{ | ||
if (model.Count == 0) return defaultValue; | ||
var minTx = model.Min(m => m.T); | ||
|
||
var tx = new Transaction.ReadOnly(model.Db, EntityId.From(minTx.Value)); | ||
return Transaction.Timestamp.Get(tx); | ||
} | ||
} |
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