Skip to content

Commit 4361eac

Browse files
committed
Fix some CA1854 NetAnalyzers suggestions
1 parent 7ab4cbb commit 4361eac

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

src/TextMateSharp/Internal/Grammars/BasicScopeAttributesProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private int ScopeToLanguage(string scope)
123123
}
124124

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

129129
private static int ToStandardTokenType(string tokenType)

src/TextMateSharp/Internal/Grammars/Grammar.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ public IRawGrammar GetExternalGrammar(string scopeName)
156156

157157
public IRawGrammar GetExternalGrammar(string scopeName, IRawRepository repository)
158158
{
159-
if (this._includedGrammars.ContainsKey(scopeName))
159+
if (_includedGrammars.TryGetValue(scopeName, out IRawGrammar value))
160160
{
161-
return this._includedGrammars[scopeName];
161+
return value;
162162
}
163163
else if (this._grammarRepository != null)
164164
{

src/TextMateSharp/Internal/Grammars/SyncRegistry.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,26 @@ public IGrammar GrammarForScopeName(
9191
Dictionary<string, int> tokenTypes,
9292
BalancedBracketSelectors balancedBracketSelectors)
9393
{
94-
if (!this._grammars.ContainsKey(scopeName))
94+
if (!_grammars.TryGetValue(scopeName, out IGrammar value))
9595
{
9696
IRawGrammar rawGrammar = Lookup(scopeName);
9797
if (rawGrammar == null)
9898
{
9999
return null;
100100
}
101-
this._grammars.Add(scopeName,
102-
new Grammar(
101+
102+
value = new Grammar(
103103
scopeName,
104104
rawGrammar,
105105
initialLanguage,
106106
embeddedLanguages,
107107
tokenTypes,
108108
balancedBracketSelectors,
109109
this,
110-
this));
110+
this);
111+
this._grammars.Add(scopeName, value);
111112
}
112-
return this._grammars[scopeName];
113+
return value;
113114
}
114115

115116
private static void CollectIncludedScopes(ICollection<string> result, IRawGrammar grammar)

src/TextMateSharp/Themes/Theme.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,12 @@ internal List<ThemeTrieElementRule> Match(string scopeName)
322322
{
323323
lock (this._cachedMatchRoot)
324324
{
325-
if (!this._cachedMatchRoot.ContainsKey(scopeName))
325+
if (!_cachedMatchRoot.TryGetValue(scopeName, out List<ThemeTrieElementRule> value))
326326
{
327-
this._cachedMatchRoot[scopeName] = this._root.Match(scopeName);
327+
value = this._root.Match(scopeName);
328+
this._cachedMatchRoot[scopeName] = value;
328329
}
329-
return this._cachedMatchRoot[scopeName];
330+
return value;
330331
}
331332
}
332333

src/TextMateSharp/Themes/ThemeTrieElement.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ public List<ThemeTrieElementRule> Match(string scope)
9494
tail = scope.Substring(dotIndex + 1);
9595
}
9696

97-
if (this.children.ContainsKey(head))
97+
if (children.TryGetValue(head, out ThemeTrieElement value))
9898
{
99-
return this.children[head].Match(tail);
99+
return value.Match(tail);
100100
}
101101

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

132132
ThemeTrieElement child;
133-
if (this.children.ContainsKey(head))
133+
if (children.TryGetValue(head, out ThemeTrieElement value))
134134
{
135-
child = this.children[head];
135+
child = value;
136136
}
137137
else
138138
{

0 commit comments

Comments
 (0)