-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/System.Windows.Forms/tests/TestUtilities/NotifyUIAProviderTheRichTextContent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Windows.Forms.Primitives; | ||
|
||
namespace System; | ||
|
||
/// <summary> | ||
/// Scope for enabling / disabling the NotifyUIAProviderTheText Switch. | ||
/// </summary> | ||
public readonly ref struct NotifyUIAProviderTheRichTextContent | ||
{ | ||
private readonly AppContextSwitchScope _switchScope; | ||
|
||
public NotifyUIAProviderTheRichTextContent(bool enable) | ||
{ | ||
// Prevent multiple NotifyUIAProviderTheRichTextContent from running simultaneously. Using Monitor to allow recursion on | ||
// the same thread. | ||
Monitor.Enter(typeof(NotifyUIAProviderTheRichTextContent)); | ||
_switchScope = new(WinFormsAppContextSwitchNames.NotifyUIAProviderTheText, GetDefaultValue, enable); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
try | ||
{ | ||
_switchScope.Dispose(); | ||
} | ||
finally | ||
{ | ||
Monitor.Exit(typeof(NotifyUIAProviderTheRichTextContent)); | ||
} | ||
} | ||
|
||
public static bool GetDefaultValue() => | ||
typeof(LocalAppContextSwitches).TestAccessor() | ||
.CreateDelegate<Func<string, bool>>("GetSwitchDefaultValue")(WinFormsAppContextSwitchNames.NotifyUIAProviderTheText); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters