using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime.Serialization; namespace StabilityMatrix.Core.Models; public abstract record StringValue(string Value) : IFormattable { /// public override string ToString() { return Value; } /// public string ToString(string? format, IFormatProvider? formatProvider) { return Value; } /// /// Get all values of type as a dictionary. /// Includes all public static properties. /// protected static Dictionary GetValues< [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T >() where T : StringValue { var values = new Dictionary(); foreach (var field in typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Static)) { if (field.GetValue(null) is T value) { // Exclude if IgnoreDataMember if (field.GetCustomAttribute() is not null) continue; values.Add(value.Value, value); } } return values; } }