Skip to content

Commit 3e8f17a

Browse files
authored
Fix new warnings found with CA1854 improvement. (#85613)
* Fix new warnings found with CA1854 improvement
1 parent a66af19 commit 3e8f17a

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/LoggerMessageGenerator.Emitter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ private void GenCases(LoggerMethod lm, string nestedIndentation)
254254
{
255255
// this is related to https://github.com/serilog/serilog-extensions-logging/issues/197
256256
string name = p.CodeName;
257-
if (lm.TemplateMap.ContainsKey(name))
257+
if (lm.TemplateMap.TryGetValue(name, out string value))
258258
{
259259
// take the letter casing from the template
260-
name = lm.TemplateMap[name];
260+
name = value;
261261
}
262262

263263
_builder.AppendLine($" {nestedIndentation}{index++} => new global::System.Collections.Generic.KeyValuePair<string, object?>(\"{name}\", this.{NormalizeSpecialSymbol(p.CodeName)}),");

src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpEndPointManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ private static HttpEndPointListener GetEPListener(string host, int port, HttpLis
135135
}
136136

137137
Dictionary<int, HttpEndPointListener>? p;
138-
if (s_ipEndPoints.ContainsKey(addr))
138+
if (s_ipEndPoints.TryGetValue(addr, out Dictionary<int, HttpEndPointListener>? value))
139139
{
140-
p = s_ipEndPoints[addr];
140+
p = value;
141141
}
142142
else
143143
{
@@ -146,9 +146,9 @@ private static HttpEndPointListener GetEPListener(string host, int port, HttpLis
146146
}
147147

148148
HttpEndPointListener? epl;
149-
if (p.ContainsKey(port))
149+
if (p.TryGetValue(port, out HttpEndPointListener? epListener))
150150
{
151-
epl = p[port];
151+
epl = epListener;
152152
}
153153
else
154154
{

src/tools/illink/src/linker/Linker.Dataflow/MethodBodyScanner.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ private static void NewKnownStack (Dictionary<int, Stack<StackSlot>> knownStacks
138138
return;
139139
}
140140

141-
if (knownStacks.ContainsKey (newOffset)) {
142-
knownStacks[newOffset] = MergeStack (knownStacks[newOffset], newStack);
141+
if (knownStacks.TryGetValue (newOffset, out Stack<StackSlot>? value)) {
142+
knownStacks[newOffset] = MergeStack (value, newStack);
143143
} else {
144144
knownStacks.Add (newOffset, new Stack<StackSlot> (newStack.Reverse ()));
145145
}
@@ -292,12 +292,12 @@ protected virtual void Scan (MethodIL methodIL, ref InterproceduralState interpr
292292
foreach (Instruction operation in methodIL.Instructions) {
293293
int curBasicBlock = blockIterator.MoveNext (operation);
294294

295-
if (knownStacks.ContainsKey (operation.Offset)) {
295+
if (knownStacks.TryGetValue (operation.Offset, out Stack<StackSlot>? knownValue)) {
296296
if (currentStack == null) {
297297
// The stack copy constructor reverses the stack
298-
currentStack = new Stack<StackSlot> (knownStacks[operation.Offset].Reverse ());
298+
currentStack = new Stack<StackSlot> (knownValue.Reverse ());
299299
} else {
300-
currentStack = MergeStack (currentStack, knownStacks[operation.Offset]);
300+
currentStack = MergeStack (currentStack, knownValue);
301301
}
302302
}
303303

0 commit comments

Comments
 (0)