Skip to content

Commit

Permalink
Add more attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
erri120 committed Nov 13, 2024
1 parent 1bf97f4 commit 8d4321f
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 51 deletions.
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);
}
}
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);
}
}
18 changes: 18 additions & 0 deletions src/NexusMods.MnemonicDB.Abstractions/Attributes/SizeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using JetBrains.Annotations;
using NexusMods.MnemonicDB.Abstractions.ValueSerializers;
using NexusMods.Paths;

namespace NexusMods.MnemonicDB.Abstractions.Attributes;

/// <summary>
/// An attribute that holds an <see cref="Size"/>.
/// </summary>
[PublicAPI]
public sealed class SizeAttribute(string ns, string name) : ScalarAttribute<Size, ulong, UInt64Serializer>(ns, name)
{
/// <inheritdoc/>
protected override ulong ToLowLevel(Size value) => value.Value;

/// <inheritdoc/>
protected override Size FromLowLevel(ulong value, AttributeResolver resolver) => Size.From(value);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
using NexusMods.MnemonicDB.Abstractions;
using NexusMods.MnemonicDB.Abstractions.Attributes;
using NexusMods.MnemonicDB.Abstractions.ElementComparers;
using JetBrains.Annotations;
using NexusMods.MnemonicDB.Abstractions.ValueSerializers;

namespace NexusMods.MnemonicDB.TestModel.Attributes;
namespace NexusMods.MnemonicDB.Abstractions.Attributes;

/// <summary>
/// An attribute that holds a collection of strings.
/// </summary>
[PublicAPI]
public sealed class StringsAttribute(string ns, string name) : CollectionAttribute<string, string, Utf8Serializer>(ns, name)
{
/// <inheritdoc/>
protected override string ToLowLevel(string value) => value;

/// <inheritdoc/>
protected override string FromLowLevel(string value, AttributeResolver resolver) => value;
}
3 changes: 2 additions & 1 deletion tests/NexusMods.MnemonicDB.TestModel/ArchiveFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NexusMods.MnemonicDB.Abstractions.Models;
using NexusMods.MnemonicDB.Abstractions.Attributes;
using NexusMods.MnemonicDB.Abstractions.Models;
using NexusMods.MnemonicDB.TestModel.Attributes;

namespace NexusMods.MnemonicDB.TestModel;
Expand Down

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions tests/NexusMods.MnemonicDB.TestModel/Attributes/SizeAttribute.cs

This file was deleted.

0 comments on commit 8d4321f

Please sign in to comment.