Skip to content

Commit f801d03

Browse files
committed
chore: use collection expressions
1 parent f5673e5 commit f801d03

File tree

56 files changed

+176
-176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+176
-176
lines changed

src/Docfx.App/PdfBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static async Task CreatePdf(string outputFolder)
6464
if (pdfTocs.Count == 0)
6565
return;
6666

67-
Program.Main(new[] { "install", "chromium" });
67+
Program.Main(["install", "chromium"]);
6868

6969
var builder = WebApplication.CreateBuilder();
7070
builder.Logging.ClearProviders();

src/Docfx.Build.Common/ModelAttributeHandlers/Handlers/HandleGenericItemsHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private static bool HandleItems(Type genericInterface, Type implHandlerType, obj
5353
var genericType = ReflectionHelper.GetGenericType(type, genericInterface);
5454
if (genericType != null)
5555
{
56-
var instance = (IHandleItems)ReflectionHelper.CreateInstance(implHandlerType, genericType.GenericTypeArguments, new[] { genericType }, new object[] { currentObj });
56+
var instance = (IHandleItems)ReflectionHelper.CreateInstance(implHandlerType, genericType.GenericTypeArguments, [genericType], [currentObj]);
5757
if (instance != null)
5858
{
5959
instance.Handle(handler);

src/Docfx.Build.Common/ModelAttributeHandlers/ReflectionHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private static Func<object[], object> GetCreateInstanceFunc(Tuple<Type, Type[],
118118

119119
private static Func<object[], object> GetCreateInstanceFuncCore(ConstructorInfo ctor, Type[] argumentTypes)
120120
{
121-
var dm = new DynamicMethod(string.Empty, typeof(object), new[] { typeof(object[]) });
121+
var dm = new DynamicMethod(string.Empty, typeof(object), [typeof(object[])]);
122122
var il = dm.GetILGenerator();
123123
for (int i = 0; i < argumentTypes.Length; i++)
124124
{
@@ -249,7 +249,7 @@ public static object GetPropertyValue(object instance, PropertyInfo prop)
249249

250250
private static Func<object, object> CreateGetPropertyFunc(PropertyInfo prop)
251251
{
252-
var dm = new DynamicMethod(string.Empty, typeof(object), new[] { typeof(object) });
252+
var dm = new DynamicMethod(string.Empty, typeof(object), [typeof(object)]);
253253
var il = dm.GetILGenerator();
254254
il.Emit(OpCodes.Ldarg_0);
255255
if (prop.DeclaringType.IsValueType)
@@ -281,7 +281,7 @@ public static void SetPropertyValue(object instance, PropertyInfo prop, object v
281281

282282
private static Action<object, object> CreateSetPropertyFunc(PropertyInfo prop)
283283
{
284-
var dm = new DynamicMethod(string.Empty, typeof(void), new[] { typeof(object), typeof(object) });
284+
var dm = new DynamicMethod(string.Empty, typeof(void), [typeof(object), typeof(object)]);
285285
var il = dm.GetILGenerator();
286286
il.Emit(OpCodes.Ldarg_0);
287287
if (prop.DeclaringType.IsValueType)

src/Docfx.Build.ManagedReference/BuildOutputs/ApiBuildOutput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class ApiBuildOutput
4747
[YamlMember(Alias = "langs")]
4848
[JsonProperty("langs")]
4949
[JsonPropertyName("langs")]
50-
public string[] SupportedLanguages { get; set; } = new string[] { "csharp", "vb" };
50+
public string[] SupportedLanguages { get; set; } = ["csharp", "vb"];
5151

5252
[YamlMember(Alias = "name")]
5353
[JsonProperty("name")]

src/Docfx.Build.ManagedReference/ManagedReferenceDocumentProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Docfx.Build.ManagedReference;
1717
public class ManagedReferenceDocumentProcessor : ReferenceDocumentProcessorBase
1818
{
1919
#region Fields
20-
private static readonly string[] SystemKeys = {
20+
private static readonly string[] SystemKeys = [
2121
"uid",
2222
"isEii",
2323
"isExtensionMethod",
@@ -52,7 +52,7 @@ public class ManagedReferenceDocumentProcessor : ReferenceDocumentProcessorBase
5252
"platform",
5353
"attributes",
5454
Constants.PropertyName.AdditionalNotes
55-
};
55+
];
5656
#endregion
5757

5858
#region Constructors

src/Docfx.Build.OverwriteDocuments/OverwriteUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Docfx.Build.OverwriteDocuments;
99

1010
public static class OverwriteUtility
1111
{
12-
private static readonly string[] UidWrappers = { "`", "``", "```", "````", "`````", "``````" };
12+
private static readonly string[] UidWrappers = ["`", "``", "```", "````", "`````", "``````"];
1313

1414
private static readonly Regex OPathRegex =
1515
new(

src/Docfx.Build.RestApi/RestApiDocumentProcessor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ public class RestApiDocumentProcessor : ReferenceDocumentProcessorBase
2828
// To keep backward compatibility, still support and change previous file endings by first mapping sequence.
2929
// Take 'a.b_swagger2.json' for an example, the json file name would be changed to 'a.b', then the html file name would be 'a.b.html'.
3030
private static readonly string[] SupportedFileEndings =
31-
{
31+
[
3232
"_swagger2.json",
3333
"_swagger.json",
3434
".swagger.json",
3535
".swagger2.json",
3636
".json",
37-
};
37+
];
3838

39-
protected static readonly string[] SystemKeys = {
39+
protected static readonly string[] SystemKeys = [
4040
"uid",
4141
"htmlId",
4242
"name",
@@ -64,7 +64,7 @@ public class RestApiDocumentProcessor : ReferenceDocumentProcessorBase
6464
"security",
6565
"tags",
6666
"externalDocs"
67-
};
67+
];
6868

6969
[ImportMany(nameof(RestApiDocumentProcessor))]
7070
public override IEnumerable<IDocumentBuildStep> BuildSteps { get; set; }

src/Docfx.Build.RestApi/SwaggerModelConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static RestApiRootItemViewModel FromSwaggerModel(SwaggerModel swagger)
115115

116116
private static readonly Regex HtmlEncodeRegex = new(@"\W", RegexOptions.Compiled);
117117
private const string TagText = "tag";
118-
private static readonly string[] OperationNames = { "get", "put", "post", "delete", "options", "head", "patch" };
118+
private static readonly string[] OperationNames = ["get", "put", "post", "delete", "options", "head", "patch"];
119119

120120
/// <summary>
121121
/// TODO: merge with the one in XrefDetails

src/Docfx.Build/Conceptual/ConceptualDocumentProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Docfx.Build.ConceptualDocuments;
1414
[Export(typeof(IDocumentProcessor))]
1515
class ConceptualDocumentProcessor : DisposableDocumentProcessor
1616
{
17-
private readonly string[] SystemKeys = {
17+
private readonly string[] SystemKeys = [
1818
"conceptual",
1919
"type",
2020
"source",
@@ -23,7 +23,7 @@ class ConceptualDocumentProcessor : DisposableDocumentProcessor
2323
"title",
2424
"rawTitle",
2525
"wordCount"
26-
};
26+
];
2727

2828
public ConceptualDocumentProcessor()
2929
{

src/Docfx.Build/Conceptual/WordCounter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Docfx.Build.ConceptualDocuments;
77

88
internal static class WordCounter
99
{
10-
private static readonly string[] ExcludeNodeXPaths = { "//title" };
10+
private static readonly string[] ExcludeNodeXPaths = ["//title"];
1111

1212
public static long CountWord(string html)
1313
{
@@ -51,7 +51,7 @@ private static int CountWordInText(string text)
5151
}
5252

5353
string specialChars = ".?!;:,()[]";
54-
char[] delimiterChars = { ' ', '\t', '\n' };
54+
char[] delimiterChars = [' ', '\t', '\n'];
5555

5656
string[] wordList = text.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
5757
return wordList.Count(s => !s.Trim().All(specialChars.Contains));

src/Docfx.Build/MarkupResultUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Docfx.Build.Engine;
1111

1212
public static class MarkupUtility
1313
{
14-
private static readonly char[] UriFragmentOrQueryString = new char[] { '#', '?' };
14+
private static readonly char[] UriFragmentOrQueryString = ['#', '?'];
1515

1616
public static MarkupResult Parse(MarkupResult markupResult, FileAndType ft, ImmutableDictionary<string, FileAndType> sourceFiles)
1717
{

src/Docfx.Build/OneOfJsonConverterFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private class OneOfJsonConverter<T> : JsonConverter<T> where T : IOneOf
4343
Utf8JsonReader readerCopy = reader;
4444
var result = JsonSerializer.Deserialize(ref readerCopy, type, options);
4545
reader.Skip();
46-
return (T)cast.Invoke(null, new[] { result })!;
46+
return (T)cast.Invoke(null, [result])!;
4747
}
4848
catch (JsonException)
4949
{

src/Docfx.Build/PostProcessors/RemoveDebugInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ namespace Docfx.Build.Engine;
99
class RemoveDebugInfo : HtmlDocumentHandler
1010
{
1111
private readonly string[] DebugInfoAttributes =
12-
{
12+
[
1313
"sourceFile",
1414
"sourceStartLineNumber",
1515
"sourceEndLineNumber",
1616
"jsonPath",
1717
"data-raw-source",
1818
"nocheck",
19-
};
19+
];
2020

2121
protected override void HandleCore(HtmlDocument document, ManifestItem manifestItem, string inputFile, string outputFile)
2222
{

src/Docfx.Build/TableOfContents/BuildTocDocument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void UpdateDependencies(HashSet<string> linkTos, Dictionary<string, ImmutableLis
8585

8686
private static string ParseFile(string link)
8787
{
88-
var queryIndex = link.IndexOfAny(new[] { '?', '#' });
88+
var queryIndex = link.IndexOfAny(['?', '#']);
8989
return queryIndex == -1 ? link : link.Remove(queryIndex);
9090
}
9191

src/Docfx.Build/TableOfContents/TocDocumentProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Docfx.Build.TableOfContents;
1414
[Export(typeof(IDocumentProcessor))]
1515
class TocDocumentProcessor : DisposableDocumentProcessor
1616
{
17-
private static readonly char[] QueryStringOrAnchor = new[] { '#', '?' };
17+
private static readonly char[] QueryStringOrAnchor = ['#', '?'];
1818

1919
public override string Name => nameof(TocDocumentProcessor);
2020

src/Docfx.Common/Path/RelativePath.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public sealed class RelativePath : IEquatable<RelativePath>
1717
public const string WorkingFolderString = "~";
1818
public static readonly string NormalizedWorkingFolder = "~/";
1919
public static readonly string AltWorkingFolder = "~\\";
20-
public static readonly RelativePath Empty = new(false, 0, new string[] { string.Empty });
21-
public static readonly RelativePath WorkingFolder = new(true, 0, new string[] { string.Empty });
20+
public static readonly RelativePath Empty = new(false, 0, [string.Empty]);
21+
public static readonly RelativePath WorkingFolder = new(true, 0, [string.Empty]);
2222
public static readonly char[] InvalidPartChars = PathUtility.InvalidPathChars.Concat(@"\/?").ToArray();
2323
private static readonly string[] EncodedInvalidPartChars = Array.ConvertAll(InvalidPartChars, ch => Uri.EscapeDataString(ch.ToString()));
24-
private static readonly char[] UnsafeInvalidPartChars = { '/' };
24+
private static readonly char[] UnsafeInvalidPartChars = ['/'];
2525
private static readonly string[] EncodedUnsafeInvalidPartChars = Array.ConvertAll(UnsafeInvalidPartChars, ch => Uri.EscapeDataString(ch.ToString()));
2626
private static readonly IDictionary<string, string> SpecialCharactersNeedToDecode = new Dictionary<string, string>
2727
{

src/Docfx.Common/UriUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static class UriUtility
99
{
1010
private const char QueryMarker = '?';
1111
private const char FragmentMarker = '#';
12-
private static readonly char[] QueryAndFragmentMarkers = { QueryMarker, FragmentMarker };
12+
private static readonly char[] QueryAndFragmentMarkers = [QueryMarker, FragmentMarker];
1313

1414
public static bool HasFragment(string uriString)
1515
{

src/Docfx.Dotnet/CompilationHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ namespace Docfx.Dotnet;
1515
internal static class CompilationHelper
1616
{
1717
// Bootstrap code to ensure essential types like `System.Object` is loaded for assemblies
18-
private static readonly SyntaxTree[] s_assemblyBootstrap = new[]
19-
{
18+
private static readonly SyntaxTree[] s_assemblyBootstrap =
19+
[
2020
CS.SyntaxFactory.ParseSyntaxTree(
2121
"""
2222
class Bootstrap
2323
{
2424
public static void Main(string[] foo) { }
2525
}
2626
"""),
27-
};
27+
];
2828

2929
public static bool CheckDiagnostics(this Compilation compilation, bool errorAsWarning)
3030
{

src/Docfx.Dotnet/DotnetApiCatalog.ApiPage.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,10 @@ void Returns(IMethodSymbol symbol, XmlComment? comment, int headingLevel)
488488
Heading(headingLevel, "Returns");
489489
body.Add(new Parameters
490490
{
491-
parameters = new[]
492-
{
491+
parameters =
492+
[
493493
new Parameter() { type = FullLink(symbol.ReturnType, compilation), description = comment?.Returns }
494-
}
494+
]
495495
});
496496
}
497497

@@ -539,10 +539,10 @@ void Field(IFieldSymbol symbol, Compilation compilation, int headingLevel)
539539
Heading(headingLevel + 1, "Field Value");
540540
body.Add(new Parameters
541541
{
542-
parameters = new[]
543-
{
542+
parameters =
543+
[
544544
new Parameter() { type = FullLink(symbol.Type, compilation) }
545-
}
545+
]
546546
});
547547

548548
Examples(comment, headingLevel + 1);
@@ -562,10 +562,10 @@ void Property(IPropertySymbol symbol, Compilation compilation, int headingLevel)
562562
Heading(headingLevel + 1, "Property Value");
563563
body.Add(new Parameters
564564
{
565-
parameters = new[]
566-
{
565+
parameters =
566+
[
567567
new Parameter() { type = FullLink(symbol.Type, compilation) }
568-
}
568+
]
569569
});
570570

571571
Examples(comment, headingLevel + 1);
@@ -585,10 +585,10 @@ void Event(IEventSymbol symbol, Compilation compilation, int headingLevel)
585585
Heading(headingLevel + 1, "Event Type");
586586
body.Add(new Parameters
587587
{
588-
parameters = new[]
589-
{
588+
parameters =
589+
[
590590
new Parameter() { type = FullLink(symbol.Type, compilation) }
591-
}
591+
]
592592
});
593593

594594
Examples(comment, headingLevel + 1);

src/Docfx.Dotnet/ManagedReference/Models/ItemViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class ItemViewModel : IOverwriteDocumentViewModel
6262
[YamlMember(Alias = "langs")]
6363
[JsonProperty("langs")]
6464
[JsonPropertyName("langs")]
65-
public string[] SupportedLanguages { get; set; } = new string[] { "csharp", "vb" };
65+
public string[] SupportedLanguages { get; set; } = ["csharp", "vb"];
6666

6767
[YamlMember(Alias = Constants.PropertyName.Name)]
6868
[JsonProperty(Constants.PropertyName.Name)]

src/Docfx.Dotnet/SourceLink/SourceLinkMap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public bool TryGetUri(
201201
{
202202
if (path.StartsWith(file.Path, StringComparison.OrdinalIgnoreCase))
203203
{
204-
var escapedPath = string.Join("/", path[file.Path.Length..].Split(new[] { '/', '\\' }).Select(Uri.EscapeDataString));
204+
var escapedPath = string.Join("/", path[file.Path.Length..].Split(['/', '\\']).Select(Uri.EscapeDataString));
205205
uri = mappedUri.Prefix + escapedPath + mappedUri.Suffix;
206206
return true;
207207
}

src/Docfx.Glob/GlobMatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private IEnumerable<GlobRegexItem[]> Compile(string pattern)
117117
}
118118
else
119119
{
120-
globs = new string[] { pattern };
120+
globs = [pattern];
121121
}
122122

123123
// **.cs is a shortcut for **/*.cs

src/Docfx.MarkdigEngine.Extensions/CodeSnippet/CodeSnippetParser.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class CodeSnippetParser : BlockParser
1313

1414
public CodeSnippetParser()
1515
{
16-
OpeningCharacters = new[] { '[' };
16+
OpeningCharacters = ['['];
1717
}
1818

1919
public override BlockState TryOpen(BlockProcessor processor)
@@ -283,13 +283,13 @@ private static bool TryParseQuery(string queryString, ref CodeSnippet codeSnippe
283283
{
284284
if (string.IsNullOrEmpty(queryString)) return false;
285285

286-
var splitQueryItems = queryString.Split(new[] { '&' });
286+
var splitQueryItems = queryString.Split(['&']);
287287

288288
int start = -1, end = -1;
289289

290290
foreach (var queryItem in splitQueryItems)
291291
{
292-
var keyValueSplit = queryItem.Split(new[] { '=' });
292+
var keyValueSplit = queryItem.Split(['=']);
293293
if (keyValueSplit.Length != 2) return false;
294294
var key = keyValueSplit[0];
295295
var value = keyValueSplit[1];

0 commit comments

Comments
 (0)