Skip to content

Commit

Permalink
When AppContext switch caching is disabled, default switch value was …
Browse files Browse the repository at this point in the history
…not stored, we were lucky with switches that have "false" as a default
  • Loading branch information
Tanya-Solyanik committed Nov 14, 2024
1 parent 91a2ac3 commit cb302c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ private static bool GetSwitchValue(string switchName, ref int cachedSwitchValue)
{
cachedSwitchValue = isSwitchEnabled ? 1 /*true*/ : -1 /*false*/;
}
else if (!hasSwitch)
{
AppContext.SetSwitch(switchName, isSwitchEnabled);
}

return isSwitchEnabled;

Expand Down Expand Up @@ -256,7 +260,6 @@ public static bool ClipboardDragDropEnableUnsafeBinaryFormatterSerialization
public static bool ClipboardDragDropEnableNrbfSerialization
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get =>
GetCachedSwitchValue(ClipboardDragDropEnableNrbfSerializationSwitchName, ref s_clipboardDragDropEnableNrbfSerialization);
get => GetCachedSwitchValue(ClipboardDragDropEnableNrbfSerializationSwitchName, ref s_clipboardDragDropEnableNrbfSerialization);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ public void Clipboard_BinaryFormatter_AppContextSwitch()
{
LocalAppContextSwitches.ClipboardDragDropEnableUnsafeBinaryFormatterSerialization.Should().BeFalse();
}

LocalAppContextSwitches.ClipboardDragDropEnableUnsafeBinaryFormatterSerialization.Should().BeFalse();
}

[WinFormsFact]
Expand All @@ -678,6 +680,8 @@ public void Clipboard_NrbfSerializer_AppContextSwitch()
{
LocalAppContextSwitches.ClipboardDragDropEnableNrbfSerialization.Should().BeTrue();
}

LocalAppContextSwitches.ClipboardDragDropEnableNrbfSerialization.Should().BeTrue();
}

[WinFormsFact]
Expand Down

0 comments on commit cb302c4

Please sign in to comment.