Skip to content

Commit

Permalink
✨ Add attribute to specify property order
Browse files Browse the repository at this point in the history
  • Loading branch information
pleonex committed Jan 30, 2024
1 parent b3e8010 commit 9da7e72
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Yarhl/IO/Serialization/Attributes/BinaryFieldOrderAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Yarhl.IO.Serialization.Attributes;

using System;

/// <summary>
/// Specify the order to serialize or deserialize the fields in binary format.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class BinaryFieldOrderAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="BinaryFieldOrderAttribute"/> class.
/// </summary>
/// <param name="order">The order of the field in the binary serialization.</param>
/// <exception cref="ArgumentOutOfRangeException">The order is less than 0.</exception>
public BinaryFieldOrderAttribute(int order)
{
if (order < 0) {
throw new ArgumentOutOfRangeException(nameof(order));
}

Order = order;
}

/// <summary>
/// Gets or sets the order of the field in the binary format.
/// </summary>
public int Order { get; set; }
}

0 comments on commit 9da7e72

Please sign in to comment.