Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some CA1854 NetAnalyzers suggestions #71

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private int ScopeToLanguage(string scope)
}

string scopeName = m.Groups[1].Value;
return _embeddedLanguages.ContainsKey(scopeName) ? _embeddedLanguages[scopeName] : 0;
return _embeddedLanguages.TryGetValue(scopeName, out int value) ? value : 0;
}

private static int ToStandardTokenType(string tokenType)
Expand Down
4 changes: 2 additions & 2 deletions src/TextMateSharp/Internal/Grammars/Grammar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ public IRawGrammar GetExternalGrammar(string scopeName)

public IRawGrammar GetExternalGrammar(string scopeName, IRawRepository repository)
{
if (this._includedGrammars.ContainsKey(scopeName))
if (_includedGrammars.TryGetValue(scopeName, out IRawGrammar value))
{
return this._includedGrammars[scopeName];
return value;
}
else if (this._grammarRepository != null)
{
Expand Down
11 changes: 6 additions & 5 deletions src/TextMateSharp/Internal/Grammars/SyncRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,26 @@ public IGrammar GrammarForScopeName(
Dictionary<string, int> tokenTypes,
BalancedBracketSelectors balancedBracketSelectors)
{
if (!this._grammars.ContainsKey(scopeName))
if (!_grammars.TryGetValue(scopeName, out IGrammar value))
{
IRawGrammar rawGrammar = Lookup(scopeName);
if (rawGrammar == null)
{
return null;
}
this._grammars.Add(scopeName,
new Grammar(

value = new Grammar(
scopeName,
rawGrammar,
initialLanguage,
embeddedLanguages,
tokenTypes,
balancedBracketSelectors,
this,
this));
this);
this._grammars.Add(scopeName, value);
}
return this._grammars[scopeName];
return value;
}

private static void CollectIncludedScopes(ICollection<string> result, IRawGrammar grammar)
Expand Down
7 changes: 4 additions & 3 deletions src/TextMateSharp/Themes/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,12 @@ internal List<ThemeTrieElementRule> Match(string scopeName)
{
lock (this._cachedMatchRoot)
{
if (!this._cachedMatchRoot.ContainsKey(scopeName))
if (!_cachedMatchRoot.TryGetValue(scopeName, out List<ThemeTrieElementRule> value))
{
this._cachedMatchRoot[scopeName] = this._root.Match(scopeName);
value = this._root.Match(scopeName);
this._cachedMatchRoot[scopeName] = value;
}
return this._cachedMatchRoot[scopeName];
return value;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/TextMateSharp/Themes/ThemeTrieElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ public List<ThemeTrieElementRule> Match(string scope)
tail = scope.Substring(dotIndex + 1);
}

if (this.children.ContainsKey(head))
if (children.TryGetValue(head, out ThemeTrieElement value))
{
return this.children[head].Match(tail);
return value.Match(tail);
}

arr = new List<ThemeTrieElementRule>();
Expand Down Expand Up @@ -130,9 +130,9 @@ public void Insert(string name, int scopeDepth, string scope, List<string> paren
}

ThemeTrieElement child;
if (this.children.ContainsKey(head))
if (children.TryGetValue(head, out ThemeTrieElement value))
{
child = this.children[head];
child = value;
}
else
{
Expand Down