/// <summary> /// 获取创建时间。 /// </summary> /// <typeparam name="TPublishedTime">指定的创建时间类型(兼容 <see cref="DateTime"/> 或 <see cref="DateTimeOffset"/>)。</typeparam> /// <param name="publicationTime">给定的 <see cref="IPublicationTime{TPublishedTime}"/>。</param> /// <param name="newPublishedTimeFactory">给定的新创建时间工厂方法。</param> /// <returns>返回 <typeparamref name="TPublishedTime"/>(兼容 <see cref="DateTime"/> 或 <see cref="DateTimeOffset"/>)。</returns> public static TPublishedTime SetPublishedTime <TPublishedTime>(this IPublicationTime <TPublishedTime> publicationTime, Func <TPublishedTime, TPublishedTime> newPublishedTimeFactory) where TPublishedTime : struct { publicationTime.SetCreatedTime(newPublishedTimeFactory); return(publicationTime.PublishedTime = newPublishedTimeFactory(publicationTime.PublishedTime)); }
/// <summary> /// 异步获取创建时间。 /// </summary> /// <typeparam name="TPublishedTime">指定的创建时间类型(兼容 <see cref="DateTime"/> 或 <see cref="DateTimeOffset"/>)。</typeparam> /// <param name="publicationTime">给定的 <see cref="IPublicationTime{TPublishedTime}"/>。</param> /// <param name="newPublishedTimeFactory">给定的新创建时间工厂方法。</param> /// <param name="cancellationToken">给定的 <see cref="CancellationToken"/>(可选)。</param> /// <returns>返回一个包含 <typeparamref name="TPublishedTime"/> (兼容 <see cref="DateTime"/> 或 <see cref="DateTimeOffset"/>)的异步操作。</returns> public static async ValueTask <TPublishedTime> SetPublishedTimeAsync <TPublishedTime>(this IPublicationTime <TPublishedTime> publicationTime, Func <TPublishedTime, TPublishedTime> newPublishedTimeFactory, CancellationToken cancellationToken = default) where TPublishedTime : struct { await publicationTime.SetCreatedTimeAsync(newPublishedTimeFactory, cancellationToken).DisableAwaitContext(); return(publicationTime.PublishedTime = newPublishedTimeFactory(publicationTime.PublishedTime)); }