| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | namespace Trailblazer.Support; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Marks a property as transient, indicating that it holds frame-local state |
| | | 7 | | /// that can be synchronized from another instance or cleared back to defaults. |
| | | 8 | | /// </summary> |
| | | 9 | | /// <remarks> |
| | | 10 | | /// When a default value source and member are provided via the two-argument constructor, |
| | | 11 | | /// <see cref="ITransient.ClearTransientState"/> resets the property to that static member's value |
| | | 12 | | /// instead of <c>default(T)</c>. Useful for types whose zero-value is not a valid reset state |
| | | 13 | | /// (e.g. identity matrices or quaternions). |
| | | 14 | | /// </remarks> |
| | | 15 | | [AttributeUsage(AttributeTargets.Property)] |
| | | 16 | | public class TransientAttribute : Attribute |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// Gets the type that declares the static member to use as the clear default, or <c>null</c> |
| | | 20 | | /// to use <c>default(T)</c>. |
| | | 21 | | /// </summary> |
| | | 22 | | public Type? DefaultValueSource { get; } |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Gets the name of the static field or property on <see cref="DefaultValueSource"/> to use |
| | | 26 | | /// as the clear default, or <c>null</c> to use <c>default(T)</c>. |
| | | 27 | | /// </summary> |
| | | 28 | | public string? DefaultValueMember { get; } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Marks the property as transient and clears it to <c>default(T)</c> on reset. |
| | | 32 | | /// </summary> |
| | 80 | 33 | | public TransientAttribute() { } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Marks the property as transient and clears it to a specific static member value on reset. |
| | | 37 | | /// </summary> |
| | | 38 | | /// <param name="defaultValueSource">The type declaring the static default member.</param> |
| | | 39 | | /// <param name="defaultValueMember">The name of the static field or property to read.</param> |
| | 4 | 40 | | public TransientAttribute(Type defaultValueSource, string defaultValueMember) |
| | | 41 | | { |
| | 4 | 42 | | DefaultValueSource = defaultValueSource; |
| | 4 | 43 | | DefaultValueMember = defaultValueMember; |
| | 4 | 44 | | } |
| | | 45 | | } |