/// <summary>
    /// 异步设置对象父标识。
    /// </summary>
    /// <param name="parentIdentifier">给定的 <see cref="IObjectParentIdentifier"/>。</param>
    /// <param name="newParentIdFactory">给定的新对象父标识工厂方法。</param>
    /// <param name="cancellationToken">给定的 <see cref="CancellationToken"/>(可选)。</param>
    /// <returns>返回一个包含父标识(兼容各种引用与值类型标识)的异步操作。</returns>
    public static async ValueTask <object?> SetObjectParentIdAsync(this IObjectParentIdentifier parentIdentifier,
                                                                   Func <object?, object?> newParentIdFactory, CancellationToken cancellationToken = default)
    {
        var currentParentId = await parentIdentifier.GetObjectParentIdAsync(cancellationToken).DisableAwaitContext();

        return(await parentIdentifier.SetObjectParentIdAsync(newParentIdFactory(currentParentId), cancellationToken)
               .DisableAwaitContext());
    }
Exemple #2
0
        public static async ValueTask <object> SetObjectParentIdAsync(this IObjectParentIdentifier parentIdentifier,
                                                                      Func <object, object> newParentIdFactory, CancellationToken cancellationToken = default)
        {
            parentIdentifier.NotNull(nameof(parentIdentifier));
            newParentIdFactory.NotNull(nameof(newParentIdFactory));

            var newParentId = await parentIdentifier.GetObjectParentIdAsync(cancellationToken).ConfigureAwait();

            return(await parentIdentifier.SetObjectParentIdAsync(newParentIdFactory.Invoke(newParentId), cancellationToken)
                   .ConfigureAwait());
        }