src/Orleans.Serialization/Session/ReferencedObjectCollection.cs
/// <summary>
/// Gets or adds a reference.
/// </summary>
/// <param name="value">The value.</param>
/// <param name="reference">The reference.</param>
/// <returns><see langword="true" /> if a reference already existed, <see langword="false" /> otherwise.</returns>
Gets or adds a reference.
Gets or adds a reference .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool GetOrAddReference(object value, out uint reference)
        {
            var nextReference = ++CurrentReferenceId;
            if (value is null)
            {
                reference = 0;
                return true;
            }
            for (int i = 0; i < _objectToReferenceCount; ++i)
            {
                if (ReferenceEquals(_objectToReference[i].Object, value))
                {
                    reference = _objectToReference[i].Id;
                    return true;
                }
            }
            if (_objectToReferenceOverflow is { } overflow)
            {
                if (overflow.TryGetValue(value, out var existing))
                {
                    reference = existing;
                    return true;
                }
                else
                {
                    reference = nextReference;
                    overflow[value] = reference;
                }
            }
            reference = nextReference;
            AddToReferenceToIdMap(value, reference);
            return false;
        }
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ] public bool GetOrAddReference ( object value , out uint reference ) { var nextReference = ++ CurrentReferenceId ; if ( value is null ) { reference = 0 ; return true ; } for ( int i = 0 ; i < _objectToReferenceCount ; ++ i ) { if ( ReferenceEquals ( _objectToReference [ i ] . Object , value ) ) { reference = _objectToReference [ i ] . Id ; return true ; } } if ( _objectToReferenceOverflow is { } overflow ) { if ( overflow . TryGetValue ( value , out var existing ) ) { reference = existing ; return true ; } else { reference = nextReference ; overflow [ value ] = reference ; } } reference = nextReference ; AddToReferenceToIdMap ( value , reference ) ; return false ; }
Gets or adds a reference.
Gets or adds a reference .
// Unconditionally bump the reference counter since a call to this method signifies a potential reference. // Null is always at reference 0 // Add the reference.
if a reference already existed,  otherwise.
if a reference already existed otherwise .
value
object
None
uint
out
reference
None