< Summary

Class:GDX.Developer.TransientReference
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Developer/TransientReference.cs
Covered lines:42
Uncovered lines:21
Coverable lines:63
Total lines:185
Line coverage:66.6% (42 of 63)
Covered branches:0
Total branches:0
Covered methods:10
Total methods:12
Method coverage:83.3% (10 of 12)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TransientReference(...)0%110100%
TransientReference(...)0%110100%
TransientReference(...)0%2100%
CompareTo(...)0%3.043083.33%
CompareTo(...)0%3.043083.33%
CompareTo(...)0%3.043083.33%
Equals(...)0%2.152066.67%
Equals(...)0%6200%
Equals(...)0%8.125050%
GetHashCode()0%2.152066.67%
operator==(...)0%110100%
operator!=(...)0%110100%

File(s)

./Packages/com.dotbunny.gdx/GDX/Developer/TransientReference.cs

#LineLine coverage
 1// Copyright (c) 2020-2024 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System;
 6using System.Runtime.Serialization;
 7
 8namespace GDX.Developer
 9{
 10    /// <summary>
 11    ///     A comparable weak reference to an object which will not prevent garbage collection. It will positively
 12    ///     compare against similar targeted reference trackers as well as the actual target object.
 13    /// </summary>
 14    /// <remarks>
 15    ///     There isn't a lot of great use cases for using this sort of thing; <see cref="WeakReference" /> on its own
 16    ///     is sufficient in most of the use cases, however this particular arrangement is useful for developer-ish
 17    ///     stuff.
 18    /// </remarks>
 19    public class TransientReference : WeakReference, IComparable, IComparable<TransientReference>,
 20        IComparable<WeakReference>, IEquatable<TransientReference>,
 21        IEquatable<WeakReference>
 22    {
 23        /// <summary>
 24        ///     Create a <see cref="TransientReference" /> referencing the <paramref name="target" />.
 25        /// </summary>
 26        /// <param name="target">The target <see cref="object" /> to reference.</param>
 1797527        public TransientReference(object target) : base(target)
 1797528        {
 1797529        }
 30
 31        /// <summary>
 32        ///     Create a <see cref="TransientReference" /> referencing the <paramref name="target" />.
 33        /// </summary>
 34        /// <param name="target">The target <see cref="object" /> to reference.</param>
 35        /// <param name="trackResurrection">Should the object remain tracked after it has been finalized.</param>
 536        public TransientReference(object target, bool trackResurrection) : base(target, trackResurrection)
 537        {
 538        }
 39
 40        /// <summary>
 41        ///     Create a <see cref="TransientReference" /> from the <paramref name="info" />.
 42        /// </summary>
 43        /// <param name="info">A <see cref="SerializationInfo" /> representation of a <see cref="TransientReference" />.
 44        /// <param name="context">Describes the source of the <see cref="SerializationInfo" />.</param>
 045        protected TransientReference(SerializationInfo info, StreamingContext context) : base(info, context)
 046        {
 047        }
 48
 49        /// <summary>
 50        ///     Compare this <see cref="TransientReference" /> to the target <see cref="object" />.
 51        /// </summary>
 52        /// <param name="obj">The target <see cref="object" /> to compare against.</param>
 53        /// <returns>1 if the same, 0 otherwise.</returns>
 54        public int CompareTo(object obj)
 155        {
 156            if (obj == Target || (TransientReference)obj == this)
 157            {
 158                return 1;
 59            }
 60
 061            return 0;
 162        }
 63
 64        /// <summary>
 65        ///     Compare this <see cref="TransientReference" /> to the target <see cref="TransientReference" />.
 66        /// </summary>
 67        /// <param name="obj">The target <see cref="TransientReference" /> to compare against.</param>
 68        /// <returns>1 if the same, 0 otherwise.</returns>
 69        public int CompareTo(TransientReference obj)
 270        {
 271            if (obj.Target == Target || obj == this)
 172            {
 173                return 1;
 74            }
 75
 176            return 0;
 277        }
 78
 79        /// <summary>
 80        ///     Compare this <see cref="TransientReference" /> to the target <see cref="WeakReference" />.
 81        /// </summary>
 82        /// <param name="obj">The target <see cref="WeakReference" /> to compare against.</param>
 83        /// <returns>1 if the same, 0 otherwise.</returns>
 84        public int CompareTo(WeakReference obj)
 185        {
 186            if (obj.Target == Target || (TransientReference)obj == this)
 187            {
 188                return 1;
 89            }
 90
 091            return 0;
 192        }
 93
 94        /// <summary>
 95        ///     Does this <see cref="TransientReference" /> equal the target <see cref="TransientReference" />.
 96        /// </summary>
 97        /// <param name="other">The target <see cref="TransientReference" /> to compare with.</param>
 98        /// <returns>true if it is the same, false otherwise.</returns>
 99        public bool Equals(TransientReference other)
 1100        {
 1101            if (other == null)
 0102            {
 0103                return false;
 104            }
 105
 1106            return Target == other.Target;
 1107        }
 108
 109        /// <summary>
 110        ///     Does this <see cref="TransientReference" /> equal the target <see cref="WeakReference" />.
 111        /// </summary>
 112        /// <param name="other">The target <see cref="WeakReference" /> to compare with.</param>
 113        /// <returns>true if it is the same, false otherwise.</returns>
 114        public bool Equals(WeakReference other)
 0115        {
 0116            if (other == null)
 0117            {
 0118                return false;
 119            }
 120
 0121            return Target == other.Target;
 0122        }
 123
 124        /// <summary>
 125        ///     Does this <see cref="TransientReference" /> equal the target <see cref="object" />.
 126        /// </summary>
 127        /// <param name="obj">The target <see cref="object" /> to compare with.</param>
 128        /// <returns>true if it is the same, false otherwise.</returns>
 129        public override bool Equals(object obj)
 1130        {
 1131            if (ReferenceEquals(null, obj) || ReferenceEquals(this, obj))
 0132            {
 0133                return false;
 134            }
 135
 1136            if (obj == Target)
 0137            {
 0138                return true;
 139            }
 140
 1141            if (obj.GetType() != GetType())
 0142            {
 0143                return false;
 144            }
 145
 1146            return Equals((TransientReference)obj);
 1147        }
 148
 149        /// <summary>
 150        ///     Return the hashcode of the <see cref="WeakReference.Target" />.
 151        /// </summary>
 152        /// <returns>Returns the <see cref="WeakReference.Target" />'s hash code, or -1 if null.</returns>
 153        public override int GetHashCode()
 44060154        {
 44060155            if (Target == null)
 0156            {
 0157                return -1;
 158            }
 159
 44060160            return Target.GetHashCode();
 44060161        }
 162
 163        /// <summary>
 164        ///     Compare <see cref="TransientReference" />s to see if they are equal.
 165        /// </summary>
 166        /// <param name="left">Left-side <see cref="TransientReference" />.</param>
 167        /// <param name="right">Right-side <see cref="TransientReference" />.</param>
 168        /// <returns>true/false if they are equal.</returns>
 169        public static bool operator ==(TransientReference left, TransientReference right)
 2170        {
 2171            return Equals(left, right);
 2172        }
 173
 174        /// <summary>
 175        ///     Compare <see cref="TransientReference" />s to see if they are not equal.
 176        /// </summary>
 177        /// <param name="left">Left-side <see cref="TransientReference" />.</param>
 178        /// <param name="right">Right-side <see cref="TransientReference" />.</param>
 179        /// <returns>true/false if they are not equal.</returns>
 180        public static bool operator !=(TransientReference left, TransientReference right)
 17974181        {
 17974182            return !Equals(left, right);
 17974183        }
 184    }
 185}

Coverage by test methods












Methods/Properties

TransientReference(System.Object)
TransientReference(System.Object, System.Boolean)
TransientReference(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)
CompareTo(System.Object)
CompareTo(GDX.Developer.TransientReference)
CompareTo(System.WeakReference)
Equals(GDX.Developer.TransientReference)
Equals(System.WeakReference)
Equals(System.Object)
GetHashCode()
operator==(GDX.Developer.TransientReference, GDX.Developer.TransientReference)
operator!=(GDX.Developer.TransientReference, GDX.Developer.TransientReference)