Skip to content

Commit 939a64c

Browse files
committed
.NET 8 and more syntax updates
1 parent c760591 commit 939a64c

8 files changed

Lines changed: 36 additions & 70 deletions

File tree

SharpDenizenTools/GlobalSuppressions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77

88
[assembly: SuppressMessage("Usage", "CA2211:Non-constant fields should not be visible")]
99
[assembly: SuppressMessage("Style", "IDE0074:Use compound assignment", Justification = "awkward syntax")]
10+
[assembly: SuppressMessage("Performance", "CA1860:Avoid using 'Enumerable.Any()' extension method")]

SharpDenizenTools/MetaHandlers/MetaDocsLoader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public static void LoadDataFromLines(MetaDocs docs, string websrc, (int, string,
303303
for (int i = 0; i < lines.Length; i++)
304304
{
305305
(int lineNum, string file, string line) = lines[i];
306-
if (line.StartsWith("<--[") && line.EndsWith("]"))
306+
if (line.StartsWith("<--[") && line.EndsWith(']'))
307307
{
308308
string objectType = line.Substring("<--[".Length, line.Length - "<--[]".Length);
309309
List<string> objectData = [];
@@ -367,7 +367,7 @@ public static void LoadInObject(MetaDocs docs, string objectType, string file, s
367367
string curValue = null;
368368
foreach (string line in objectData)
369369
{
370-
if (line.StartsWith("@"))
370+
if (line.StartsWith('@'))
371371
{
372372
if (curKey != null && curValue != null)
373373
{

SharpDenizenTools/MetaObjects/MetaAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public override bool ApplyValue(MetaDocs docs, string key, string value)
6565
}
6666
outRegex += $"({regexable})|";
6767
}
68-
if (outRegex.EndsWith("|"))
68+
if (outRegex.EndsWith('|'))
6969
{
7070
outRegex = outRegex[0..^1];
7171
}

SharpDenizenTools/MetaObjects/MetaObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public void PostCheckTags(MetaDocs docs, string[] tags)
239239
{
240240
foreach (string tag in tags)
241241
{
242-
if (tag.EndsWith(">"))
242+
if (tag.EndsWith('>'))
243243
{
244244
MetaTag realTag = docs.FindTag(tag);
245245
if (realTag == null)

SharpDenizenTools/MetaObjects/MetaTag.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public override bool ApplyValue(MetaDocs docs, string key, string value)
118118
case "attribute":
119119
TagFull = value;
120120
CleanedName = CleanTag(TagFull);
121-
if (CleanedName.Contains('.') && !CleanedName.StartsWith("&"))
121+
if (CleanedName.Contains('.') && !CleanedName.StartsWith('&'))
122122
{
123123
BeforeDot = CleanedName.Before('.');
124124
}

SharpDenizenTools/ScriptAnalysis/AdvancedMatcher.cs

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -26,64 +26,44 @@ public class AlwaysMatchHelper : MatchHelper
2626
}
2727

2828
/// <summary>Implements <see cref="MatchHelper"/>.</summary>
29-
public class ExactMatchHelper : MatchHelper
29+
public class ExactMatchHelper(string _text) : MatchHelper
3030
{
31-
/// <summary>Constructor.</summary>
32-
public ExactMatchHelper(string _text)
33-
{
34-
Text = _text.ToLowerFast();
35-
}
3631

3732
/// <summary>Required data.</summary>
38-
public string Text;
33+
public string Text = _text.ToLowerFast();
3934

4035
/// <summary>Implements <see cref="MatchHelper.DoesMatch(string)"/>.</summary>
4136
public override bool DoesMatch(string input) => Text == input.ToLowerFast();
4237
}
4338

4439
/// <summary>Implements <see cref="MatchHelper"/>.</summary>
45-
public class PrefixAsteriskMatchHelper : MatchHelper
40+
public class PrefixAsteriskMatchHelper(string _text) : MatchHelper
4641
{
47-
/// <summary>Constructor.</summary>
48-
public PrefixAsteriskMatchHelper(string _text)
49-
{
50-
Text = _text.ToLowerFast();
51-
}
5242

5343
/// <summary>Required data.</summary>
54-
public string Text;
44+
public string Text = _text.ToLowerFast();
5545

5646
/// <summary>Implements <see cref="MatchHelper.DoesMatch(string)"/>.</summary>
5747
public override bool DoesMatch(string input) => input.ToLowerFast().EndsWith(Text);
5848
}
5949

6050
/// <summary>Implements <see cref="MatchHelper"/>.</summary>
61-
public class PostfixAsteriskMatchHelper : MatchHelper
51+
public class PostfixAsteriskMatchHelper(string _text) : MatchHelper
6252
{
63-
/// <summary>Constructor.</summary>
64-
public PostfixAsteriskMatchHelper(string _text)
65-
{
66-
Text = _text.ToLowerFast();
67-
}
6853

6954
/// <summary>Required data.</summary>
70-
public string Text;
55+
public string Text = _text.ToLowerFast();
7156

7257
/// <summary>Implements <see cref="MatchHelper.DoesMatch(string)"/>.</summary>
7358
public override bool DoesMatch(string input) => input.ToLowerFast().StartsWith(Text);
7459
}
7560

7661
/// <summary>Implements <see cref="MatchHelper"/>.</summary>
77-
public class MultipleAsteriskMatchHelper : MatchHelper
62+
public class MultipleAsteriskMatchHelper(string[] _texts) : MatchHelper
7863
{
79-
/// <summary>Constructor.</summary>
80-
public MultipleAsteriskMatchHelper(string[] _texts)
81-
{
82-
Texts = _texts;
83-
}
8464

8565
/// <summary>Required data.</summary>
86-
public string[] Texts;
66+
public string[] Texts = _texts;
8767

8868
/// <summary>Implements <see cref="MatchHelper.DoesMatch(string)"/>.</summary>
8969
public override bool DoesMatch(string input)
@@ -112,32 +92,22 @@ public override bool DoesMatch(string input)
11292
}
11393

11494
/// <summary>Implements <see cref="MatchHelper"/>.</summary>
115-
public class RegexMatchHelper : MatchHelper
95+
public class RegexMatchHelper(string _regex) : MatchHelper
11696
{
117-
/// <summary>Constructor.</summary>
118-
public RegexMatchHelper(string _regex)
119-
{
120-
Pattern = new Regex(_regex, RegexOptions.Compiled | RegexOptions.IgnoreCase);
121-
}
12297

12398
/// <summary>Required data.</summary>
124-
public Regex Pattern;
99+
public Regex Pattern = new(_regex, RegexOptions.Compiled | RegexOptions.IgnoreCase);
125100

126101
/// <summary>Implements <see cref="MatchHelper.DoesMatch(string)"/>.</summary>
127102
public override bool DoesMatch(string input) => Pattern.IsMatch(input);
128103
}
129104

130105
/// <summary>Implements <see cref="MatchHelper"/>.</summary>
131-
public class MultipleMatchesHelper : MatchHelper
106+
public class MultipleMatchesHelper(MatchHelper[] _matches) : MatchHelper
132107
{
133-
/// <summary>Constructor.</summary>
134-
public MultipleMatchesHelper(MatchHelper[] _matches)
135-
{
136-
Matches = _matches;
137-
}
138108

139109
/// <summary>Required data.</summary>
140-
public MatchHelper[] Matches;
110+
public MatchHelper[] Matches = _matches;
141111

142112
/// <summary>Implements <see cref="MatchHelper.DoesMatch(string)"/>.</summary>
143113
public override bool DoesMatch(string input)
@@ -154,16 +124,11 @@ public override bool DoesMatch(string input)
154124
}
155125

156126
/// <summary>Implements <see cref="MatchHelper"/>.</summary>
157-
public class InverseMatchHelper : MatchHelper
127+
public class InverseMatchHelper(MatchHelper _matcher) : MatchHelper
158128
{
159-
/// <summary>Constructor.</summary>
160-
public InverseMatchHelper(MatchHelper _matcher)
161-
{
162-
Matcher = _matcher;
163-
}
164129

165130
/// <summary>Required data.</summary>
166-
public MatchHelper Matcher;
131+
public MatchHelper Matcher = _matcher;
167132

168133
/// <summary>Implements <see cref="MatchHelper.DoesMatch(string)"/>.</summary>
169134
public override bool DoesMatch(string input) => !Matcher.DoesMatch(input);
@@ -180,7 +145,7 @@ public static MatchHelper CreateMatcher(string input)
180145
{
181146
MatchHelper result;
182147
int asterisk;
183-
if (input.StartsWith("!"))
148+
if (input.StartsWith('!'))
184149
{
185150
result = new InverseMatchHelper(CreateMatcher(input[1..]));
186151
}

SharpDenizenTools/ScriptAnalysis/ScriptChecker.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public void ClearCommentsFromLines()
180180
{
181181
for (int i = 0; i < CleanedLines.Length; i++)
182182
{
183-
if (CleanedLines[i].StartsWith("#"))
183+
if (CleanedLines[i].StartsWith('#'))
184184
{
185185
if (Lines[i].StartsWith("##") && CleanedLines[i].StartsWith("##ignorewarning "))
186186
{
@@ -199,11 +199,11 @@ public void ClearCommentsFromLines()
199199
{
200200
BlankLines++;
201201
}
202-
else if (CleanedLines[i].StartsWith("-"))
202+
else if (CleanedLines[i].StartsWith('-'))
203203
{
204204
CodeLines++;
205205
}
206-
else if (CleanedLines[i].EndsWith(":"))
206+
else if (CleanedLines[i].EndsWith(':'))
207207
{
208208
StructureLines++;
209209
}
@@ -277,7 +277,7 @@ public void LoadInjects()
277277
{
278278
for (int x = i; x >= 0; x--)
279279
{
280-
if (CleanedLines[x].Length > 0 && CleanedLines[x].EndsWith(":") && !Lines[x].Replace("\t", " ").StartsWith(" "))
280+
if (CleanedLines[x].Length > 0 && CleanedLines[x].EndsWith(':') && !Lines[x].Replace("\t", " ").StartsWith(' '))
281281
{
282282
string scriptName = CleanedLines[x][0..^1];
283283
Injects.Add(scriptName);
@@ -305,7 +305,7 @@ public void BasicLineFormatCheck()
305305
for (int i = 0; i < Lines.Length; i++)
306306
{
307307
string line = Lines[i];
308-
if (line.EndsWith(" "))
308+
if (line.EndsWith(' '))
309309
{
310310
int endChar;
311311
for (endChar = line.Length - 1; endChar >= 0; endChar--)
@@ -318,7 +318,7 @@ public void BasicLineFormatCheck()
318318
endChar = Math.Max(0, endChar);
319319
Warn(MinorWarnings, i, "stray_space_eol", "Stray space after end of line (possible copy/paste mixup. Enable View->Render Whitespace in VS Code).", endChar, Math.Max(endChar, line.Length - 1));
320320
}
321-
else if (CleanedLines[i].StartsWith("- ") && !CleanedLines[i].EndsWith(":"))
321+
else if (CleanedLines[i].StartsWith("- ") && !CleanedLines[i].EndsWith(':'))
322322
{
323323
int spaces = CountPreSpaces(line);
324324
while (i + 1 < Lines.Length)
@@ -379,7 +379,7 @@ public void CheckForBraces()
379379
}
380380
for (int i = 0; i < Lines.Length; i++)
381381
{
382-
if (Lines[i].EndsWith("{") || Lines[i].EndsWith("}"))
382+
if (Lines[i].EndsWith('{') || Lines[i].EndsWith('}'))
383383
{
384384
int start = Lines[i].IndexOfAny(BracesChars);
385385
int end = Lines[i].LastIndexOfAny(BracesChars);
@@ -732,7 +732,7 @@ public static CommandArgument[] BuildArgs(int line, int startChar, string string
732732
hasSpace = true;
733733
}
734734
}
735-
if (!(hasSpace || (tagMarks != 0 && matched.Contains(' '))) && !matched.EndsWith(":"))
735+
if (!(hasSpace || (tagMarks != 0 && matched.Contains(' '))) && !matched.EndsWith(':'))
736736
{
737737
checker.Warn(checker.MinorWarnings, line, "bad_quotes", "Pointless quotes (arguments quoted but do not contain spaces).", startChar + start, startChar + i);
738738
}
@@ -793,7 +793,7 @@ public void CheckSingleCommand(int line, int startChar, string commandText, Scri
793793
string[] parts = commandText.Split(' ', 2);
794794
string commandName = parts[0].ToLowerFast();
795795
int cmdLen = commandName.Length;
796-
if (commandName.StartsWith("~") || commandName.StartsWith("^"))
796+
if (commandName.StartsWith('~') || commandName.StartsWith('^'))
797797
{
798798
commandName = commandName[1..];
799799
}
@@ -973,14 +973,14 @@ void checkAsScript(List<object> list, ScriptCheckContext context = null)
973973
if (typeString.Text == "task")
974974
{
975975
// Workaround the weird way shoot command does things
976-
context.Definitions.UnionWith(new[] { "shot_entities", "last_entity", "location", "hit_entities" });
976+
context.Definitions.UnionWith(["shot_entities", "last_entity", "location", "hit_entities"]);
977977
}
978978
else if (typeString.Text == "economy")
979979
{
980-
context.Definitions.UnionWith(new[] { "amount" });
980+
context.Definitions.UnionWith(["amount"]);
981981
}
982982
// Default run command definitions get used sometimes
983-
context.Definitions.UnionWith(new[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" });
983+
context.Definitions.UnionWith(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]);
984984
if (Injects.Contains(script.Name) || Injects.Contains("*"))
985985
{
986986
context.HasUnknowableDefinitions = true;
@@ -1492,7 +1492,7 @@ public Dictionary<LineTrackedString, object> GatherActualContainers()
14921492
continue;
14931493
}
14941494
string text = cleaned["- ".Length..];
1495-
if (!cleaned.EndsWith(":"))
1495+
if (!cleaned.EndsWith(':'))
14961496
{
14971497
while (i + 1 < Lines.Length)
14981498
{
@@ -1549,7 +1549,7 @@ public Dictionary<LineTrackedString, object> GatherActualContainers()
15491549
string startofline;
15501550
string endofline = "";
15511551
int endIndex = cleanStartCut;
1552-
if (cleaned.EndsWith(":"))
1552+
if (cleaned.EndsWith(':'))
15531553
{
15541554
startofline = cleaned[0..^1];
15551555
}

SharpDenizenTools/SharpDenizenTools.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<Configurations>Debug;Release</Configurations>
1313
<Version>1.0.0</Version>
1414
<ProjectGuid>{3DB47D69-4228-4F22-1763-152292496865}</ProjectGuid>
15-
<TargetFramework>net6.0</TargetFramework>
15+
<TargetFramework>net8.0</TargetFramework>
1616
</PropertyGroup>
1717
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
1818
<DebugSymbols>true</DebugSymbols>

0 commit comments

Comments
 (0)