Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/AppContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public static partial class AppContext
return data;
}

/// <summary>
/// Sets the value of the named data element assigned to the current application domain.
/// </summary>
/// <param name="name">The name of the data element</param>
/// <param name="data">The value of <paramref name="name"/></param>
/// <exception cref="ArgumentNullException">If <paramref name="name"/> is <see langword="null"/></exception>
public static void SetData(string name, object? data)
{
if (name == null)
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public static partial class AppContext
public static string BaseDirectory { get { throw null; } }
public static string? TargetFrameworkName { get { throw null; } }
public static object? GetData(string name) { throw null; }
public static void SetData(string name, object? data) { }
public static void SetSwitch(string switchName, bool isEnabled) { }
public static bool TryGetSwitch(string switchName, out bool isEnabled) { throw null; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<Compile Include="System\ActivatorTests.cs" />
<Compile Include="System\ActivatorTests.Generic.cs" />
<Compile Include="System\AmbiguousImplementationExceptionTests.cs" />
<Compile Include="System\AppContext\AppContext.cs" />
<Compile Include="System\ArgumentExceptionTests.cs" />
<Compile Include="System\ArgumentNullExceptionTests.cs" />
<Compile Include="System\ArgumentOutOfRangeExceptionTests.cs" />
Expand Down
33 changes: 33 additions & 0 deletions src/libraries/System.Runtime/tests/System/AppContext/AppContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Xunit;

namespace System.Tests
{
public partial class AppContextTests
{
[Theory]
[InlineData("AppContext_Case1", 123)]
[InlineData("AppContext_Case2", "")]
[InlineData("AppContext_Case3", null)]
public void AppContext_GetSetDataTest(string dataKey, object value)
{
// Set data
AppContext.SetData(dataKey, value);

// Get previously set data
object actual = AppContext.GetData(dataKey);

// Validate instance equality
Assert.Same(value, actual);
}

[Fact]
public void AppContext_ThrowTest()
{
ArgumentNullException exception = Assert.Throws<ArgumentNullException>(() => AppContext.SetData(null, 123));
Assert.Contains("name", exception.Message);
}
}
}