diff --git a/src/Constructorio_NET.Tests/client/modules/SearchTests.cs b/src/Constructorio_NET.Tests/client/modules/SearchTests.cs index 4ed178d..146d625 100644 --- a/src/Constructorio_NET.Tests/client/modules/SearchTests.cs +++ b/src/Constructorio_NET.Tests/client/modules/SearchTests.cs @@ -567,6 +567,20 @@ public async Task GetSearchResultsWithRedirect() Assert.IsNotNull(res.ResultId, "ResultId should exist"); } + [Test] + public void RedirectDataIndexerAccessesArbitraryKeys() + { + string json = @"{""url"":""/test"",""rule_id"":49023,""match_id"":185282,""foo"":""bar"",""custom_key"":123}"; + RedirectData data = Newtonsoft.Json.JsonConvert.DeserializeObject(json); + + Assert.AreEqual("/test", data.Url, "Url property should be accessible"); + Assert.AreEqual(49023, data.RuleId, "RuleId property should be accessible"); + Assert.AreEqual(185282, data.MatchId, "MatchId property should be accessible"); + Assert.AreEqual("bar", data["foo"]?.ToString(), "Indexer should access arbitrary string key"); + Assert.AreEqual(123L, data["custom_key"], "Indexer should access arbitrary numeric key"); + Assert.IsNull(data["nonexistent"], "Indexer should return null for missing keys"); + } + [Test] public async Task GetSearchResultsShouldReturnResultWithRefinedContent() { diff --git a/src/constructor.io/models/Search/RedirectData.cs b/src/constructor.io/models/Search/RedirectData.cs index 000fa4f..4bb121b 100644 --- a/src/constructor.io/models/Search/RedirectData.cs +++ b/src/constructor.io/models/Search/RedirectData.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Newtonsoft.Json; /** @@ -16,5 +17,21 @@ public class RedirectData [JsonProperty("match_id")] public int MatchId { get; set; } + + [JsonExtensionData] + private Dictionary _additionalData; + + /// + /// Indexer for accessing arbitrary metadata keys + /// + public object this[string key] + { + get => _additionalData?.TryGetValue(key, out var value) == true ? value : null; + set + { + _additionalData ??= new Dictionary(); + _additionalData[key] = value; + } + } } } \ No newline at end of file