string simpleName = Path.GetFileNameWithoutExtension(fileName);
- if (dictionary.ContainsKey(simpleName))
+ if (dictionary.TryGetValue(simpleName, out string otherFullFileName))
{
if (strict)
{
throw new CommandLineException("Multiple input files matching same simple name " +
- fullFileName + " " + dictionary[simpleName]);
+ fullFileName + " " + otherFullFileName);
}
}
else
return;
}
- if (knownStacks.ContainsKey(newOffset))
+ if (knownStacks.TryGetValue(newOffset, out var knownStack))
{
- knownStacks[newOffset] = MergeStack(knownStacks[newOffset], newStack);
+ knownStacks[newOffset] = MergeStack(knownStack, newStack);
}
else
{
ValidateNoReferenceToReference(locals, methodBody, reader.Offset);
int curBasicBlock = blockIterator.MoveNext(reader.Offset);
- if (knownStacks.ContainsKey(reader.Offset))
+ if (knownStacks.TryGetValue(reader.Offset, out var knownStack))
{
if (currentStack == null)
{
// The stack copy constructor reverses the stack
- currentStack = new Stack<StackSlot>(knownStacks[reader.Offset].Reverse());
+ currentStack = new Stack<StackSlot>(knownStack.Reverse());
}
else
{
- currentStack = MergeStack(currentStack, knownStacks[reader.Offset]);
+ currentStack = MergeStack(currentStack, knownStack);
}
}
_offsetToDefName.Clear();
foreach (ISymbolDefinitionNode n in definedSymbols)
{
- if (!_offsetToDefName.ContainsKey(n.Offset))
+ if (!_offsetToDefName.TryGetValue(n.Offset, out var nodes))
{
- _offsetToDefName[n.Offset] = new List<ISymbolDefinitionNode>();
+ nodes = new List<ISymbolDefinitionNode>();
+ _offsetToDefName[n.Offset] = nodes;
}
- _offsetToDefName[n.Offset].Add(n);
+ nodes.Add(n);
_byteInterruptionOffsets[n.Offset] = true;
}
var methods = new Dictionary<string, int>(lc.Methods.Count);
foreach (LoggerMethod lm in lc.Methods)
{
- if (methods.ContainsKey(lm.Name))
+ if (methods.TryGetValue(lm.Name, out int currentCount))
{
- int currentCount = methods[lm.Name];
lm.UniqueName = $"{lm.Name}{currentCount}";
methods[lm.Name] = currentCount + 1;
}
// to build a list of ldap attributes for each object type.
if (null != ldapAttribute)
{
- if (propertyNameToLdapAttr.ContainsKey(propertyName))
+ if (propertyNameToLdapAttr.TryGetValue(propertyName, out string[] ldapAttributes))
{
- string[] props = new string[propertyNameToLdapAttr[propertyName].Length + 1];
- propertyNameToLdapAttr[propertyName].CopyTo(props, 0);
- props[propertyNameToLdapAttr[propertyName].Length] = ldapAttribute;
+ string[] props = new string[ldapAttributes.Length + 1];
+ ldapAttributes.CopyTo(props, 0);
+ props[ldapAttributes.Length] = ldapAttribute;
propertyNameToLdapAttr[propertyName] = props;
}
else
{
_package.ThrowIfWriteOnly();
- if (!_propertyDictionary.ContainsKey(propertyName))
+ if (!_propertyDictionary.TryGetValue(propertyName, out object? value))
return null;
- return _propertyDictionary[propertyName];
+ return value;
}
// Shim function to adequately cast the result of GetPropertyValue.
{
XPathNodeRef nodeRef;
- if (_idValueMap == null || !_idValueMap.ContainsKey(id))
+ if (_idValueMap == null || !_idValueMap.TryGetValue(id, out nodeRef))
{
pageElem = null;
return 0;
}
// Extract page and index from XPathNodeRef
- nodeRef = _idValueMap[id];
pageElem = nodeRef.Page;
return nodeRef.Index;
}
/// </summary>
public int Add(T value)
{
- int id;
-
- if (!_lookup.ContainsKey(value))
+ if (!_lookup.TryGetValue(value, out int id))
{
// The value does not yet exist, so add it to the list
id = _list.Count;
_lookup.Add(value, id);
_list.Add(value);
}
- else
- {
- id = _lookup[value];
- }
return id;
}
{
privilegeLock.EnterReadLock();
- if (luids.ContainsKey(privilege))
+ if (luids.TryGetValue(privilege, out luid))
{
- luid = luids[privilege];
-
privilegeLock.ExitReadLock();
}
else
if (privilegeLock.IsWriteLockHeld)
{
- if (!luids.ContainsKey(privilege))
+ if (luids.TryAdd(privilege, luid))
{
- luids[privilege] = luid;
privileges[luid] = privilege;
}
// Go deeper if the number of children is greater the element to compare against.
if (current != null)
{
- if (!dict.ContainsKey(current.Count))
+ if (!dict.TryGetValue(current.Count, out Collection<BuilderElements> builderElements))
{
- dict.Add(current.Count, new Collection<BuilderElements>());
+ builderElements = new Collection<BuilderElements>();
+ dict.Add(current.Count, builderElements);
}
- dict[current.Count].Add(current);
+
+ builderElements.Add(current);
current.GetDictionaryElements(dict);
}
if (srcToState != null)
{
// - If not found, clone a new DestToState, add SrcToState.DestToState to SrcToDestHash, and add SrcToState to CloneStack.
- if (!SrcToDestHash.ContainsKey(srcToState))
+ if (!SrcToDestHash.TryGetValue(srcToState, out destToState))
{
destToState = CreateNewState(srcToState.Rule);
SrcToDestHash.Add(srcToState, destToState);
CloneStack.Push(srcToState);
}
- else
- {
- destToState = SrcToDestHash[srcToState];
- }
}
// - Clone the transition from SrcFromState.SrcToState at DestFromState.DestToState
if (icall == null)
{
string? methodSig = BuildSignature(method, className);
- if (methodSig != null && icallClass.Icalls.ContainsKey(methodSig))
- icall = icallClass.Icalls[methodSig];
+ if (methodSig != null)
+ icallClass.Icalls.TryGetValue(methodSig, out icall);
+
+ if (icall == null)
+ // Registered at runtime
+ continue;
}
- if (icall == null)
- // Registered at runtime
- continue;
icall.Method = method;
icall.TokenIndex = (int)method.MetadataToken & 0xffffff;