diff --git a/.editorconfig b/.editorconfig
index f8ad6ea8e56..9e4042e0a42 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -78,7 +78,8 @@ csharp_prefer_static_local_function = true:suggestion
dotnet_diagnostic.IDE0010.severity = suggestion # IDE0010: Add missing cases to switch statement
dotnet_style_object_initializer = true:suggestion # IDE0017: Use object initializers
csharp_style_inlined_variable_declaration = true:suggestion # IDE0018: Inline variable declaration
-dotnet_style_collection_initializer = true:suggestion # IDE0028: Use collection initializers
+dotnet_style_collection_initializer = true:suggestion # IDE0028: Use collection initializers or expressions
+dotnet_style_prefer_collection_expression = true:suggestion # IDE0028: Use collection initializers or expressions
dotnet_style_prefer_auto_properties = true:suggestion # IDE0032: Use auto-implemented property
dotnet_style_explicit_tuple_names = true:suggestion # IDE0033: Use explicitly provided tuple name
csharp_prefer_simple_default_expression = true:suggestion # IDE0034: Simplify default expression
diff --git a/src/Docfx.App/Config/BuildJsonConfig.cs b/src/Docfx.App/Config/BuildJsonConfig.cs
index c9dd2a4003a..ed4b395004f 100644
--- a/src/Docfx.App/Config/BuildJsonConfig.cs
+++ b/src/Docfx.App/Config/BuildJsonConfig.cs
@@ -72,7 +72,7 @@ internal class BuildJsonConfig
///
[JsonProperty("globalMetadataFiles")]
[JsonPropertyName("globalMetadataFiles")]
- public ListWithStringFallback GlobalMetadataFiles { get; set; } = new();
+ public ListWithStringFallback GlobalMetadataFiles { get; set; } = [];
///
/// Metadata that applies to some specific files.
@@ -99,7 +99,7 @@ internal class BuildJsonConfig
///
[JsonProperty("template")]
[JsonPropertyName("template")]
- public ListWithStringFallback Template { get; set; } = new();
+ public ListWithStringFallback Template { get; set; } = [];
///
/// The themes applied to the documentation.
@@ -123,7 +123,7 @@ internal class BuildJsonConfig
///
[JsonProperty("postProcessors")]
[JsonPropertyName("postProcessors")]
- public ListWithStringFallback PostProcessors { get; set; } = new();
+ public ListWithStringFallback PostProcessors { get; set; } = [];
///
/// Run in debug mode. With debug mode, raw model and view model will be exported
diff --git a/src/Docfx.App/Config/FileMetadataPairs.cs b/src/Docfx.App/Config/FileMetadataPairs.cs
index 7390e638ad1..b816e909576 100644
--- a/src/Docfx.App/Config/FileMetadataPairs.cs
+++ b/src/Docfx.App/Config/FileMetadataPairs.cs
@@ -39,7 +39,7 @@ public FileMetadataPairs(IEnumerable items)
///
public FileMetadataPairs(FileMetadataPairsItem item)
{
- _items = new List { item };
+ _items = [item];
}
///
diff --git a/src/Docfx.App/Config/GroupConfig.cs b/src/Docfx.App/Config/GroupConfig.cs
index c6346938de3..f443a717c1a 100644
--- a/src/Docfx.App/Config/GroupConfig.cs
+++ b/src/Docfx.App/Config/GroupConfig.cs
@@ -23,5 +23,5 @@ internal class GroupConfig
///
[Newtonsoft.Json.JsonExtensionData]
[System.Text.Json.Serialization.JsonExtensionData]
- public Dictionary Metadata { get; set; } = new();
+ public Dictionary Metadata { get; set; } = [];
}
diff --git a/src/Docfx.App/Helpers/DocumentBuilderWrapper.cs b/src/Docfx.App/Helpers/DocumentBuilderWrapper.cs
index 2bafb81bef6..c9324530912 100644
--- a/src/Docfx.App/Helpers/DocumentBuilderWrapper.cs
+++ b/src/Docfx.App/Helpers/DocumentBuilderWrapper.cs
@@ -263,7 +263,7 @@ private static FileMetadata GetFileMetadata(string baseDirectory, BuildJsonConfi
{
foreach (var (key, value) in config.FileMetadata)
{
- var list = result.TryGetValue(key, out var items) ? items : result[key] = new();
+ var list = result.TryGetValue(key, out var items) ? items : result[key] = [];
foreach (var pair in value.Items)
{
list.Add(new FileMetadataItem(pair.Glob, key, pair.Value));
@@ -277,7 +277,7 @@ private static FileMetadata GetFileMetadata(string baseDirectory, BuildJsonConfi
{
foreach (var (key, value) in JsonUtility.Deserialize>(path))
{
- var list = result.TryGetValue(key, out var items) ? items : result[key] = new();
+ var list = result.TryGetValue(key, out var items) ? items : result[key] = [];
foreach (var pair in value.Items)
{
list.Add(new FileMetadataItem(pair.Glob, key, pair.Value));
diff --git a/src/Docfx.App/Helpers/MetadataMerger.cs b/src/Docfx.App/Helpers/MetadataMerger.cs
index 2dee2e496f3..c4b80118d2f 100644
--- a/src/Docfx.App/Helpers/MetadataMerger.cs
+++ b/src/Docfx.App/Helpers/MetadataMerger.cs
@@ -14,8 +14,8 @@ namespace Docfx;
internal class MetadataMerger
{
- private readonly Dictionary> _metaTable = new();
- private readonly Dictionary> _propTable = new();
+ private readonly Dictionary> _metaTable = [];
+ private readonly Dictionary> _propTable = [];
public void Merge(MetadataMergeParameters parameters)
{
diff --git a/src/Docfx.App/PdfBuilder.cs b/src/Docfx.App/PdfBuilder.cs
index 2e4123f6a3b..9cef7a4696b 100644
--- a/src/Docfx.App/PdfBuilder.cs
+++ b/src/Docfx.App/PdfBuilder.cs
@@ -297,7 +297,7 @@ await Parallel.ForEachAsync(pages, async (item, _) =>
var key = CleanUrl(url);
if (!pagesByUrl.TryGetValue(key, out var dests))
- pagesByUrl[key] = dests = new();
+ pagesByUrl[key] = dests = [];
dests.Add((node, document.Structure.Catalog.GetNamedDestinations()));
pageBytes[node] = bytes;
diff --git a/src/Docfx.App/RunBuild.cs b/src/Docfx.App/RunBuild.cs
index 5501ae9e856..0549827bfd3 100644
--- a/src/Docfx.App/RunBuild.cs
+++ b/src/Docfx.App/RunBuild.cs
@@ -21,7 +21,7 @@ public static string Exec(BuildJsonConfig config, BuildOptions options, string c
var stopwatch = Stopwatch.StartNew();
if (config.Template == null || config.Template.Count == 0)
{
- config.Template = new ListWithStringFallback { "default" };
+ config.Template = ["default"];
}
var baseDirectory = Path.GetFullPath(string.IsNullOrEmpty(configDirectory) ? Directory.GetCurrentDirectory() : configDirectory);
diff --git a/src/Docfx.App/RunMerge.cs b/src/Docfx.App/RunMerge.cs
index 76df5b5ed51..1b6ed57744a 100644
--- a/src/Docfx.App/RunMerge.cs
+++ b/src/Docfx.App/RunMerge.cs
@@ -56,7 +56,7 @@ private static MetadataMergeParameters ConfigToParameter(MergeJsonItemConfig con
OutputBaseDir = outputDirectory,
Metadata = config.GlobalMetadata?.ToImmutableDictionary() ?? ImmutableDictionary.Empty,
FileMetadata = ConvertToFileMetadataItem(baseDirectory, config.FileMetadata),
- TocMetadata = config.TocMetadata?.ToImmutableList() ?? ImmutableList.Empty,
+ TocMetadata = config.TocMetadata?.ToImmutableList() ?? [],
Files = GetFileCollectionFromFileMapping(
baseDirectory,
DocumentType.Article,
diff --git a/src/Docfx.Build.Common/MarkdownReader.cs b/src/Docfx.Build.Common/MarkdownReader.cs
index 1aae2b1eaf8..66e9a40fc33 100644
--- a/src/Docfx.Build.Common/MarkdownReader.cs
+++ b/src/Docfx.Build.Common/MarkdownReader.cs
@@ -13,7 +13,7 @@ namespace Docfx.Build.Common;
public class MarkdownReader
{
- private static readonly ImmutableList RequiredProperties = ImmutableList.Create(Constants.PropertyName.Uid);
+ private static readonly ImmutableList RequiredProperties = [Constants.PropertyName.Uid];
public static IEnumerable ReadMarkdownAsOverwrite(IHostService host, FileAndType ft)
{
diff --git a/src/Docfx.Build.Common/ModelAttributeHandlers/HandleModelAttributesContext.cs b/src/Docfx.Build.Common/ModelAttributeHandlers/HandleModelAttributesContext.cs
index 10f37bc5c1c..87a6811be05 100644
--- a/src/Docfx.Build.Common/ModelAttributeHandlers/HandleModelAttributesContext.cs
+++ b/src/Docfx.Build.Common/ModelAttributeHandlers/HandleModelAttributesContext.cs
@@ -14,11 +14,11 @@ public class HandleModelAttributesContext
public bool EnableContentPlaceholder { get; set; }
public string PlaceholderContent { get; set; }
public bool ContainsPlaceholder { get; set; }
- public HashSet Dependency { get; set; } = new();
+ public HashSet Dependency { get; set; } = [];
public FileAndType FileAndType { get; set; }
public HashSet LinkToFiles { get; set; } = new(FilePathComparer.OSPlatformSensitiveStringComparer);
- public HashSet LinkToUids { get; set; } = new();
- public List Uids { get; set; } = new();
- public Dictionary> UidLinkSources { get; set; } = new();
- public Dictionary> FileLinkSources { get; set; } = new();
+ public HashSet LinkToUids { get; set; } = [];
+ public List Uids { get; set; } = [];
+ public Dictionary> UidLinkSources { get; set; } = [];
+ public Dictionary> FileLinkSources { get; set; } = [];
}
diff --git a/src/Docfx.Build.Common/ModelAttributeHandlers/Handlers/UrlContentHandler.cs b/src/Docfx.Build.Common/ModelAttributeHandlers/Handlers/UrlContentHandler.cs
index 369a59e41f3..9cd182da3fa 100644
--- a/src/Docfx.Build.Common/ModelAttributeHandlers/Handlers/UrlContentHandler.cs
+++ b/src/Docfx.Build.Common/ModelAttributeHandlers/Handlers/UrlContentHandler.cs
@@ -98,7 +98,7 @@ private static string GetHrefFromRoot(string originalHref, HandleModelAttributes
if (!context.FileLinkSources.TryGetValue(file, out List sources))
{
- sources = new List();
+ sources = [];
context.FileLinkSources[file] = sources;
}
sources.Add(new LinkSourceInfo
diff --git a/src/Docfx.Build.Common/Reference/OverwriteDocumentModel.cs b/src/Docfx.Build.Common/Reference/OverwriteDocumentModel.cs
index 8ac8f568cbb..90d9118ba0c 100644
--- a/src/Docfx.Build.Common/Reference/OverwriteDocumentModel.cs
+++ b/src/Docfx.Build.Common/Reference/OverwriteDocumentModel.cs
@@ -17,7 +17,7 @@ public class OverwriteDocumentModel
[ExtensibleMember]
[Newtonsoft.Json.JsonExtensionData]
[System.Text.Json.Serialization.JsonExtensionData]
- public Dictionary Metadata { get; set; } = new();
+ public Dictionary Metadata { get; set; } = [];
///
/// The uid for this overwrite document, as defined in YAML header
@@ -49,7 +49,7 @@ public class OverwriteDocumentModel
[YamlIgnore]
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
- public HashSet LinkToFiles { get; set; } = new();
+ public HashSet LinkToFiles { get; set; } = [];
///
/// Links to other Uids
@@ -57,7 +57,7 @@ public class OverwriteDocumentModel
[YamlIgnore]
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
- public HashSet LinkToUids { get; set; } = new();
+ public HashSet LinkToUids { get; set; } = [];
///
/// Link sources information for file
@@ -65,7 +65,7 @@ public class OverwriteDocumentModel
[YamlIgnore]
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
- public Dictionary> FileLinkSources { get; set; } = new();
+ public Dictionary> FileLinkSources { get; set; } = [];
///
/// Link sources information for Uid
@@ -73,7 +73,7 @@ public class OverwriteDocumentModel
[YamlIgnore]
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
- public Dictionary> UidLinkSources { get; set; } = new();
+ public Dictionary> UidLinkSources { get; set; } = [];
///
/// Dependencies extracted from the markdown content
diff --git a/src/Docfx.Build.ManagedReference/ApplyPlatformVersion.cs b/src/Docfx.Build.ManagedReference/ApplyPlatformVersion.cs
index 9135d8c370a..87da14659f5 100644
--- a/src/Docfx.Build.ManagedReference/ApplyPlatformVersion.cs
+++ b/src/Docfx.Build.ManagedReference/ApplyPlatformVersion.cs
@@ -60,7 +60,7 @@ private static List GetPlatformVersionFromMetadata(object value)
{
if (value is string text)
{
- return new List { text };
+ return [text];
}
if (value is IEnumerable