From debbca7574197305a34646a08a1d9dc20e69a17e Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Mon, 5 Jun 2023 19:40:06 +0000 Subject: [PATCH] Mark StartTime as experimental --- .../ExperimentalAttribute.cs | 53 +++++++++++++++++++ .../FakeTimeProvider.cs | 2 + 2 files changed, 55 insertions(+) create mode 100644 src/Libraries/Microsoft.Extensions.TimeProvider.Testing/ExperimentalAttribute.cs diff --git a/src/Libraries/Microsoft.Extensions.TimeProvider.Testing/ExperimentalAttribute.cs b/src/Libraries/Microsoft.Extensions.TimeProvider.Testing/ExperimentalAttribute.cs new file mode 100644 index 00000000000..6d7d44a95f8 --- /dev/null +++ b/src/Libraries/Microsoft.Extensions.TimeProvider.Testing/ExperimentalAttribute.cs @@ -0,0 +1,53 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Diagnostics.CodeAnalysis; + +/// +/// Indicates that an API element is experimental and subject to change without notice. +/// +[ExcludeFromCodeCoverage] +[AttributeUsage( + AttributeTargets.Class | + AttributeTargets.Struct | + AttributeTargets.Enum | + AttributeTargets.Interface | + AttributeTargets.Delegate | + AttributeTargets.Method | + AttributeTargets.Constructor | + AttributeTargets.Property | + AttributeTargets.Field | + AttributeTargets.Event | + AttributeTargets.Assembly)] +internal sealed class ExperimentalAttribute : Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public ExperimentalAttribute() + { + // Intentionally left empty. + } + + /// + /// Initializes a new instance of the class. + /// + /// Human readable explanation for marking experimental API. + public ExperimentalAttribute(string message) + { +#pragma warning disable R9A014 // Use the 'Microsoft.Extensions.Diagnostics.Throws' class instead of explicitly throwing exception for improved performance +#pragma warning disable R9A039 // Remove superfluous null check when compiling in a nullable context +#pragma warning disable R9A060 // Consider removing unnecessary null coalescing (??) since the left-hand value is statically known not to be null +#pragma warning disable SA1101 // Prefix local calls with this + Message = message ?? throw new ArgumentNullException(nameof(message)); +#pragma warning restore SA1101 // Prefix local calls with this +#pragma warning restore R9A060 // Consider removing unnecessary null coalescing (??) since the left-hand value is statically known not to be null +#pragma warning restore R9A039 // Remove superfluous null check when compiling in a nullable context +#pragma warning restore R9A014 // Use the 'Microsoft.Extensions.Diagnostics.Throws' class instead of explicitly throwing exception for improved performance + } + + /// + /// Gets a human readable explanation for marking API as experimental. + /// + public string? Message { get; } +} diff --git a/src/Libraries/Microsoft.Extensions.TimeProvider.Testing/FakeTimeProvider.cs b/src/Libraries/Microsoft.Extensions.TimeProvider.Testing/FakeTimeProvider.cs index b7cb12d0e67..43c38e4b1ee 100644 --- a/src/Libraries/Microsoft.Extensions.TimeProvider.Testing/FakeTimeProvider.cs +++ b/src/Libraries/Microsoft.Extensions.TimeProvider.Testing/FakeTimeProvider.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Threading; using Microsoft.Shared.Diagnostics; @@ -23,6 +24,7 @@ public class FakeTimeProvider : TimeProvider /// /// Gets the time at which the instance of the was initialized. /// + [Experimental] public DateTimeOffset StartTime { get; } = new DateTimeOffset(2000, 1, 1, 0, 0, 0, 0, TimeSpan.Zero); ///