Skip to content

Commit

Permalink
Fix new warnings found with CA1854 improvement. (#85613)
Browse files Browse the repository at this point in the history
* Fix new warnings found with CA1854 improvement
  • Loading branch information
buyaa-n authored May 2, 2023
1 parent a66af19 commit 3e8f17a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ private void GenCases(LoggerMethod lm, string nestedIndentation)
{
// this is related to https://github.com/serilog/serilog-extensions-logging/issues/197
string name = p.CodeName;
if (lm.TemplateMap.ContainsKey(name))
if (lm.TemplateMap.TryGetValue(name, out string value))
{
// take the letter casing from the template
name = lm.TemplateMap[name];
name = value;
}

_builder.AppendLine($" {nestedIndentation}{index++} => new global::System.Collections.Generic.KeyValuePair<string, object?>(\"{name}\", this.{NormalizeSpecialSymbol(p.CodeName)}),");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ private static HttpEndPointListener GetEPListener(string host, int port, HttpLis
}

Dictionary<int, HttpEndPointListener>? p;
if (s_ipEndPoints.ContainsKey(addr))
if (s_ipEndPoints.TryGetValue(addr, out Dictionary<int, HttpEndPointListener>? value))
{
p = s_ipEndPoints[addr];
p = value;
}
else
{
Expand All @@ -146,9 +146,9 @@ private static HttpEndPointListener GetEPListener(string host, int port, HttpLis
}

HttpEndPointListener? epl;
if (p.ContainsKey(port))
if (p.TryGetValue(port, out HttpEndPointListener? epListener))
{
epl = p[port];
epl = epListener;
}
else
{
Expand Down
10 changes: 5 additions & 5 deletions src/tools/illink/src/linker/Linker.Dataflow/MethodBodyScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ private static void NewKnownStack (Dictionary<int, Stack<StackSlot>> knownStacks
return;
}

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

if (knownStacks.ContainsKey (operation.Offset)) {
if (knownStacks.TryGetValue (operation.Offset, out Stack<StackSlot>? knownValue)) {
if (currentStack == null) {
// The stack copy constructor reverses the stack
currentStack = new Stack<StackSlot> (knownStacks[operation.Offset].Reverse ());
currentStack = new Stack<StackSlot> (knownValue.Reverse ());
} else {
currentStack = MergeStack (currentStack, knownStacks[operation.Offset]);
currentStack = MergeStack (currentStack, knownValue);
}
}

Expand Down

0 comments on commit 3e8f17a

Please sign in to comment.