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