Skip to content

Commit

Permalink
Add security Set (#8491)
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Molinero authored Jan 2, 2025
1 parent f75ea38 commit 75d8e71
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Common/Securities/Security.cs
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,17 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o
/// <param name="key">The property key</param>
/// <param name="value">The property value</param>
public void Add(string key, object value)
{
Set(key, value);
}

/// <summary>
/// Sets the specified custom property.
/// This allows us to use the security object as a dynamic object for quick storage.
/// </summary>
/// <param name="key">The property key</param>
/// <param name="value">The property value</param>
public void Set(string key, object value)
{
Cache.Properties[key] = value;
}
Expand Down
9 changes: 9 additions & 0 deletions Tests/Common/Securities/SecurityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,15 @@ public void SetsAndGetsDynamicCustomPropertiesUsingDynamicInterface()
Assert.Throws<RuntimeBinderException>(() => { var notAProperty = dynamicSecurity.NotAProperty; });
}

[Test]
public void SetCustomProperty()
{
var security = GetSecurity();
security.Set("Bool", true);
Assert.AreEqual(true, security.TryGet<bool>("Bool", out var boolValue));
Assert.AreEqual(true, boolValue);
}

[Test]
public void SetsAndGetsDynamicCustomPropertiesUsingGenericInterface()
{
Expand Down

0 comments on commit 75d8e71

Please sign in to comment.