Skip to content

Commit 21a3c3b

Browse files
committed
Fix
1 parent 68f401d commit 21a3c3b

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/Components/Components/src/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Microsoft.AspNetCore.Components.ITempData.Keep() -> void
55
Microsoft.AspNetCore.Components.ITempData.Keep(string! key) -> void
66
Microsoft.AspNetCore.Components.ITempData.Peek(string! key) -> object?
77
Microsoft.AspNetCore.Components.TempData
8+
Microsoft.AspNetCore.Components.TempData.ContainsValue(object? value) -> bool
89
Microsoft.AspNetCore.Components.TempData.TempData() -> void
910
Microsoft.AspNetCore.Components.TempData.Get(string! key) -> object?
1011
Microsoft.AspNetCore.Components.TempData.this[string! key].get -> object?

src/Components/Components/src/TempData.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ public bool Remove(string key)
6464
return _data.Remove(key);
6565
}
6666

67+
/// <summary>
68+
/// Returns true if the TempData dictionary contains the specified <paramref name="value"/>.
69+
/// </summary>
70+
public bool ContainsValue(object? value)
71+
{
72+
return _data.ContainsValue(value);
73+
}
74+
6775
/// <summary>
6876
/// Gets the data that should be saved for the next request.
6977
/// </summary>
@@ -153,14 +161,24 @@ IEnumerator IEnumerable.GetEnumerator()
153161

154162
class TempDataEnumerator : IEnumerator<KeyValuePair<string, object?>>
155163
{
164+
private readonly TempData _tempData;
156165
private readonly IEnumerator<KeyValuePair<string, object?>> _innerEnumerator;
157166

158167
public TempDataEnumerator(TempData tempData)
159168
{
169+
_tempData = tempData;
160170
_innerEnumerator = tempData._data.GetEnumerator();
161171
}
162172

163-
public KeyValuePair<string, object?> Current => _innerEnumerator.Current;
173+
public KeyValuePair<string, object?> Current
174+
{
175+
get
176+
{
177+
var kvp = _innerEnumerator.Current;
178+
_tempData.Remove(kvp.Key);
179+
return kvp;
180+
}
181+
}
164182

165183
object IEnumerator.Current => _innerEnumerator.Current;
166184

src/Components/Components/test/TempDataTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void Save_ReturnsOnlyRetainedKeys()
158158
public void Load_PopulatesDataFromDictionary()
159159
{
160160
var tempData = new TempData();
161-
var dataToLoad = new Dictionary<string, object?>
161+
var dataToLoad = new Dictionary<string, object>
162162
{
163163
["Key1"] = "Value1",
164164
["Key2"] = "Value2"
@@ -175,7 +175,7 @@ public void Load_ClearsExistingDataBeforeLoading()
175175
{
176176
var tempData = new TempData();
177177
tempData["ExistingKey"] = "ExistingValue";
178-
var dataToLoad = new Dictionary<string, object?>
178+
var dataToLoad = new Dictionary<string, object>
179179
{
180180
["NewKey"] = "NewValue"
181181
};

0 commit comments

Comments
 (0)