未验证 提交 6a9bfee0 编写于 作者: R Robin Lindner 提交者: GitHub

Expose AppContext.SetData in ref assembly (#62996)

* Expose AppContext.SetData in ref assembly

* Implement test for Set/GetData

* Add doc comment
上级 1c09d36e
......@@ -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)
......
......@@ -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; }
}
......@@ -144,8 +144,9 @@
<Compile Include="System\ValueTypeTests.cs" />
<Compile Include="System\VersionTests.cs" />
<Compile Include="System\WeakReferenceTests.cs" />
<Compile Include="System\AppContext\AppContext.Switch.cs" />
<Compile Include="System\AppContext\AppContext.Switch.Validation.cs" />
<Compile Include="System\AppContext\AppContextTests.cs" />
<Compile Include="System\AppContext\AppContextTests.Switch.cs" />
<Compile Include="System\AppContext\AppContextTests.Switch.Validation.cs" />
<Compile Include="System\Collections\Generic\KeyNotFoundExceptionTests.cs" />
<Compile Include="System\Collections\Generic\KeyValuePairTests.cs" />
<Compile Include="System\Collections\ObjectModel\CollectionTests.cs" />
......
// 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()
{
AssertExtensions.Throws<ArgumentNullException>("name", () => AppContext.SetData(null, 123));
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册