From 260caf00083eeb02de3a98be7ed5202da01a3c3c Mon Sep 17 00:00:00 2001 From: Jordan Wages Date: Tue, 23 Apr 2024 05:03:29 -0500 Subject: [PATCH] ValueFormatAttribute --- CapyKit/Attributes/ValueFormatAttribute.cs | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 CapyKit/Attributes/ValueFormatAttribute.cs diff --git a/CapyKit/Attributes/ValueFormatAttribute.cs b/CapyKit/Attributes/ValueFormatAttribute.cs new file mode 100644 index 0000000..67c7ebc --- /dev/null +++ b/CapyKit/Attributes/ValueFormatAttribute.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CapyKit.Attributes +{ + /// + /// Custom attribute for formatting values in a specific way. + /// + [AttributeUsage(AttributeTargets.Property)] + public class ValueFormatAttribute : Attribute + { + #region Properties + + /// Gets or sets the format to use for formatting the value. + /// The format string used to format the value. + public string Format { get; private set; } + + #endregion Properties + + #region Constructors + + /// + /// Default constructor. Initializes a new instance of the + /// class with an empty format string. + /// + public ValueFormatAttribute() + { + this.Format = string.Empty; + } + + /// + /// Constructor. Initializes a new instance of the class with + /// the specified format string. + /// + /// The format string used to format the value. + public ValueFormatAttribute(string format) + { + this.Format = format; + } + + #endregion Constructors + + #region Methods + + /// Gets a parameterized formatted string for the specified index. + /// (Optional) Zero-based index of the item in the string to format. + /// A formatted string with the specified index and format. + public string GetFormatParameterizedString(int index = 0) + { + return "{" + index + ":" + this.Format + "}"; + } + + #endregion Methods + } +}