File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed
src/Components/Components Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ Microsoft.AspNetCore.Components.ITempData.Keep() -> void
55Microsoft.AspNetCore.Components.ITempData.Keep(string! key) -> void
66Microsoft.AspNetCore.Components.ITempData.Peek(string! key) -> object?
77Microsoft.AspNetCore.Components.TempData
8+ Microsoft.AspNetCore.Components.TempData.ContainsValue(object? value) -> bool
89Microsoft.AspNetCore.Components.TempData.TempData() -> void
910Microsoft.AspNetCore.Components.TempData.Get(string! key) -> object?
1011Microsoft.AspNetCore.Components.TempData.this[string! key].get -> object?
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 } ;
You can’t perform that action at this time.
0 commit comments