src/Orleans.Core.Abstractions/Core/GrainExtensions.cs
/// <summary>
/// Returns a reference to the provided grain.
/// </summary>
/// <param name="grain">The grain to create a reference for.</param>
/// <returns>A reference to the provided grain.</returns>
Returns a reference to the provided grain.
Returns a reference to the provided grain .
internal static GrainReference AsReference(this IAddressable grain)
        {
            if (grain is null)
            {
                ThrowGrainNull();
            }
            var reference = grain as GrainReference;
            if (reference != null) return reference;
            var context = grain switch
            {
                Grain grainBase => grainBase.GrainContext,
                IGrainBase activation => activation.GrainContext,
                ISystemTargetBase systemTarget => systemTarget,
                _ => throw new ArgumentException(GetWrongGrainTypeErrorMessage(grain), nameof(grain))
            };
            if (context?.GrainReference is not { } grainRef)
            {
                throw new ArgumentException(WRONG_GRAIN_ERROR_MSG, nameof(grain));
            }
            return grainRef;
        }
internal static GrainReference AsReference ( this IAddressable grain ) { if ( grain is null ) { ThrowGrainNull ( ) ; } var reference = grain as GrainReference ; if ( reference != null ) return reference ; var context = grain switch { Grain grainBase => grainBase . GrainContext , IGrainBase activation => activation . GrainContext , ISystemTargetBase systemTarget => systemTarget , _ => throw new ArgumentException ( GetWrongGrainTypeErrorMessage ( grain ) , nameof ( grain ) ) } ; if ( context ? . GrainReference is not { } grainRef ) { throw new ArgumentException ( WRONG_GRAIN_ERROR_MSG , nameof ( grain ) ) ; } return grainRef ; }
Returns a reference to the provided grain.
Returns a reference to the provided grain .
// When called against an instance of a grain reference class, do nothing
A reference to the provided grain.
A reference to the provided grain .
IAddressable
this
grain
The grain to create a reference for.
The grain to create a reference for .