< Summary

Information
Class: Trailblazer.Support.TransientAttribute
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Support/TransientState/TransientAttribute.cs
Line coverage
100%
Covered lines: 5
Uncovered lines: 0
Coverable lines: 5
Total lines: 52
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
.ctor(...)100%11100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Support/TransientState/TransientAttribute.cs

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