File tree 3 files changed +6
-14
lines changed
Features/JsonPatch/src/Internal
Http/Authentication.Core/src 3 files changed +6
-14
lines changed Original file line number Diff line number Diff line change @@ -147,7 +147,7 @@ public virtual bool TryTest(
147
147
}
148
148
149
149
// As per JsonPatch spec, the target location must exist for test to be successful
150
- if ( ! dictionary . ContainsKey ( convertedKey ) )
150
+ if ( ! dictionary . TryGetValue ( convertedKey , out var currentValue ) )
151
151
{
152
152
errorMessage = Resources . FormatTargetLocationAtPathSegmentNotFound ( segment ) ;
153
153
return false ;
@@ -158,8 +158,6 @@ public virtual bool TryTest(
158
158
return false ;
159
159
}
160
160
161
- var currentValue = dictionary [ convertedKey ] ;
162
-
163
161
// The target segment does not have an assigned value to compare the test value with
164
162
if ( currentValue == null )
165
163
{
Original file line number Diff line number Diff line change @@ -184,15 +184,14 @@ public virtual void AddScheme(AuthenticationScheme scheme)
184
184
/// <param name="name">The name of the authenticationScheme being removed.</param>
185
185
public virtual void RemoveScheme ( string name )
186
186
{
187
- if ( ! _schemes . ContainsKey ( name ) )
187
+ if ( ! _schemes . TryGetValue ( name , out var scheme ) )
188
188
{
189
189
return ;
190
190
}
191
191
lock ( _lock )
192
192
{
193
- if ( _schemes . ContainsKey ( name ) )
193
+ if ( _schemes . TryGetValue ( name , out scheme ) )
194
194
{
195
- var scheme = _schemes [ name ] ;
196
195
if ( _requestHandlers . Remove ( scheme ) )
197
196
{
198
197
_requestHandlersCopy = _requestHandlers . ToArray ( ) ;
Original file line number Diff line number Diff line change @@ -652,26 +652,21 @@ public virtual async Task<IEnumerable<AuthenticationScheme>> GetExternalAuthenti
652
652
{
653
653
var auth = await Context . AuthenticateAsync ( IdentityConstants . ExternalScheme ) ;
654
654
var items = auth ? . Properties ? . Items ;
655
- if ( auth ? . Principal == null || items == null || ! items . ContainsKey ( LoginProviderKey ) )
655
+ if ( auth ? . Principal == null || items == null || ! items . TryGetValue ( LoginProviderKey , out var provider ) )
656
656
{
657
657
return null ;
658
658
}
659
659
660
660
if ( expectedXsrf != null )
661
661
{
662
- if ( ! items . ContainsKey ( XsrfKey ) )
663
- {
664
- return null ;
665
- }
666
- var userId = items [ XsrfKey ] as string ;
667
- if ( userId != expectedXsrf )
662
+ if ( ! items . TryGetValue ( XsrfKey , out var userId ) ||
663
+ userId != expectedXsrf )
668
664
{
669
665
return null ;
670
666
}
671
667
}
672
668
673
669
var providerKey = auth . Principal . FindFirstValue ( ClaimTypes . NameIdentifier ) ;
674
- var provider = items [ LoginProviderKey ] as string ;
675
670
if ( providerKey == null || provider == null )
676
671
{
677
672
return null ;
You can’t perform that action at this time.
0 commit comments