public static TPublishedBy SetPublishedBy <TPublishedBy, TPublishedTime> (this IPublication <TPublishedBy, TPublishedTime> publication, Func <TPublishedBy, TPublishedBy> newPublishedByFactory) where TPublishedBy : IEquatable <TPublishedBy> where TPublishedTime : struct { publication.NotNull(nameof(publication)); return(publication.PublishedBy = newPublishedByFactory.Invoke(publication.PublishedBy)); }
/// <summary> /// 异步获取发表者。 /// </summary> /// <typeparam name="TPublishedBy">指定的发表者类型。</typeparam> /// <typeparam name="TPublishedTime">指定的发表时间类型(兼容 <see cref="DateTime"/> 或 <see cref="DateTimeOffset"/>)。</typeparam> /// <param name="publication">给定的 <see cref="IPublication{TPublishedBy, TPublishedTime}"/>。</param> /// <param name="newPublishedByFactory">给定的新发表者工厂方法。</param> /// <param name="cancellationToken">给定的 <see cref="CancellationToken"/>(可选)。</param> /// <returns>返回一个包含 <typeparamref name="TPublishedBy"/>(兼容标识或字符串)的异步操作。</returns> public static ValueTask <TPublishedBy> SetPublishedByAsync <TPublishedBy, TPublishedTime>( this IPublication <TPublishedBy, TPublishedTime> publication, Func <TPublishedBy, TPublishedBy> newPublishedByFactory, CancellationToken cancellationToken = default) where TPublishedBy : IEquatable <TPublishedBy> where TPublishedTime : struct { publication.NotNull(nameof(publication)); return(cancellationToken.RunOrCancelValueAsync(() => publication.PublishedBy = newPublishedByFactory.Invoke(publication.PublishedBy))); }