CKTIS / C#
System.TimeProvider: praktična referenca
System.TimeProvider: praktična referenca: TimeProvider apstrahira trenutačno vrijeme i timere te omogućuje determinističke testove.
Verzija: .NET API; verified against .NET 10 reference surface
Sintaksa
System.TimeProvider /* select a documented member or constructor */TimeProvider apstrahira trenutačno vrijeme i timere te omogućuje determinističke testove.
U testirljivi kod ga ubrizgajte umjesto izravne uporabe DateTimeOffset.UtcNow i Timer.
Sistemski provider i dalje ovisi o satu hosta; monotoni timestamp razlikuje se od UTC.
GetElapsedTime zahtijeva timestampove istog providera; timere treba osloboditi.
Cijeli program doista koristi System.TimeProvider; točno očekivani stdout jest True.
Primjeri
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
TimeProvider provider = TimeProvider.System;
Console.WriteLine(provider.GetUtcNow().Offset == TimeSpan.Zero);
Rezultat
True
Cijeli program doista koristi `System.TimeProvider`; točno očekivani stdout jest `True`.