diff --git a/src/libraries/Common/tests/System/Diagnostics/DebuggerAttributes.cs b/src/libraries/Common/tests/System/Diagnostics/DebuggerAttributes.cs index 07b212f8a24ec..54ff93f35d0b6 100644 --- a/src/libraries/Common/tests/System/Diagnostics/DebuggerAttributes.cs +++ b/src/libraries/Common/tests/System/Diagnostics/DebuggerAttributes.cs @@ -1,6 +1,3 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -277,5 +274,20 @@ private static PropertyInfo GetProperty(object obj, string propertyName) } return null; } + + internal static void ValidateDebuggerDisplayAttribute_CancellationTokenSource() + { + var cts = new CancellationTokenSource(); + string display = ValidateDebuggerDisplayReferences(cts); + Debug.Assert(display == "IsCancellationRequested = False, IsDisposed = False"); + + cts.Cancel(); + display = ValidateDebuggerDisplayReferences(cts); + Debug.Assert(display == "IsCancellationRequested = True, IsDisposed = False"); + + cts.Dispose(); + display = ValidateDebuggerDisplayReferences(cts); + Debug.Assert(display == "IsCancellationRequested = True, IsDisposed = True"); + } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs index 26c2eb7078598..6236a65da5f03 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs @@ -1,6 +1,3 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; @@ -22,6 +19,7 @@ namespace System.Threading /// concurrently from multiple threads. /// /// + [DebuggerDisplay("IsCancellationRequested = {IsCancellationRequested}, Disposed = {_disposed}")] public class CancellationTokenSource : IDisposable { /// A that's already canceled.