-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add attribute to specify property order
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/Yarhl/IO/Serialization/Attributes/BinaryFieldOrderAttribute.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,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; } | ||
} |