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 #113 from Nexus-Mods/feat/more-attributes
More attributes and misc improvements
- Loading branch information
Showing
38 changed files
with
434 additions
and
110 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/NexusMods.MnemonicDB.Abstractions/Attributes/AbsolutePathAttribute.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 JetBrains.Annotations; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NexusMods.MnemonicDB.Abstractions.ValueSerializers; | ||
using NexusMods.Paths; | ||
|
||
namespace NexusMods.MnemonicDB.Abstractions.Attributes; | ||
|
||
/// <summary> | ||
/// An attribute that holds an <see cref="AbsolutePath"/>. | ||
/// </summary> | ||
[PublicAPI] | ||
public sealed class AbsolutePathAttribute(string ns, string name) : ScalarAttribute<AbsolutePath, string, Utf8InsensitiveSerializer>(ns, name) | ||
{ | ||
/// <inheritdoc/> | ||
protected override string ToLowLevel(AbsolutePath value) => value.ToString(); | ||
|
||
/// <inheritdoc/> | ||
protected override AbsolutePath FromLowLevel(string value, AttributeResolver resolver) | ||
{ | ||
return resolver.ServiceProvider.GetRequiredService<IFileSystem>().FromUnsanitizedFullPath(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
17 changes: 17 additions & 0 deletions
17
src/NexusMods.MnemonicDB.Abstractions/Attributes/BooleanAttribute.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 boolean value. | ||
/// </summary> | ||
[PublicAPI] | ||
public sealed class BooleanAttribute(string ns, string name) : ScalarAttribute<bool, byte, UInt8Serializer>(ns, name) | ||
{ | ||
/// <inheritdoc/> | ||
protected override byte ToLowLevel(bool value) => value ? (byte)1 : (byte)0; | ||
|
||
/// <inheritdoc/> | ||
protected override bool FromLowLevel(byte value, AttributeResolver resolver) => value == 1; | ||
} |
3 changes: 2 additions & 1 deletion
3
src/NexusMods.MnemonicDB.Abstractions/Attributes/CardinalityAttribute.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
4 changes: 3 additions & 1 deletion
4
src/NexusMods.MnemonicDB.Abstractions/Attributes/CollectionAttribute.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
53 changes: 53 additions & 0 deletions
53
src/NexusMods.MnemonicDB.Abstractions/Attributes/EnumAttribute.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,53 @@ | ||
using System; | ||
using JetBrains.Annotations; | ||
using NexusMods.MnemonicDB.Abstractions.ValueSerializers; | ||
|
||
namespace NexusMods.MnemonicDB.Abstractions.Attributes; | ||
|
||
/// <summary> | ||
/// An attribute that holds an enum value backed by an int32 value. | ||
/// </summary> | ||
[PublicAPI] | ||
public sealed class EnumAttribute<T>(string ns, string name) : ScalarAttribute<T, int, Int32Serializer>(ns, name) | ||
where T : Enum | ||
{ | ||
/// <inheritdoc /> | ||
protected override int ToLowLevel(T value) | ||
{ | ||
// NOTE(halgari): Looks like an allocation, but the cast to object is removed by the JIT since the type of | ||
// T is a compile-time constant. Verified via sharpLab.io: | ||
// https://sharplab.io/#v2:EYLgtghglgdgNAFxBAzmAPgAQEwEYCwAUJgAwAEAygBYQBOADgDITAB0ASgK4wJRgCmAbiJEA2gCkoCAOL8Y/WlADGACgQBPevwD2AMxUBZdQFEYnMAEoLAXTKYAzHexkAwgB4AKgD4yAdyoK/GQeZCBkpuZkAN5EZHHxDmSwCGQGKiEAbhAANpz8FtGx8cWYAOxkKskWKtrAAFb8SggWWblCRXEAvkTdhESJcpFGEWDRZABi2tpkALxkJHBkAEJ0s2S4ZJ2CQA= | ||
return (int)(object)value; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override T FromLowLevel(int value, AttributeResolver resolver) | ||
{ | ||
// Same as ToLowLevel, the cast to object is removed by the JIT | ||
return (T)(object)value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// An attribute that holds an enum value backed by a byte value. | ||
/// </summary> | ||
[PublicAPI] | ||
public sealed class EnumByteAttribute<T>(string ns, string name) : ScalarAttribute<T, byte, UInt8Serializer>(ns, name) | ||
where T : Enum | ||
{ | ||
/// <inheritdoc /> | ||
protected override byte ToLowLevel(T value) | ||
{ | ||
// NOTE(halgari): Looks like an allocation, but the cast to object is removed by the JIT since the type of | ||
// T is a compile-time constant. Verified via sharpLab.io: | ||
// https://sharplab.io/#v2:EYLgtghglgdgNAFxBAzmAPgAQEwEYCwAUJgAwAEAygBYQBOADgDITAB0ASgK4wJRgCmAbiJEA2gCkoCAOL8Y/WlADGACgQBPevwD2AMxUBZdQFEYnMAEoLAXTKYAzHexkAwgB4AKgD4yAdyoK/GQeZCBkpuZkAN5EZHHxDmSwCGQGKiEAbhAANpz8FtGx8cWYAOxkKskWKtrAAFb8SggWWblCRXEAvkTdhESJcpFGEWDRZABi2tpkALxkJHBkAEJ0s2S4ZJ2CQA= | ||
return (byte)(object)value; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override T FromLowLevel(byte value, AttributeResolver resolver) | ||
{ | ||
// Same as ToLowLevel, the cast to object is removed by the JIT | ||
return (T)(object)value; | ||
} | ||
} |
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; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/NexusMods.MnemonicDB.Abstractions/Attributes/Int16Attribute.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 an int16 value. | ||
/// </summary> | ||
[PublicAPI] | ||
public sealed class Int16Attribute(string ns, string name) : ScalarAttribute<short, short, Int16Serializer>(ns, name) | ||
{ | ||
/// <inheritdoc /> | ||
protected override short ToLowLevel(short value) => value; | ||
|
||
/// <inheritdoc /> | ||
protected override short FromLowLevel(short value, AttributeResolver resolver) => value; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/NexusMods.MnemonicDB.Abstractions/Attributes/Int32Attribute.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 an int32 value. | ||
/// </summary> | ||
[PublicAPI] | ||
public sealed class Int32Attribute(string ns, string name) : ScalarAttribute<int, int, Int32Serializer>(ns, name) | ||
{ | ||
/// <inheritdoc /> | ||
protected override int ToLowLevel(int value) => value; | ||
|
||
/// <inheritdoc /> | ||
protected override int FromLowLevel(int value, AttributeResolver resolver) => value; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/NexusMods.MnemonicDB.Abstractions/Attributes/Int64Attribute.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 an uint64 value. | ||
/// </summary> | ||
[PublicAPI] | ||
public sealed class Int64Attribute(string ns, string name) : ScalarAttribute<long, long, Int64Serializer>(ns, name) | ||
{ | ||
/// <inheritdoc /> | ||
protected override long ToLowLevel(long value) => value; | ||
|
||
/// <inheritdoc /> | ||
protected override long FromLowLevel(long 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
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
22 changes: 22 additions & 0 deletions
22
src/NexusMods.MnemonicDB.Abstractions/Attributes/RelativePathAttribute.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 JetBrains.Annotations; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NexusMods.MnemonicDB.Abstractions.ValueSerializers; | ||
using NexusMods.Paths; | ||
|
||
namespace NexusMods.MnemonicDB.Abstractions.Attributes; | ||
|
||
/// <summary> | ||
/// An attribute that holds an <see cref="RelativePath"/>. | ||
/// </summary> | ||
[PublicAPI] | ||
public sealed class RelativePathAttribute(string ns, string name) : ScalarAttribute<RelativePath, string, Utf8InsensitiveSerializer>(ns, name) | ||
{ | ||
/// <inheritdoc/> | ||
protected override string ToLowLevel(RelativePath value) => value.ToString(); | ||
|
||
/// <inheritdoc/> | ||
protected override RelativePath FromLowLevel(string value, AttributeResolver resolver) | ||
{ | ||
return new RelativePath(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
Oops, something went wrong.