/// <summary> /// 异步设置对象标识。 /// </summary> /// <param name="identifier">给定的 <see cref="IObjectIdentifier"/>。</param> /// <param name="newIdFactory">给定的新对象标识工厂方法。</param> /// <param name="cancellationToken">给定的 <see cref="CancellationToken"/>(可选)。</param> /// <returns>返回一个包含标识(兼容各种引用与值类型标识)的异步操作。</returns> public static async ValueTask <object> SetObjectIdAsync(this IObjectIdentifier identifier, Func <object, object> newIdFactory, CancellationToken cancellationToken = default) { var currentId = await identifier.GetObjectIdAsync(cancellationToken).DisableAwaitContext(); return(await identifier.SetObjectIdAsync(newIdFactory(currentId), cancellationToken) .DisableAwaitContext()); }
public static async ValueTask <object> SetObjectIdAsync(this IObjectIdentifier identifier, Func <object, object> newIdFactory, CancellationToken cancellationToken = default) { identifier.NotNull(nameof(identifier)); newIdFactory.NotNull(nameof(newIdFactory)); var newId = await identifier.GetObjectIdAsync(cancellationToken).ConfigureAwait(); return(await identifier.SetObjectIdAsync(newIdFactory.Invoke(newId), cancellationToken) .ConfigureAwait()); }