From 1466228d3d39fb282ba26c7c9de74d8f4eb62563 Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Sat, 14 Dec 2024 22:33:17 +0900 Subject: [PATCH] chore: apply code formatter for IDE0028, and IDE0300-IDE0304 --- .editorconfig | 3 +- src/Docfx.App/Config/BuildJsonConfig.cs | 6 +- src/Docfx.App/Config/FileMetadataPairs.cs | 2 +- src/Docfx.App/Config/GroupConfig.cs | 2 +- .../Helpers/DocumentBuilderWrapper.cs | 4 +- src/Docfx.App/Helpers/MetadataMerger.cs | 4 +- src/Docfx.App/PdfBuilder.cs | 2 +- src/Docfx.App/RunBuild.cs | 2 +- src/Docfx.App/RunMerge.cs | 2 +- src/Docfx.Build.Common/MarkdownReader.cs | 2 +- .../HandleModelAttributesContext.cs | 10 +- .../Handlers/UrlContentHandler.cs | 2 +- .../Reference/OverwriteDocumentModel.cs | 10 +- .../ApplyPlatformVersion.cs | 2 +- .../BuildOutputs/ApiBuildOutput.cs | 2 +- .../BuildOutputs/ApiReferenceBuildOutput.cs | 2 +- .../FillReferenceInformation.cs | 2 +- .../MergeManagedReferenceDocument.cs | 2 +- .../SplitClassPageToMemberLevel.cs | 12 +- .../SplitRestApiToOperationLevel.cs | 10 +- .../MarkdownFragmentsCreator.cs | 2 +- .../OverwriteDocumentModelCreator.cs | 4 +- .../OverwriteUtility.cs | 2 +- .../Rules/YamlCodeBlockRule.cs | 2 +- .../BuildRestApiDocument.cs | 2 +- src/Docfx.Build.RestApi/Swagger/InfoObject.cs | 2 +- .../Swagger/Internals/SwaggerArray.cs | 2 +- .../Swagger/Internals/SwaggerObject.cs | 2 +- .../Swagger/OperationObject.cs | 2 +- .../Swagger/ParameterObject.cs | 2 +- .../Swagger/PathItemObject.cs | 2 +- .../Swagger/ResponseObject.cs | 2 +- .../Swagger/SwaggerModel.cs | 2 +- .../Swagger/TagItemObject.cs | 2 +- .../SwaggerModelConverter.cs | 4 +- .../Models/DocumentSchema.cs | 2 +- .../Models/JsonPointer.cs | 4 +- .../Processors/Helper.cs | 4 +- .../Processors/ProcessContext.cs | 14 +- .../Processors/XrefInterpreter.cs | 2 +- .../Processors/XrefPropertiesInterpreter.cs | 2 +- .../ValidateFragmentsHandler.cs | 2 +- .../SplitRestApiToTagLevel.cs | 6 +- .../BuildOutputs/ApiBuildOutput.cs | 2 +- .../ApiExceptionInfoBuildOutput.cs | 2 +- .../ApiInheritanceTreeBuildOutput.cs | 2 +- .../BuildOutputs/ApiNames.cs | 2 +- .../BuildOutputs/ApiParameterBuildOutput.cs | 2 +- .../BuildOutputs/ApiSyntaxBuildOutput.cs | 2 +- .../ModelConverter.cs | 6 +- src/Docfx.Build/CompilePhaseHandler.cs | 2 +- src/Docfx.Build/DocumentBuildContext.cs | 4 +- src/Docfx.Build/DocumentBuilder.cs | 2 +- src/Docfx.Build/FileCollection.cs | 2 +- src/Docfx.Build/HostService.cs | 4 +- src/Docfx.Build/LinkPhaseHandler.cs | 2 +- src/Docfx.Build/ManifestProcessor.cs | 2 +- src/Docfx.Build/MarkupResultUtility.cs | 2 +- .../PostProcessors/HtmlPostProcessor.cs | 2 +- .../PostProcessors/ValidateBookmark.cs | 2 +- .../LocalFileResourceReader.cs | 2 +- src/Docfx.Build/SingleDocumentBuilder.cs | 12 +- .../TableOfContents/BuildTocDocument.cs | 2 +- .../TableOfContents/MarkdownTocReader.cs | 4 +- .../TableOfContents/TocResolver.cs | 2 +- .../TableOfContents/TocRestructureUtility.cs | 6 +- .../TemplateModelTransformer.cs | 4 +- src/Docfx.Build/XRefMaps/XRefArchive.cs | 4 +- src/Docfx.Build/XRefMaps/XRefCollection.cs | 4 +- src/Docfx.Build/XRefMaps/XRefMap.cs | 2 +- src/Docfx.Common/CompositeDictionary.cs | 2 +- .../FileAbstractLayer/EmptyFileReader.cs | 2 +- src/Docfx.Common/FileMapping.cs | 2 +- .../NewtonsoftJson/ConvertToObjectHelper.cs | 4 +- .../Loggers/CompositeLogListener.cs | 2 +- .../ResourcePools/ResourcePoolManager.cs | 2 +- .../ExternalReferencePackageReader.cs | 2 +- .../ReferenceViewModel.cs | 10 +- .../TocItemViewModel.cs | 2 +- .../RestApiItemViewModelBase.cs | 2 +- .../RestApiParameterViewModel.cs | 2 +- .../RestApiResponseViewModel.cs | 2 +- .../RestApiTagViewModel.cs | 2 +- .../ApiParameter.cs | 2 +- .../ArgumentInfo.cs | 2 +- .../AttributeInfo.cs | 2 +- .../ExceptionInfo.cs | 2 +- .../InheritanceTree.cs | 2 +- .../ItemViewModel.cs | 40 ++--- .../LinkInfo.cs | 2 +- .../NamedArgumentInfo.cs | 2 +- .../PageViewModel.cs | 6 +- .../SyntaxDetailViewModel.cs | 4 +- src/Docfx.Dotnet/DotnetApiCatalog.Compile.cs | 6 +- .../DotnetApiCatalog.ManagedReference.cs | 10 +- src/Docfx.Dotnet/DotnetApiCatalog.Toc.cs | 6 +- .../Filters/AttributeFilterInfo.cs | 2 +- src/Docfx.Dotnet/Filters/ConfigFilterRule.cs | 4 +- .../ManagedReference/Models/ItemViewModel.cs | 8 +- .../ManagedReference/Models/PageViewModel.cs | 6 +- .../Models/SyntaxDetailViewModel.cs | 2 +- .../Resolvers/ResolveReference.cs | 2 +- .../Resolvers/SetDerivedClass.cs | 4 +- .../Resolvers/YamlMetadataResolver.cs | 20 +-- .../Visitors/SymbolVisitorAdapter.cs | 54 +++---- .../TypeGenericParameterNameVisitor.cs | 2 +- .../Visitors/YamlModelGenerator.cs | 30 ++-- src/Docfx.Dotnet/Parsers/XHtmlWriter.cs | 2 +- .../SymbolUrlResolver.SourceLink.cs | 2 +- src/Docfx.Dotnet/YamlViewModelExtensions.cs | 4 +- src/Docfx.Glob/FileGlob.cs | 4 +- src/Docfx.Glob/GlobMatcher.cs | 18 +-- .../CodeSnippet/HtmlCodeSnippetRenderer.cs | 22 +-- .../TabGroup/ActiveAndVisibleRewriter.cs | 2 +- src/Docfx.Plugins/FileModel.cs | 4 +- src/Docfx.Plugins/GroupInfo.cs | 2 +- src/Docfx.Plugins/Manifest.cs | 2 +- src/Docfx.Plugins/ManifestGroupInfo.cs | 2 +- src/Docfx.Plugins/ManifestItem.cs | 4 +- src/Docfx.Plugins/OutputFileInfo.cs | 2 +- src/Docfx.Plugins/TreeItem.cs | 2 +- src/Docfx.Plugins/XRefSpec.cs | 2 +- .../EmitGenericCollectionNodeDeserializer.cs | 6 +- .../EmitGenericDictionaryNodeDeserializer.cs | 6 +- .../DefaultEmitObjectFactory.cs | 2 +- .../FullObjectGraphTraversalStrategy.cs | 6 +- .../TypeInspectors/EmitTypeInspector.cs | 4 +- .../YamlDeserializer.cs | 12 +- src/docfx/Models/BuildCommand.cs | 4 +- src/docfx/Models/TemplateCommand.cs | 2 +- .../MarkdownReaderTest.cs | 2 +- .../ModelAttributeHandlerTest.cs | 20 +-- .../OverwriteDocumentModelCreatorTest.cs | 35 ++--- .../SplitRestApiToOperationLevelTest.cs | 2 +- .../SchemaFragmentsIteratorTest.cs | 2 +- .../ConceptualDocumentProcessorTest.cs | 2 +- test/Docfx.Build.Tests/DocumentBuilderTest.cs | 82 +++++----- .../DocumentProcessors/YamlDocumentModel.cs | 4 +- .../FileMetadataHelperTest.cs | 58 ++++--- .../JintProcessorHelperTest.cs | 2 +- .../TemplateProcessorUnitTest.cs | 2 +- .../TocDocumentProcessorTest.cs | 142 +++++++++--------- test/Docfx.Build.Tests/TocRestructureTest.cs | 8 +- .../XRefMapSerializationTest.cs | 12 +- ...UniversalReferenceDocumentProcessorTest.cs | 2 +- .../CompositeDictionaryTest.cs | 6 +- .../ConvertToObjectHelperTest.cs | 8 +- test/Docfx.Common.Tests/PathUtilityTest.cs | 6 +- .../YamlSerializationTest.cs | 8 +- test/Docfx.Dotnet.Tests/ApiFilterUnitTest.cs | 2 +- .../GenerateMetadataFromCSUnitTest.cs | 2 +- .../GenerateMetadataFromVBUnitTest.cs | 2 +- .../TestUtility.cs | 6 +- .../TestUtility/TestLoggerListener.cs | 2 +- test/Docfx.Tests.Common/TestBase.cs | 2 +- test/Docfx.Tests.Common/TestListenerScope.cs | 2 +- test/Docfx.Tests.Common/TestLoggerListener.cs | 2 +- 157 files changed, 516 insertions(+), 516 deletions(-) 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 collection) diff --git a/src/Docfx.Build.ManagedReference/BuildOutputs/ApiBuildOutput.cs b/src/Docfx.Build.ManagedReference/BuildOutputs/ApiBuildOutput.cs index d3087ea9a83..989e40db3f4 100644 --- a/src/Docfx.Build.ManagedReference/BuildOutputs/ApiBuildOutput.cs +++ b/src/Docfx.Build.ManagedReference/BuildOutputs/ApiBuildOutput.cs @@ -184,7 +184,7 @@ public class ApiBuildOutput [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; public static ApiBuildOutput FromModel(PageViewModel model) { diff --git a/src/Docfx.Build.ManagedReference/BuildOutputs/ApiReferenceBuildOutput.cs b/src/Docfx.Build.ManagedReference/BuildOutputs/ApiReferenceBuildOutput.cs index 487ea9af900..dda51eaf027 100644 --- a/src/Docfx.Build.ManagedReference/BuildOutputs/ApiReferenceBuildOutput.cs +++ b/src/Docfx.Build.ManagedReference/BuildOutputs/ApiReferenceBuildOutput.cs @@ -174,7 +174,7 @@ public class ApiReferenceBuildOutput [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] [System.Text.Json.Serialization.JsonPropertyName("__metadata__")] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; [EditorBrowsable(EditorBrowsableState.Never)] [YamlIgnore] diff --git a/src/Docfx.Build.ManagedReference/FillReferenceInformation.cs b/src/Docfx.Build.ManagedReference/FillReferenceInformation.cs index fdb4e53d15a..63356c20225 100644 --- a/src/Docfx.Build.ManagedReference/FillReferenceInformation.cs +++ b/src/Docfx.Build.ManagedReference/FillReferenceInformation.cs @@ -14,7 +14,7 @@ namespace Docfx.Build.ManagedReference; [Export(nameof(ManagedReferenceDocumentProcessor), typeof(IDocumentBuildStep))] public class FillReferenceInformation : BaseDocumentBuildStep { - private readonly Dictionary _items = new(); + private readonly Dictionary _items = []; public override string Name => nameof(FillReferenceInformation); diff --git a/src/Docfx.Build.ManagedReference/MergeManagedReferenceDocument.cs b/src/Docfx.Build.ManagedReference/MergeManagedReferenceDocument.cs index acf4e8e7c7a..6f823e326a6 100644 --- a/src/Docfx.Build.ManagedReference/MergeManagedReferenceDocument.cs +++ b/src/Docfx.Build.ManagedReference/MergeManagedReferenceDocument.cs @@ -176,7 +176,7 @@ private static PageViewModel ConvertToVM(MergeItem mergeItem) { var vm = new PageViewModel { - Items = new List(), + Items = [], References = mergeItem.References?.Values.ToList(), Metadata = mergeItem.Metadata, }; diff --git a/src/Docfx.Build.ManagedReference/SplitClassPageToMemberLevel.cs b/src/Docfx.Build.ManagedReference/SplitClassPageToMemberLevel.cs index 73349a07201..934c312bcdd 100644 --- a/src/Docfx.Build.ManagedReference/SplitClassPageToMemberLevel.cs +++ b/src/Docfx.Build.ManagedReference/SplitClassPageToMemberLevel.cs @@ -21,8 +21,8 @@ public class SplitClassPageToMemberLevel : BaseDocumentBuildStep private const string SplitFromPropertyName = "_splitFrom"; private const string IsOverloadPropertyName = "_isOverload"; private const int MaximumFileNameLength = 180; - private static readonly List EmptyList = new(); - private static readonly string[] EmptyArray = Array.Empty(); + private static readonly List EmptyList = []; + private static readonly string[] EmptyArray = []; public override string Name => nameof(SplitClassPageToMemberLevel); @@ -95,7 +95,7 @@ private static void RenewDupeFileModels(FileModel dupeModel, Dictionary { }); + var newModel = GenerateNewFileModel(dupeModel, page, Path.GetFileNameWithoutExtension(newFilePath), []); modelsDict[newFilePath] = newModel; } @@ -180,7 +180,7 @@ private SplittedResult SplitModelToOverloadLevel(FileModel model, Dictionary { primaryItem }; + page.Items = [primaryItem]; page.Metadata[SplitReferencePropertyName] = true; page.Metadata[SplitFromPropertyName] = true; @@ -210,7 +210,7 @@ private static IEnumerable GetNewPages(PageViewModel page) { foreach (var item in overload) { - yield return ExtractPageViewModel(page, new List { item }); + yield return ExtractPageViewModel(page, [item]); } } else @@ -296,7 +296,7 @@ private static List GetVersionFromMetadata(object value) { if (value is string text) { - return new List { text }; + return [text]; } return GetListFromObject(value); diff --git a/src/Docfx.Build.OperationLevelRestApi/SplitRestApiToOperationLevel.cs b/src/Docfx.Build.OperationLevelRestApi/SplitRestApiToOperationLevel.cs index b108f10f8cb..6d520c7b5a7 100644 --- a/src/Docfx.Build.OperationLevelRestApi/SplitRestApiToOperationLevel.cs +++ b/src/Docfx.Build.OperationLevelRestApi/SplitRestApiToOperationLevel.cs @@ -77,9 +77,9 @@ private static Tuple, List> SplitModelToOpe } // Reset children - content.Children = new List(); + content.Children = []; content.Metadata["_isSplittedByOperation"] = true; - content.Tags = new List(); + content.Tags = []; model.Content = content; // Reset uid definition @@ -123,8 +123,8 @@ private static IEnumerable GenerateOperationModels(Res Summary = child.Summary, Remarks = child.Remarks, Documentation = child.Documentation, - Children = new List { child }, - Tags = new List(), + Children = [child], + Tags = [], Metadata = MergeChildMetadata(root, child) }; @@ -139,7 +139,7 @@ private static IEnumerable GenerateOperationModels(Res child.Description = null; child.Summary = null; child.Remarks = null; - child.Tags = new List(); + child.Tags = []; yield return model; } diff --git a/src/Docfx.Build.OverwriteDocuments/MarkdownFragmentsCreator.cs b/src/Docfx.Build.OverwriteDocuments/MarkdownFragmentsCreator.cs index 34a8c202ecc..0eebf55cdd9 100644 --- a/src/Docfx.Build.OverwriteDocuments/MarkdownFragmentsCreator.cs +++ b/src/Docfx.Build.OverwriteDocuments/MarkdownFragmentsCreator.cs @@ -69,7 +69,7 @@ private List PropertySection() { PropertyName = key, PropertyNameSource = Next(), - PropertyValue = new List(), + PropertyValue = [], }; Block block; while ((block = Peek()) != null && !_inlineCodeHeadingRule.Parse(block, out var _)) diff --git a/src/Docfx.Build.OverwriteDocuments/OverwriteDocumentModelCreator.cs b/src/Docfx.Build.OverwriteDocuments/OverwriteDocumentModelCreator.cs index 5a9f3f2af30..2d4bc3a3fa7 100644 --- a/src/Docfx.Build.OverwriteDocuments/OverwriteDocumentModelCreator.cs +++ b/src/Docfx.Build.OverwriteDocuments/OverwriteDocumentModelCreator.cs @@ -37,7 +37,7 @@ internal static Dictionary ConvertYamlCodeBlock(string yamlCodeB { if (string.IsNullOrEmpty(yamlCodeBlock) || yamlCodeBlockSource == null) { - return new Dictionary(); + return []; } using var reader = new StringReader(yamlCodeBlock); @@ -202,7 +202,7 @@ private MarkdownDocument CreateDocument(MarkdownPropertyModel model) private static Dictionary CreateDictionaryObject() { - return new Dictionary(); + return []; } private static List CreateDictionaryArrayObject(OPathSegment segment) diff --git a/src/Docfx.Build.OverwriteDocuments/OverwriteUtility.cs b/src/Docfx.Build.OverwriteDocuments/OverwriteUtility.cs index 2dc08df726d..04744dd0e43 100644 --- a/src/Docfx.Build.OverwriteDocuments/OverwriteUtility.cs +++ b/src/Docfx.Build.OverwriteDocuments/OverwriteUtility.cs @@ -79,7 +79,7 @@ public static void AddOrUpdateFragmentEntity(this Dictionary(), + Properties = [], Metadata = metadata }; fragments.Add(uid, value); diff --git a/src/Docfx.Build.OverwriteDocuments/Rules/YamlCodeBlockRule.cs b/src/Docfx.Build.OverwriteDocuments/Rules/YamlCodeBlockRule.cs index 08f1c03e0c0..e8fef8289cf 100644 --- a/src/Docfx.Build.OverwriteDocuments/Rules/YamlCodeBlockRule.cs +++ b/src/Docfx.Build.OverwriteDocuments/Rules/YamlCodeBlockRule.cs @@ -10,7 +10,7 @@ public sealed class YamlCodeBlockRule : IOverwriteBlockRule { public string TokenName => "YamlCodeBlock"; - private static readonly List _allowedLanguages = new() { "yaml", "yml" }; + private static readonly List _allowedLanguages = ["yaml", "yml"]; public bool Parse(Block block, out string value) { diff --git a/src/Docfx.Build.RestApi/BuildRestApiDocument.cs b/src/Docfx.Build.RestApi/BuildRestApiDocument.cs index 621072c8990..8e2b79feafb 100644 --- a/src/Docfx.Build.RestApi/BuildRestApiDocument.cs +++ b/src/Docfx.Build.RestApi/BuildRestApiDocument.cs @@ -15,7 +15,7 @@ namespace Docfx.Build.RestApi; [Export(nameof(RestApiDocumentProcessor), typeof(IDocumentBuildStep))] public class BuildRestApiDocument : BuildReferenceDocumentBase { - private static readonly HashSet MarkupKeys = new() { "description" }; + private static readonly HashSet MarkupKeys = ["description"]; public override string Name => nameof(BuildRestApiDocument); diff --git a/src/Docfx.Build.RestApi/Swagger/InfoObject.cs b/src/Docfx.Build.RestApi/Swagger/InfoObject.cs index f599720bf85..5248b10b8e0 100644 --- a/src/Docfx.Build.RestApi/Swagger/InfoObject.cs +++ b/src/Docfx.Build.RestApi/Swagger/InfoObject.cs @@ -32,5 +32,5 @@ public class InfoObject [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary PatternedObjects { get; set; } = new(); + public Dictionary PatternedObjects { get; set; } = []; } diff --git a/src/Docfx.Build.RestApi/Swagger/Internals/SwaggerArray.cs b/src/Docfx.Build.RestApi/Swagger/Internals/SwaggerArray.cs index 6219f6b225d..087513a2e3c 100644 --- a/src/Docfx.Build.RestApi/Swagger/Internals/SwaggerArray.cs +++ b/src/Docfx.Build.RestApi/Swagger/Internals/SwaggerArray.cs @@ -7,7 +7,7 @@ internal class SwaggerArray : SwaggerObjectBase { public override SwaggerObjectType ObjectType => SwaggerObjectType.Array; - public List Array { get; set; } = new(); + public List Array { get; set; } = []; public override SwaggerObjectBase Clone() { diff --git a/src/Docfx.Build.RestApi/Swagger/Internals/SwaggerObject.cs b/src/Docfx.Build.RestApi/Swagger/Internals/SwaggerObject.cs index 397971ea2ce..58fabf90f16 100644 --- a/src/Docfx.Build.RestApi/Swagger/Internals/SwaggerObject.cs +++ b/src/Docfx.Build.RestApi/Swagger/Internals/SwaggerObject.cs @@ -7,7 +7,7 @@ internal class SwaggerObject : SwaggerObjectBase { public override SwaggerObjectType ObjectType => SwaggerObjectType.Object; - public Dictionary Dictionary { get; set; } = new(); + public Dictionary Dictionary { get; set; } = []; public override SwaggerObjectBase Clone() { diff --git a/src/Docfx.Build.RestApi/Swagger/OperationObject.cs b/src/Docfx.Build.RestApi/Swagger/OperationObject.cs index 070d2bc56ca..060977a85ab 100644 --- a/src/Docfx.Build.RestApi/Swagger/OperationObject.cs +++ b/src/Docfx.Build.RestApi/Swagger/OperationObject.cs @@ -49,5 +49,5 @@ public class OperationObject [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.Build.RestApi/Swagger/ParameterObject.cs b/src/Docfx.Build.RestApi/Swagger/ParameterObject.cs index b09e5759b01..3e547b8d9b7 100644 --- a/src/Docfx.Build.RestApi/Swagger/ParameterObject.cs +++ b/src/Docfx.Build.RestApi/Swagger/ParameterObject.cs @@ -23,5 +23,5 @@ public class ParameterObject [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.Build.RestApi/Swagger/PathItemObject.cs b/src/Docfx.Build.RestApi/Swagger/PathItemObject.cs index 6071499c396..d50da2c9583 100644 --- a/src/Docfx.Build.RestApi/Swagger/PathItemObject.cs +++ b/src/Docfx.Build.RestApi/Swagger/PathItemObject.cs @@ -25,5 +25,5 @@ public class PathItemObject [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.Build.RestApi/Swagger/ResponseObject.cs b/src/Docfx.Build.RestApi/Swagger/ResponseObject.cs index fd098a1a225..a4affc6a5b9 100644 --- a/src/Docfx.Build.RestApi/Swagger/ResponseObject.cs +++ b/src/Docfx.Build.RestApi/Swagger/ResponseObject.cs @@ -31,5 +31,5 @@ public class ResponseObject [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.Build.RestApi/Swagger/SwaggerModel.cs b/src/Docfx.Build.RestApi/Swagger/SwaggerModel.cs index fa68585d5a8..f4359c2829c 100644 --- a/src/Docfx.Build.RestApi/Swagger/SwaggerModel.cs +++ b/src/Docfx.Build.RestApi/Swagger/SwaggerModel.cs @@ -95,5 +95,5 @@ public class SwaggerModel [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.Build.RestApi/Swagger/TagItemObject.cs b/src/Docfx.Build.RestApi/Swagger/TagItemObject.cs index f632850f081..ba48519bc88 100644 --- a/src/Docfx.Build.RestApi/Swagger/TagItemObject.cs +++ b/src/Docfx.Build.RestApi/Swagger/TagItemObject.cs @@ -37,5 +37,5 @@ public class TagItemObject [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.Build.RestApi/SwaggerModelConverter.cs b/src/Docfx.Build.RestApi/SwaggerModelConverter.cs index 72d25d62495..9a83e692a9b 100644 --- a/src/Docfx.Build.RestApi/SwaggerModelConverter.cs +++ b/src/Docfx.Build.RestApi/SwaggerModelConverter.cs @@ -25,9 +25,9 @@ public static RestApiRootItemViewModel FromSwaggerModel(SwaggerModel swagger) Metadata = swagger.Metadata, Description = swagger.Description, Summary = swagger.Summary, - Children = new List(), + Children = [], Raw = swagger.Raw, - Tags = new List() + Tags = [] }; if (swagger.Tags != null) { diff --git a/src/Docfx.Build.SchemaDriven/Models/DocumentSchema.cs b/src/Docfx.Build.SchemaDriven/Models/DocumentSchema.cs index 3dfa1ad58c3..6a9422ed41b 100644 --- a/src/Docfx.Build.SchemaDriven/Models/DocumentSchema.cs +++ b/src/Docfx.Build.SchemaDriven/Models/DocumentSchema.cs @@ -142,7 +142,7 @@ BaseSchema ResolveRefCore(BaseSchema schema) private static bool CheckOverwriteAbility(BaseSchema schema) { - return CheckOverwriteAbilityCore(schema, new Dictionary()); + return CheckOverwriteAbilityCore(schema, []); } private static bool CheckOverwriteAbilityCore(BaseSchema schema, Dictionary cache) diff --git a/src/Docfx.Build.SchemaDriven/Models/JsonPointer.cs b/src/Docfx.Build.SchemaDriven/Models/JsonPointer.cs index ea62b760e06..fca8be66e26 100644 --- a/src/Docfx.Build.SchemaDriven/Models/JsonPointer.cs +++ b/src/Docfx.Build.SchemaDriven/Models/JsonPointer.cs @@ -24,7 +24,7 @@ public JsonPointer(string raw) throw new InvalidJsonPointerException($"Invalid json pointer \"{raw}\""); } - _parts = _isRoot ? Array.Empty() : raw.Substring(1).Split(Splitter[0]); + _parts = _isRoot ? [] : raw.Substring(1).Split(Splitter[0]); _raw = raw; } @@ -32,7 +32,7 @@ public JsonPointer(string raw) public JsonPointer(string[] parts) { _isRoot = parts == null || parts.Length == 0; - _parts = parts ?? Array.Empty(); + _parts = parts ?? []; _raw = Splitter + string.Join(Splitter, parts); } diff --git a/src/Docfx.Build.SchemaDriven/Processors/Helper.cs b/src/Docfx.Build.SchemaDriven/Processors/Helper.cs index 400c17da3b5..6c0e3e3d2b5 100644 --- a/src/Docfx.Build.SchemaDriven/Processors/Helper.cs +++ b/src/Docfx.Build.SchemaDriven/Processors/Helper.cs @@ -21,7 +21,7 @@ public static void AddFileLinkSource(this Dictionary sources)) { - sources = new List(); + sources = []; fileLinkSources[file] = sources; } sources.Add(source); @@ -31,7 +31,7 @@ public static void SetOriginalContentFile(this IProcessContext context, string p { if (!context.PathProperties.TryGetValue(path, out var properties)) { - properties = context.PathProperties[path] = new Dictionary(); + properties = context.PathProperties[path] = []; } properties[ContentOriginalFileKeyName] = file; diff --git a/src/Docfx.Build.SchemaDriven/Processors/ProcessContext.cs b/src/Docfx.Build.SchemaDriven/Processors/ProcessContext.cs index 4fe3d6bc2fd..3d9054ede99 100644 --- a/src/Docfx.Build.SchemaDriven/Processors/ProcessContext.cs +++ b/src/Docfx.Build.SchemaDriven/Processors/ProcessContext.cs @@ -51,12 +51,12 @@ public ProcessContext(IHostService hs, FileModel fm, IDocumentBuildContext bc, M _model = fm; OriginalFileAndType = fm.OriginalFileAndType; FileAndType = fm.FileAndType; - Uids = new List(); - UidLinkSources = new Dictionary>(); - FileLinkSources = new Dictionary>(); - Dependency = new HashSet(); - XRefSpecs = new List(); - ExternalXRefSpecs = new List(); + Uids = []; + UidLinkSources = []; + FileLinkSources = []; + Dependency = []; + XRefSpecs = []; + ExternalXRefSpecs = []; Metadata = new Dictionary(); if (((IDictionary)fm.Properties).TryGetValue("PathProperties", out var properties)) { @@ -65,7 +65,7 @@ public ProcessContext(IHostService hs, FileModel fm, IDocumentBuildContext bc, M } else { - fm.Properties.PathProperties = PathProperties = new Dictionary>(); + fm.Properties.PathProperties = PathProperties = []; } Host = hs; diff --git a/src/Docfx.Build.SchemaDriven/Processors/XrefInterpreter.cs b/src/Docfx.Build.SchemaDriven/Processors/XrefInterpreter.cs index a61b9d6f7f2..f2fe10dc811 100644 --- a/src/Docfx.Build.SchemaDriven/Processors/XrefInterpreter.cs +++ b/src/Docfx.Build.SchemaDriven/Processors/XrefInterpreter.cs @@ -61,7 +61,7 @@ private static void AddUidLinkSource(Dictionary> ui var file = source.Target; if (!uidLinkSources.TryGetValue(file, out List sources)) { - sources = new List(); + sources = []; uidLinkSources[file] = sources; } sources.Add(source); diff --git a/src/Docfx.Build.SchemaDriven/Processors/XrefPropertiesInterpreter.cs b/src/Docfx.Build.SchemaDriven/Processors/XrefPropertiesInterpreter.cs index a6df05fedd5..a101c6bb28f 100644 --- a/src/Docfx.Build.SchemaDriven/Processors/XrefPropertiesInterpreter.cs +++ b/src/Docfx.Build.SchemaDriven/Processors/XrefPropertiesInterpreter.cs @@ -62,7 +62,7 @@ public object Interpret(BaseSchema schema, object value, IProcessContext context Uid = uid }; - var parts = schema.XrefProperties ?? new List { "name", "fullName" }; + var parts = schema.XrefProperties ?? ["name", "fullName"]; var root = context.GetModel(); foreach (var part in parts.Distinct()) { diff --git a/src/Docfx.Build.SchemaDriven/ValidateFragmentsHandler.cs b/src/Docfx.Build.SchemaDriven/ValidateFragmentsHandler.cs index 4d4aa003a70..0a8ff8d107b 100644 --- a/src/Docfx.Build.SchemaDriven/ValidateFragmentsHandler.cs +++ b/src/Docfx.Build.SchemaDriven/ValidateFragmentsHandler.cs @@ -10,7 +10,7 @@ namespace Docfx.Build.SchemaDriven; public class ValidateFragmentsHandler : ISchemaFragmentsHandler { - private readonly Dictionary _isMissingUidsLogged = new(); + private readonly Dictionary _isMissingUidsLogged = []; public void HandleUid(string uidKey, YamlMappingNode node, Dictionary fragments, BaseSchema schema, string oPathPrefix, string uid) { diff --git a/src/Docfx.Build.TagLevelRestApi/SplitRestApiToTagLevel.cs b/src/Docfx.Build.TagLevelRestApi/SplitRestApiToTagLevel.cs index dacd4b03c3a..021a9aabac4 100644 --- a/src/Docfx.Build.TagLevelRestApi/SplitRestApiToTagLevel.cs +++ b/src/Docfx.Build.TagLevelRestApi/SplitRestApiToTagLevel.cs @@ -82,7 +82,7 @@ private static Tuple, TreeItemRestructure> SplitModelToOperation // Only keep not tagged children in root model var groupedUids = splittedModels.SelectMany(m => m.Uids).Select(u => u.Name).ToList(); - content.Tags = new List(); + content.Tags = []; content.Children = content.Children.Where(child => !groupedUids.Contains(child.Uid)).ToList(); content.Metadata["_isSplittedByTag"] = true; model.Content = content; @@ -118,7 +118,7 @@ private static IEnumerable GenerateTagModels(RestApiRo Description = tag.Description, Documentation = tag.Documentation, Children = tagChildren, - Tags = new List(), + Tags = [], Metadata = MergeTagMetadata(root, tag) }; } @@ -131,7 +131,7 @@ private static IEnumerable GetChildrenByTag(RestApiRo var children = root.Children.Where(child => child.Tags != null && tagName == child.Tags.FirstOrDefault()); foreach (var child in children) { - child.Tags = new List(); + child.Tags = []; yield return child; } } diff --git a/src/Docfx.Build.UniversalReference/BuildOutputs/ApiBuildOutput.cs b/src/Docfx.Build.UniversalReference/BuildOutputs/ApiBuildOutput.cs index f5284e1a38d..58a24f7b476 100644 --- a/src/Docfx.Build.UniversalReference/BuildOutputs/ApiBuildOutput.cs +++ b/src/Docfx.Build.UniversalReference/BuildOutputs/ApiBuildOutput.cs @@ -175,5 +175,5 @@ public class ApiBuildOutput [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.Build.UniversalReference/BuildOutputs/ApiExceptionInfoBuildOutput.cs b/src/Docfx.Build.UniversalReference/BuildOutputs/ApiExceptionInfoBuildOutput.cs index d9963944c0f..f20e4133064 100644 --- a/src/Docfx.Build.UniversalReference/BuildOutputs/ApiExceptionInfoBuildOutput.cs +++ b/src/Docfx.Build.UniversalReference/BuildOutputs/ApiExceptionInfoBuildOutput.cs @@ -24,5 +24,5 @@ public class ApiExceptionInfoBuildOutput [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.Build.UniversalReference/BuildOutputs/ApiInheritanceTreeBuildOutput.cs b/src/Docfx.Build.UniversalReference/BuildOutputs/ApiInheritanceTreeBuildOutput.cs index 17666ce6e3f..eb063276c24 100644 --- a/src/Docfx.Build.UniversalReference/BuildOutputs/ApiInheritanceTreeBuildOutput.cs +++ b/src/Docfx.Build.UniversalReference/BuildOutputs/ApiInheritanceTreeBuildOutput.cs @@ -30,5 +30,5 @@ public class ApiInheritanceTreeBuildOutput [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.Build.UniversalReference/BuildOutputs/ApiNames.cs b/src/Docfx.Build.UniversalReference/BuildOutputs/ApiNames.cs index 687702098cc..eaf537642ba 100644 --- a/src/Docfx.Build.UniversalReference/BuildOutputs/ApiNames.cs +++ b/src/Docfx.Build.UniversalReference/BuildOutputs/ApiNames.cs @@ -45,5 +45,5 @@ public class ApiNames [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.Build.UniversalReference/BuildOutputs/ApiParameterBuildOutput.cs b/src/Docfx.Build.UniversalReference/BuildOutputs/ApiParameterBuildOutput.cs index f9e9419457b..56f95c95805 100644 --- a/src/Docfx.Build.UniversalReference/BuildOutputs/ApiParameterBuildOutput.cs +++ b/src/Docfx.Build.UniversalReference/BuildOutputs/ApiParameterBuildOutput.cs @@ -39,5 +39,5 @@ public class ApiParameterBuildOutput [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.Build.UniversalReference/BuildOutputs/ApiSyntaxBuildOutput.cs b/src/Docfx.Build.UniversalReference/BuildOutputs/ApiSyntaxBuildOutput.cs index 70490d78d8c..901b101b529 100644 --- a/src/Docfx.Build.UniversalReference/BuildOutputs/ApiSyntaxBuildOutput.cs +++ b/src/Docfx.Build.UniversalReference/BuildOutputs/ApiSyntaxBuildOutput.cs @@ -35,5 +35,5 @@ public class ApiSyntaxBuildOutput [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.Build.UniversalReference/ModelConverter.cs b/src/Docfx.Build.UniversalReference/ModelConverter.cs index e0bbd94a4e8..9d09fc18c52 100644 --- a/src/Docfx.Build.UniversalReference/ModelConverter.cs +++ b/src/Docfx.Build.UniversalReference/ModelConverter.cs @@ -31,7 +31,7 @@ public static ApiBuildOutput ToApiBuildOutput(PageViewModel model) Dictionary references = null; if (model.References != null) { - references = new Dictionary(); + references = []; foreach (var reference in model.References .Where(r => !string.IsNullOrEmpty(r.Uid)) .Select(ToReferenceApiNames)) @@ -44,7 +44,7 @@ public static ApiBuildOutput ToApiBuildOutput(PageViewModel model) var childUids = model.Items[0].Children ?? Enumerable.Empty() .Concat(model.Items[0].ChildrenInDevLangs != null ? model.Items[0].ChildrenInDevLangs.SelectMany(kv => kv.Value) - : Enumerable.Empty()) + : []) .Distinct(); var children = new Dictionary(); if (model.References != null) @@ -388,7 +388,7 @@ public static List> ToApiListInDevLangs(T defaultValu } var result = new List>(); - values ??= new SortedList(); + values ??= []; foreach (var language in supportedLanguages) { result.Add(new ApiLanguageValuePair diff --git a/src/Docfx.Build/CompilePhaseHandler.cs b/src/Docfx.Build/CompilePhaseHandler.cs index 71da01dbaf2..e766f87abb9 100644 --- a/src/Docfx.Build/CompilePhaseHandler.cs +++ b/src/Docfx.Build/CompilePhaseHandler.cs @@ -10,7 +10,7 @@ namespace Docfx.Build.Engine; internal class CompilePhaseHandler { - private readonly List _restructions = new(); + private readonly List _restructions = []; public DocumentBuildContext Context { get; } diff --git a/src/Docfx.Build/DocumentBuildContext.cs b/src/Docfx.Build/DocumentBuildContext.cs index 9f8e0ac58f0..f38bedb442d 100644 --- a/src/Docfx.Build/DocumentBuildContext.cs +++ b/src/Docfx.Build/DocumentBuildContext.cs @@ -126,7 +126,7 @@ from u in xrefMaps public ConcurrentDictionary> TocMap { get; } = new(FilePathComparer.OSPlatformSensitiveStringComparer); - public HashSet XRef { get; } = new(); + public HashSet XRef { get; } = []; public string RootTocPath { get; } @@ -136,7 +136,7 @@ from u in xrefMaps public CancellationToken CancellationToken { get; } = CancellationToken.None; - internal ConcurrentBag ManifestItems { get; } = new(); + internal ConcurrentBag ManifestItems { get; } = []; private ConcurrentDictionary ExternalXRefSpec { get; } = new(); diff --git a/src/Docfx.Build/DocumentBuilder.cs b/src/Docfx.Build/DocumentBuilder.cs index 6b9c3f72813..a36b2727b43 100644 --- a/src/Docfx.Build/DocumentBuilder.cs +++ b/src/Docfx.Build/DocumentBuilder.cs @@ -27,7 +27,7 @@ public class DocumentBuilder : IDisposable public DocumentBuilder(IEnumerable assemblies, ImmutableArray postProcessorNames) { Logger.LogVerbose("Loading plug-ins and post-processors..."); - var assemblyList = assemblies?.ToList() ?? new List(); + var assemblyList = assemblies?.ToList() ?? []; assemblyList.Add(typeof(DocumentBuilder).Assembly); _container = CompositionContainer.GetContainer(assemblyList); _container.SatisfyImports(this); diff --git a/src/Docfx.Build/FileCollection.cs b/src/Docfx.Build/FileCollection.cs index 48b557d0ee3..d330383a373 100644 --- a/src/Docfx.Build/FileCollection.cs +++ b/src/Docfx.Build/FileCollection.cs @@ -8,7 +8,7 @@ namespace Docfx.Build.Engine; public class FileCollection { - private readonly List _files = new(); + private readonly List _files = []; public int Count => _files.Count; diff --git a/src/Docfx.Build/HostService.cs b/src/Docfx.Build/HostService.cs index f71caf153f9..409baa2dd11 100644 --- a/src/Docfx.Build/HostService.cs +++ b/src/Docfx.Build/HostService.cs @@ -12,7 +12,7 @@ namespace Docfx.Build.Engine; [Export(typeof(IHostService))] class HostService : IHostService { - private Dictionary> _uidIndex = new(); + private Dictionary> _uidIndex = []; public TemplateProcessor Template { get; set; } @@ -65,7 +65,7 @@ public ImmutableList LookupByUid(string uid) { return result.ToImmutableList(); } - return ImmutableList.Empty; + return []; } public MarkupResult Markup(string markdown, FileAndType ft) diff --git a/src/Docfx.Build/LinkPhaseHandler.cs b/src/Docfx.Build/LinkPhaseHandler.cs index 5957e92252d..519c5746b73 100644 --- a/src/Docfx.Build/LinkPhaseHandler.cs +++ b/src/Docfx.Build/LinkPhaseHandler.cs @@ -35,7 +35,7 @@ public void Handle(List hostServices, int maxParallelism) private void Save(List hostServices, int maxParallelism) { - _manifestWithContext = new List(); + _manifestWithContext = []; foreach (var hostService in hostServices) { _manifestWithContext.AddRange(ExportManifest(hostService)); diff --git a/src/Docfx.Build/ManifestProcessor.cs b/src/Docfx.Build/ManifestProcessor.cs index e135b74a317..37e60352b6f 100644 --- a/src/Docfx.Build/ManifestProcessor.cs +++ b/src/Docfx.Build/ManifestProcessor.cs @@ -29,7 +29,7 @@ public ManifestProcessor(List manifestWithContext, Docu // E.g. we can set TOC model to be globally shared by every data model // Make sure it is single thread _globalMetadata = _templateProcessor.Tokens?.ToDictionary(pair => pair.Key, pair => (object)pair.Value) - ?? new Dictionary(); + ?? []; } public void Process() diff --git a/src/Docfx.Build/MarkupResultUtility.cs b/src/Docfx.Build/MarkupResultUtility.cs index 53a642c18cb..754c58e4860 100644 --- a/src/Docfx.Build/MarkupResultUtility.cs +++ b/src/Docfx.Build/MarkupResultUtility.cs @@ -109,7 +109,7 @@ where string.Equals(attr.Name, "src", StringComparison.OrdinalIgnoreCase) || if (!fileLinkSources.TryGetValue(file, out List sources)) { - sources = new List(); + sources = []; fileLinkSources[file] = sources; } sources.Add(new LinkSourceInfo diff --git a/src/Docfx.Build/PostProcessors/HtmlPostProcessor.cs b/src/Docfx.Build/PostProcessors/HtmlPostProcessor.cs index a052eaed954..ad06f41dc91 100644 --- a/src/Docfx.Build/PostProcessors/HtmlPostProcessor.cs +++ b/src/Docfx.Build/PostProcessors/HtmlPostProcessor.cs @@ -15,7 +15,7 @@ sealed class HtmlPostProcessor : IPostProcessor { private static readonly UTF8Encoding Utf8EncodingWithoutBom = new(false); - public List Handlers { get; } = new(); + public List Handlers { get; } = []; private bool _handlerInitialized; diff --git a/src/Docfx.Build/PostProcessors/ValidateBookmark.cs b/src/Docfx.Build/PostProcessors/ValidateBookmark.cs index 04199ecbe4a..d3e4d46aabb 100644 --- a/src/Docfx.Build/PostProcessors/ValidateBookmark.cs +++ b/src/Docfx.Build/PostProcessors/ValidateBookmark.cs @@ -12,7 +12,7 @@ namespace Docfx.Build.Engine; sealed class ValidateBookmark : HtmlDocumentHandler { private static readonly string XPathTemplate = "//*/@{0}"; - private static readonly HashSet WhiteList = new() { "top" }; + private static readonly HashSet WhiteList = ["top"]; /// /// bookmarks mapping from output file -> bookmarks /// diff --git a/src/Docfx.Build/ResourceFileReaders/LocalFileResourceReader.cs b/src/Docfx.Build/ResourceFileReaders/LocalFileResourceReader.cs index 9b38e384863..21a7f8b44c4 100644 --- a/src/Docfx.Build/ResourceFileReaders/LocalFileResourceReader.cs +++ b/src/Docfx.Build/ResourceFileReaders/LocalFileResourceReader.cs @@ -48,7 +48,7 @@ private IEnumerable GetFiles(string directory, string searchPattern, int { if (searchLevel < 1) { - return Enumerable.Empty(); + return []; } var files = Directory.GetFiles(directory, searchPattern, SearchOption.TopDirectoryOnly); var dirs = Directory.GetDirectories(directory); diff --git a/src/Docfx.Build/SingleDocumentBuilder.cs b/src/Docfx.Build/SingleDocumentBuilder.cs index f1cf5ee4aa5..0eaa49ce547 100644 --- a/src/Docfx.Build/SingleDocumentBuilder.cs +++ b/src/Docfx.Build/SingleDocumentBuilder.cs @@ -31,8 +31,8 @@ public static ImmutableList Build( processor, parameters.Files.EnumerateFiles()); - new CompilePhaseHandler(null).Handle(new List { hostService }, parameters.MaxParallelism); - new LinkPhaseHandler(null, null).Handle(new List { hostService }, parameters.MaxParallelism); + new CompilePhaseHandler(null).Handle([hostService], parameters.MaxParallelism); + new LinkPhaseHandler(null, null).Handle([hostService], parameters.MaxParallelism); return hostService.Models; } @@ -75,13 +75,13 @@ public Manifest Build(DocumentBuildParameters parameters, IMarkdownService markd Xrefmap = ExportXRefMap(parameters, context), SourceBasePath = StringExtension.ToNormalizedPath(EnvironmentContext.BaseDirectory), }; - manifest.Groups = new List - { + manifest.Groups = + [ new(parameters.GroupInfo) { XRefmap = (string)manifest.Xrefmap } - }; + ]; return manifest; } @@ -103,7 +103,7 @@ from p in (from processor in processors where priority != ProcessingPriority.NotSupported group processor by priority into ps orderby ps.Key descending - select ps.ToList()).FirstOrDefault() ?? new List { null } + select ps.ToList()).FirstOrDefault() ?? [null] group file by p).ToList(); var toHandleItems = files.Where(s => s.Key != null); diff --git a/src/Docfx.Build/TableOfContents/BuildTocDocument.cs b/src/Docfx.Build/TableOfContents/BuildTocDocument.cs index d2c7b63318f..b395e758cd0 100644 --- a/src/Docfx.Build/TableOfContents/BuildTocDocument.cs +++ b/src/Docfx.Build/TableOfContents/BuildTocDocument.cs @@ -84,7 +84,7 @@ void UpdateDependencies(HashSet linkTos, Dictionary> dict, string path, LinkSourceInfo source) - => dict[path] = dict.TryGetValue(path, out var sources) ? sources.Add(source) : ImmutableList.Create(source); + => dict[path] = dict.TryGetValue(path, out var sources) ? sources.Add(source) : [source]; private static LinkSourceInfo GetLinkSourceInfo(string path, string anchor, string source, string includedFrom) { diff --git a/src/Docfx.Build/TableOfContents/MarkdownTocReader.cs b/src/Docfx.Build/TableOfContents/MarkdownTocReader.cs index cbd396e8fbc..db4a3728e6c 100644 --- a/src/Docfx.Build/TableOfContents/MarkdownTocReader.cs +++ b/src/Docfx.Build/TableOfContents/MarkdownTocReader.cs @@ -68,7 +68,7 @@ internal sealed class InitialState : ParseState public InitialState(string filePath) { Parents = new Stack(); - Root = new(); + Root = []; FilePath = filePath; } public override int Level => 0; @@ -144,7 +144,7 @@ protected ParseState ApplyCore(ParseState state, int level, string text, string if (state.Parents.Count > 0) { var parent = state.Parents.Peek(); - parent.Items ??= new(); + parent.Items ??= []; parent.Items.Add(item); } else diff --git a/src/Docfx.Build/TableOfContents/TocResolver.cs b/src/Docfx.Build/TableOfContents/TocResolver.cs index 24cec8aa4d3..9c2f43e4944 100644 --- a/src/Docfx.Build/TableOfContents/TocResolver.cs +++ b/src/Docfx.Build/TableOfContents/TocResolver.cs @@ -11,7 +11,7 @@ namespace Docfx.Build.TableOfContents; class TocResolver { private readonly Dictionary _collection; - private readonly Dictionary _notInProjectTocCache = new(); + private readonly Dictionary _notInProjectTocCache = []; public TocResolver(Dictionary collection) { diff --git a/src/Docfx.Build/TableOfContents/TocRestructureUtility.cs b/src/Docfx.Build/TableOfContents/TocRestructureUtility.cs index 1ce0abf42c4..464b9ea8f67 100644 --- a/src/Docfx.Build/TableOfContents/TocRestructureUtility.cs +++ b/src/Docfx.Build/TableOfContents/TocRestructureUtility.cs @@ -15,7 +15,7 @@ public static void Restructure(TocItemViewModel toc, IList { return; } - RestructureCore(toc, new(), restructures); + RestructureCore(toc, [], restructures); } private static void RestructureCore(TocItemViewModel item, List items, IList restructures) @@ -91,7 +91,7 @@ private static void RestructureItem(TocItemViewModel item, List unresolvedXRefs) { - unresolvedXRefs = new List(); + unresolvedXRefs = []; using (var stream = EnvironmentContext.FileAbstractLayer.Create(destFilePath)) { using var sw = new StreamWriter(stream); @@ -293,7 +293,7 @@ private void TransformHtml(IDocumentBuildContext context, string html, string so HtmlDocument document = new(); document.LoadHtml(html); - unresolvedXRefs = new List(); + unresolvedXRefs = []; TransformXrefInHtml(context, sourceFilePath, destFilePath, document.DocumentNode, unresolvedXRefs); TransformLinkInHtml(context, sourceFilePath, destFilePath, document.DocumentNode); diff --git a/src/Docfx.Build/XRefMaps/XRefArchive.cs b/src/Docfx.Build/XRefMaps/XRefArchive.cs index 893dbae35aa..b63ad979c3c 100644 --- a/src/Docfx.Build/XRefMaps/XRefArchive.cs +++ b/src/Docfx.Build/XRefMaps/XRefArchive.cs @@ -71,7 +71,7 @@ public static XRefArchive Open(string file, XRefArchiveMode mode) } fs = File.Create(file); archive = new ZipArchive(fs, ZipArchiveMode.Update); - entries = new List(); + entries = []; break; default: throw new ArgumentOutOfRangeException(nameof(mode)); @@ -299,7 +299,7 @@ public void Dispose() bool IXRefContainer.IsEmbeddedRedirections => true; - IEnumerable IXRefContainer.GetRedirections() => Enumerable.Empty(); + IEnumerable IXRefContainer.GetRedirections() => []; public IXRefContainerReader GetReader() { diff --git a/src/Docfx.Build/XRefMaps/XRefCollection.cs b/src/Docfx.Build/XRefMaps/XRefCollection.cs index 357a313bb99..b1c3eabf1df 100644 --- a/src/Docfx.Build/XRefMaps/XRefCollection.cs +++ b/src/Docfx.Build/XRefMaps/XRefCollection.cs @@ -29,8 +29,8 @@ public Task GetReaderAsync(string baseFolder, IReadOnlyLis private sealed class ReaderCreator { private readonly ImmutableList _uris; - private readonly HashSet _set = new(); - private readonly Dictionary, Uri> _processing = new(); + private readonly HashSet _set = []; + private readonly Dictionary, Uri> _processing = []; private readonly XRefMapDownloader _downloader; public ReaderCreator(ImmutableList uris, int maxParallelism, string baseFolder, IReadOnlyList fallbackFolders) diff --git a/src/Docfx.Build/XRefMaps/XRefMap.cs b/src/Docfx.Build/XRefMaps/XRefMap.cs index f376109837a..1699465440f 100644 --- a/src/Docfx.Build/XRefMaps/XRefMap.cs +++ b/src/Docfx.Build/XRefMaps/XRefMap.cs @@ -61,7 +61,7 @@ public class XRefMap : IXRefContainer [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Others { get; set; } = new(); + public Dictionary Others { get; set; } = []; public void Sort() { diff --git a/src/Docfx.Common/CompositeDictionary.cs b/src/Docfx.Common/CompositeDictionary.cs index 5415854b216..01b967a6561 100644 --- a/src/Docfx.Common/CompositeDictionary.cs +++ b/src/Docfx.Common/CompositeDictionary.cs @@ -192,7 +192,7 @@ private sealed class Entry public sealed class Builder { - private readonly List _entries = new(); + private readonly List _entries = []; internal Builder() { } diff --git a/src/Docfx.Common/FileAbstractLayer/EmptyFileReader.cs b/src/Docfx.Common/FileAbstractLayer/EmptyFileReader.cs index 07540ab2245..fe54c58038c 100644 --- a/src/Docfx.Common/FileAbstractLayer/EmptyFileReader.cs +++ b/src/Docfx.Common/FileAbstractLayer/EmptyFileReader.cs @@ -13,7 +13,7 @@ private EmptyFileReader() public PathMapping? FindFile(RelativePath file) => null; - public IEnumerable EnumerateFiles() => Enumerable.Empty(); + public IEnumerable EnumerateFiles() => []; public string GetExpectedPhysicalPath(RelativePath file) => null; } diff --git a/src/Docfx.Common/FileMapping.cs b/src/Docfx.Common/FileMapping.cs index 451e2288289..9b89ecf8a7a 100644 --- a/src/Docfx.Common/FileMapping.cs +++ b/src/Docfx.Common/FileMapping.cs @@ -28,7 +28,7 @@ namespace Docfx; [System.Text.Json.Serialization.JsonConverter(typeof(FileMappingConverter.SystemTextJsonConverter))] public class FileMapping { - private readonly List _items = new(); + private readonly List _items = []; /// /// Flags to distinguish items are expanded or not. diff --git a/src/Docfx.Common/Json/NewtonsoftJson/ConvertToObjectHelper.cs b/src/Docfx.Common/Json/NewtonsoftJson/ConvertToObjectHelper.cs index 7e05c239676..6605967af4a 100644 --- a/src/Docfx.Common/Json/NewtonsoftJson/ConvertToObjectHelper.cs +++ b/src/Docfx.Common/Json/NewtonsoftJson/ConvertToObjectHelper.cs @@ -76,12 +76,12 @@ public static object ConvertStrongTypeToJObject(object raw) public static object ConvertExpandoObjectToObject(object raw) { - return ConvertExpandoObjectToObjectCore(raw, new Dictionary()); + return ConvertExpandoObjectToObjectCore(raw, []); } public static object ConvertToDynamic(object obj) { - return ConvertToDynamicCore(obj, new Dictionary()); + return ConvertToDynamicCore(obj, []); } private static object ConvertExpandoObjectToObjectCore(object obj, Dictionary cache) diff --git a/src/Docfx.Common/Loggers/CompositeLogListener.cs b/src/Docfx.Common/Loggers/CompositeLogListener.cs index 680c0618568..d6ed964219c 100644 --- a/src/Docfx.Common/Loggers/CompositeLogListener.cs +++ b/src/Docfx.Common/Loggers/CompositeLogListener.cs @@ -6,7 +6,7 @@ namespace Docfx.Common; public class CompositeLogListener : ILoggerListener { private readonly object _sync = new(); - private readonly List _listeners = new(); + private readonly List _listeners = []; public CompositeLogListener() { diff --git a/src/Docfx.Common/ResourcePools/ResourcePoolManager.cs b/src/Docfx.Common/ResourcePools/ResourcePoolManager.cs index 7c4a7ef68cf..d435b6a8cda 100644 --- a/src/Docfx.Common/ResourcePools/ResourcePoolManager.cs +++ b/src/Docfx.Common/ResourcePools/ResourcePoolManager.cs @@ -8,7 +8,7 @@ public class ResourcePoolManager where TResource : class { private readonly object _syncRoot = new(); - private readonly List _resources = new(); + private readonly List _resources = []; private readonly Stack _stack = new(); private readonly Func _creator; private readonly int _maxResourceCount; diff --git a/src/Docfx.DataContracts.Common/ExternalReferences/ExternalReferencePackageReader.cs b/src/Docfx.DataContracts.Common/ExternalReferences/ExternalReferencePackageReader.cs index d1e0f1ebdac..a5443e00417 100644 --- a/src/Docfx.DataContracts.Common/ExternalReferences/ExternalReferencePackageReader.cs +++ b/src/Docfx.DataContracts.Common/ExternalReferences/ExternalReferencePackageReader.cs @@ -74,7 +74,7 @@ private static Dictionary> GetUidEntryMap(ZipArchive zip) { if (!uidEntryMap.TryGetValue(entry.Uid, out List list)) { - list = new List(); + list = []; uidEntryMap[entry.Uid] = list; } list.Add(entry.FullName); diff --git a/src/Docfx.DataContracts.Common/ReferenceViewModel.cs b/src/Docfx.DataContracts.Common/ReferenceViewModel.cs index 7810640f850..96ca044f8de 100644 --- a/src/Docfx.DataContracts.Common/ReferenceViewModel.cs +++ b/src/Docfx.DataContracts.Common/ReferenceViewModel.cs @@ -50,7 +50,7 @@ public class ReferenceViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.Name)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList NameInDevLangs { get; private set; } = new(); + public SortedList NameInDevLangs { get; private set; } = []; [YamlMember(Alias = Constants.PropertyName.NameWithType)] [JsonProperty(Constants.PropertyName.NameWithType)] @@ -60,7 +60,7 @@ public class ReferenceViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.NameWithType)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList NameWithTypeInDevLangs { get; private set; } = new(); + public SortedList NameWithTypeInDevLangs { get; private set; } = []; [YamlMember(Alias = Constants.PropertyName.FullName)] [JsonProperty(Constants.PropertyName.FullName)] @@ -70,17 +70,17 @@ public class ReferenceViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.FullName)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList FullNameInDevLangs { get; private set; } = new(); + public SortedList FullNameInDevLangs { get; private set; } = []; [ExtensibleMember(Constants.ExtensionMemberPrefix.Spec)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList> Specs { get; private set; } = new(); + public SortedList> Specs { get; private set; } = []; [ExtensibleMember] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public Dictionary Additional { get; private set; } = new(); + public Dictionary Additional { get; private set; } = []; [EditorBrowsable(EditorBrowsableState.Never)] [YamlIgnore] diff --git a/src/Docfx.DataContracts.Common/TocItemViewModel.cs b/src/Docfx.DataContracts.Common/TocItemViewModel.cs index 81937c34265..3611d348b48 100644 --- a/src/Docfx.DataContracts.Common/TocItemViewModel.cs +++ b/src/Docfx.DataContracts.Common/TocItemViewModel.cs @@ -116,7 +116,7 @@ public class TocItemViewModel [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] [System.Text.Json.Serialization.JsonPropertyName("__metadata__")] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; [EditorBrowsable(EditorBrowsableState.Never)] [YamlIgnore] diff --git a/src/Docfx.DataContracts.RestApi/RestApiItemViewModelBase.cs b/src/Docfx.DataContracts.RestApi/RestApiItemViewModelBase.cs index 71ebce5c825..2b1900799e2 100644 --- a/src/Docfx.DataContracts.RestApi/RestApiItemViewModelBase.cs +++ b/src/Docfx.DataContracts.RestApi/RestApiItemViewModelBase.cs @@ -58,5 +58,5 @@ public class RestApiItemViewModelBase : IOverwriteDocumentViewModel [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.DataContracts.RestApi/RestApiParameterViewModel.cs b/src/Docfx.DataContracts.RestApi/RestApiParameterViewModel.cs index 2211bbc46fc..2407dad082a 100644 --- a/src/Docfx.DataContracts.RestApi/RestApiParameterViewModel.cs +++ b/src/Docfx.DataContracts.RestApi/RestApiParameterViewModel.cs @@ -25,5 +25,5 @@ public class RestApiParameterViewModel [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.DataContracts.RestApi/RestApiResponseViewModel.cs b/src/Docfx.DataContracts.RestApi/RestApiResponseViewModel.cs index a2fe4118d8e..b8823d01ef9 100644 --- a/src/Docfx.DataContracts.RestApi/RestApiResponseViewModel.cs +++ b/src/Docfx.DataContracts.RestApi/RestApiResponseViewModel.cs @@ -35,5 +35,5 @@ public class RestApiResponseViewModel [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.DataContracts.RestApi/RestApiTagViewModel.cs b/src/Docfx.DataContracts.RestApi/RestApiTagViewModel.cs index 5d095f314a6..b76ebe77298 100644 --- a/src/Docfx.DataContracts.RestApi/RestApiTagViewModel.cs +++ b/src/Docfx.DataContracts.RestApi/RestApiTagViewModel.cs @@ -48,5 +48,5 @@ public class RestApiTagViewModel : IOverwriteDocumentViewModel [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.DataContracts.UniversalReference/ApiParameter.cs b/src/Docfx.DataContracts.UniversalReference/ApiParameter.cs index 2f367ac46ca..ec59c309591 100644 --- a/src/Docfx.DataContracts.UniversalReference/ApiParameter.cs +++ b/src/Docfx.DataContracts.UniversalReference/ApiParameter.cs @@ -48,5 +48,5 @@ public class ApiParameter [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.DataContracts.UniversalReference/ArgumentInfo.cs b/src/Docfx.DataContracts.UniversalReference/ArgumentInfo.cs index 09f70d2c4b0..29389305a71 100644 --- a/src/Docfx.DataContracts.UniversalReference/ArgumentInfo.cs +++ b/src/Docfx.DataContracts.UniversalReference/ArgumentInfo.cs @@ -26,5 +26,5 @@ public class ArgumentInfo [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.DataContracts.UniversalReference/AttributeInfo.cs b/src/Docfx.DataContracts.UniversalReference/AttributeInfo.cs index 073941c6215..faf7f48f60d 100644 --- a/src/Docfx.DataContracts.UniversalReference/AttributeInfo.cs +++ b/src/Docfx.DataContracts.UniversalReference/AttributeInfo.cs @@ -36,5 +36,5 @@ public class AttributeInfo [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.DataContracts.UniversalReference/ExceptionInfo.cs b/src/Docfx.DataContracts.UniversalReference/ExceptionInfo.cs index c7fad174904..ca82920f156 100644 --- a/src/Docfx.DataContracts.UniversalReference/ExceptionInfo.cs +++ b/src/Docfx.DataContracts.UniversalReference/ExceptionInfo.cs @@ -29,5 +29,5 @@ public class ExceptionInfo [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.DataContracts.UniversalReference/InheritanceTree.cs b/src/Docfx.DataContracts.UniversalReference/InheritanceTree.cs index 6d4cfc1fa15..467782f95af 100644 --- a/src/Docfx.DataContracts.UniversalReference/InheritanceTree.cs +++ b/src/Docfx.DataContracts.UniversalReference/InheritanceTree.cs @@ -32,5 +32,5 @@ public class InheritanceTree [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.DataContracts.UniversalReference/ItemViewModel.cs b/src/Docfx.DataContracts.UniversalReference/ItemViewModel.cs index 7e81cbf246f..eb27364d38c 100644 --- a/src/Docfx.DataContracts.UniversalReference/ItemViewModel.cs +++ b/src/Docfx.DataContracts.UniversalReference/ItemViewModel.cs @@ -46,7 +46,7 @@ public class ItemViewModel : IOverwriteDocumentViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.Parent)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList ParentInDevLangs { get; set; } = new(); + public SortedList ParentInDevLangs { get; set; } = []; [YamlMember(Alias = "package")] [JsonProperty("package")] @@ -57,7 +57,7 @@ public class ItemViewModel : IOverwriteDocumentViewModel [ExtensibleMember("package" + Constants.PrefixSeparator)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList PackageInDevLangs { get; set; } = new(); + public SortedList PackageInDevLangs { get; set; } = []; [YamlMember(Alias = Constants.PropertyName.Children)] [MergeOption(MergeOption.Ignore)] // todo : merge more children @@ -69,7 +69,7 @@ public class ItemViewModel : IOverwriteDocumentViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.Children)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList> ChildrenInDevLangs { get; set; } = new(); + public SortedList> ChildrenInDevLangs { get; set; } = []; /// /// item's link URL @@ -93,7 +93,7 @@ public class ItemViewModel : IOverwriteDocumentViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.Name)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList Names { get; set; } = new(); + public SortedList Names { get; set; } = []; [YamlMember(Alias = Constants.PropertyName.NameWithType)] [JsonProperty(Constants.PropertyName.NameWithType)] @@ -103,7 +103,7 @@ public class ItemViewModel : IOverwriteDocumentViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.NameWithType)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList NamesWithType { get; set; } = new(); + public SortedList NamesWithType { get; set; } = []; [YamlMember(Alias = Constants.PropertyName.FullName)] [JsonProperty(Constants.PropertyName.FullName)] @@ -113,7 +113,7 @@ public class ItemViewModel : IOverwriteDocumentViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.FullName)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList FullNames { get; set; } = new(); + public SortedList FullNames { get; set; } = []; [YamlMember(Alias = Constants.PropertyName.Type)] [JsonProperty(Constants.PropertyName.Type)] @@ -131,7 +131,7 @@ public class ItemViewModel : IOverwriteDocumentViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.Source)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList SourceInDevLangs { get; set; } = new(); + public SortedList SourceInDevLangs { get; set; } = []; /// /// item's documentation's source detail @@ -151,7 +151,7 @@ public class ItemViewModel : IOverwriteDocumentViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.Assemblies)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList> AssemblyNameListInDevLangs { get; set; } = new(); + public SortedList> AssemblyNameListInDevLangs { get; set; } = []; [YamlMember(Alias = Constants.PropertyName.Namespace)] [JsonProperty(Constants.PropertyName.Namespace)] @@ -162,7 +162,7 @@ public class ItemViewModel : IOverwriteDocumentViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.Namespace)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList NamespaceNameInDevLangs { get; set; } = new(); + public SortedList NamespaceNameInDevLangs { get; set; } = []; /// /// item's summary @@ -213,7 +213,7 @@ public class ItemViewModel : IOverwriteDocumentViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.Overridden)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList OverriddenInDevLangs { get; set; } = new(); + public SortedList OverriddenInDevLangs { get; set; } = []; [YamlMember(Alias = Constants.PropertyName.Overload)] [JsonProperty(Constants.PropertyName.Overload)] @@ -224,7 +224,7 @@ public class ItemViewModel : IOverwriteDocumentViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.Overload)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList OverloadInDevLangs { get; set; } = new(); + public SortedList OverloadInDevLangs { get; set; } = []; [YamlMember(Alias = "exceptions")] [JsonProperty("exceptions")] @@ -234,7 +234,7 @@ public class ItemViewModel : IOverwriteDocumentViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.Exceptions)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList> ExceptionsInDevLangs { get; set; } = new(); + public SortedList> ExceptionsInDevLangs { get; set; } = []; [YamlMember(Alias = "seealso")] [JsonProperty("seealso")] @@ -278,12 +278,12 @@ public class ItemViewModel : IOverwriteDocumentViewModel [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] [UniqueIdentityReference] - public List InheritanceUidReference => GetInheritanceUidReference(Inheritance)?.ToList() ?? new List(); + public List InheritanceUidReference => GetInheritanceUidReference(Inheritance)?.ToList() ?? []; [ExtensibleMember(Constants.ExtensionMemberPrefix.Inheritance)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList> InheritanceInDevLangs { get; set; } = new(); + public SortedList> InheritanceInDevLangs { get; set; } = []; [YamlMember(Alias = Constants.PropertyName.DerivedClasses)] [MergeOption(MergeOption.Ignore)] @@ -295,7 +295,7 @@ public class ItemViewModel : IOverwriteDocumentViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.DerivedClasses)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList> DerivedClassesInDevLangs { get; set; } = new(); + public SortedList> DerivedClassesInDevLangs { get; set; } = []; [YamlMember(Alias = Constants.PropertyName.Implements)] [MergeOption(MergeOption.Ignore)] // todo : merge more children @@ -307,7 +307,7 @@ public class ItemViewModel : IOverwriteDocumentViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.Implements)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList> ImplementsInDevLangs { get; set; } = new(); + public SortedList> ImplementsInDevLangs { get; set; } = []; [YamlMember(Alias = Constants.PropertyName.InheritedMembers)] [MergeOption(MergeOption.Ignore)] // todo : merge more children @@ -319,7 +319,7 @@ public class ItemViewModel : IOverwriteDocumentViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.InheritedMembers)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList> InheritedMembersInDevLangs { get; set; } = new(); + public SortedList> InheritedMembersInDevLangs { get; set; } = []; [YamlMember(Alias = Constants.PropertyName.ExtensionMethods)] [MergeOption(MergeOption.Ignore)] // todo : merge more children @@ -331,7 +331,7 @@ public class ItemViewModel : IOverwriteDocumentViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.ExtensionMethods)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList> ExtensionMethodsInDevLangs { get; set; } = new(); + public SortedList> ExtensionMethodsInDevLangs { get; set; } = []; /// /// item's conceptual @@ -352,13 +352,13 @@ public class ItemViewModel : IOverwriteDocumentViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.Platform)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList> PlatformInDevLangs { get; set; } = new(); + public SortedList> PlatformInDevLangs { get; set; } = []; [ExtensibleMember] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] [System.Text.Json.Serialization.JsonPropertyName("__metadata__")] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; [EditorBrowsable(EditorBrowsableState.Never)] [YamlIgnore] diff --git a/src/Docfx.DataContracts.UniversalReference/LinkInfo.cs b/src/Docfx.DataContracts.UniversalReference/LinkInfo.cs index 7a18c78acfb..a5ad351e19a 100644 --- a/src/Docfx.DataContracts.UniversalReference/LinkInfo.cs +++ b/src/Docfx.DataContracts.UniversalReference/LinkInfo.cs @@ -39,7 +39,7 @@ public class LinkInfo [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } public enum LinkType diff --git a/src/Docfx.DataContracts.UniversalReference/NamedArgumentInfo.cs b/src/Docfx.DataContracts.UniversalReference/NamedArgumentInfo.cs index 112111323d2..ae2f0b8eed2 100644 --- a/src/Docfx.DataContracts.UniversalReference/NamedArgumentInfo.cs +++ b/src/Docfx.DataContracts.UniversalReference/NamedArgumentInfo.cs @@ -31,5 +31,5 @@ public class NamedArgumentInfo [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.DataContracts.UniversalReference/PageViewModel.cs b/src/Docfx.DataContracts.UniversalReference/PageViewModel.cs index dbe7b09c8d1..efb67ce29c6 100644 --- a/src/Docfx.DataContracts.UniversalReference/PageViewModel.cs +++ b/src/Docfx.DataContracts.UniversalReference/PageViewModel.cs @@ -15,14 +15,14 @@ public class PageViewModel [YamlMember(Alias = "items")] [JsonProperty("items")] [JsonPropertyName("items")] - public List Items { get; set; } = new(); + public List Items { get; set; } = []; [YamlMember(Alias = "references")] [JsonProperty("references")] [JsonPropertyName("references")] [UniqueIdentityReferenceIgnore] [MarkdownContentIgnore] - public List References { get; set; } = new(); + public List References { get; set; } = []; [YamlMember(Alias = "shouldSkipMarkup")] [JsonProperty("shouldSkipMarkup")] @@ -32,5 +32,5 @@ public class PageViewModel [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.DataContracts.UniversalReference/SyntaxDetailViewModel.cs b/src/Docfx.DataContracts.UniversalReference/SyntaxDetailViewModel.cs index 34c11f2770b..6ddde79102f 100644 --- a/src/Docfx.DataContracts.UniversalReference/SyntaxDetailViewModel.cs +++ b/src/Docfx.DataContracts.UniversalReference/SyntaxDetailViewModel.cs @@ -47,13 +47,13 @@ public class SyntaxDetailViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.Return)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList ReturnInDevLangs { get; set; } = new(); + public SortedList ReturnInDevLangs { get; set; } = []; [ExtensibleMember] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] [System.Text.Json.Serialization.JsonPropertyName("__metadata__")] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; [EditorBrowsable(EditorBrowsableState.Never)] [YamlIgnore] diff --git a/src/Docfx.Dotnet/DotnetApiCatalog.Compile.cs b/src/Docfx.Dotnet/DotnetApiCatalog.Compile.cs index 480849fcfcb..e94c3a1a01a 100644 --- a/src/Docfx.Dotnet/DotnetApiCatalog.Compile.cs +++ b/src/Docfx.Dotnet/DotnetApiCatalog.Compile.cs @@ -20,9 +20,9 @@ partial class DotnetApiCatalog { var files = config.Files?.Select(s => new FileInformation(s)) .GroupBy(f => f.Type) - .ToDictionary(s => s.Key, s => s.Distinct().ToList()) ?? new(); + .ToDictionary(s => s.Key, s => s.Distinct().ToList()) ?? []; - var msbuildProperties = config.MSBuildProperties ?? new Dictionary(); + var msbuildProperties = config.MSBuildProperties ?? []; msbuildProperties.TryAdd("Configuration", "Release"); // NOTE: @@ -122,7 +122,7 @@ await LoadCompilationFromProject(project.AbsolutePath) is { } compilation) if (hasCompilationError) { - return new(); + return []; } if (assemblies.Count <= 0) diff --git a/src/Docfx.Dotnet/DotnetApiCatalog.ManagedReference.cs b/src/Docfx.Dotnet/DotnetApiCatalog.ManagedReference.cs index 3612add070e..001182f02b3 100644 --- a/src/Docfx.Dotnet/DotnetApiCatalog.ManagedReference.cs +++ b/src/Docfx.Dotnet/DotnetApiCatalog.ManagedReference.cs @@ -66,7 +66,7 @@ void ResolveAndExportYamlMetadata( YamlUtility.Serialize(tocFilePath, tocViewModel, YamlMime.TableOfContent); outputFileNames.Add(tocFilePath, 1); - ApiReferenceViewModel indexer = new(); + ApiReferenceViewModel indexer = []; // generate each item's yaml var members = model.Members; @@ -142,7 +142,7 @@ bool MergeNode(MetadataItem node) { if (node.Type is MemberType.Assembly) { - foreach (var item in node.Items ?? new()) + foreach (var item in node.Items ?? []) { MergeNode(item); } @@ -152,7 +152,7 @@ bool MergeNode(MetadataItem node) if (!result.TryGetValue(node.Name, out var existingNode)) { result.Add(node.Name, node); - foreach (var item in node.Items ?? new()) + foreach (var item in node.Items ?? []) { MergeNode(item); } @@ -161,11 +161,11 @@ bool MergeNode(MetadataItem node) if (node.Type is MemberType.Namespace or MemberType.Class) { - foreach (var item in node.Items ?? new()) + foreach (var item in node.Items ?? []) { if (MergeNode(item)) { - existingNode.Items ??= new(); + existingNode.Items ??= []; existingNode.Items.Add(item); } } diff --git a/src/Docfx.Dotnet/DotnetApiCatalog.Toc.cs b/src/Docfx.Dotnet/DotnetApiCatalog.Toc.cs index 9d61e3c50a6..d148421e458 100644 --- a/src/Docfx.Dotnet/DotnetApiCatalog.Toc.cs +++ b/src/Docfx.Dotnet/DotnetApiCatalog.Toc.cs @@ -37,7 +37,7 @@ class TocNode internal TocNodeType type; internal string? id; internal bool containsLeafNodes; - internal List<(ISymbol symbol, Compilation compilation)> symbols = new(); + internal List<(ISymbol symbol, Compilation compilation)> symbols = []; } private static List CreateToc(List<(IAssemblySymbol symbol, Compilation compilation)> assemblies, ExtractMetadataConfig config, DotnetApiOptions options) @@ -104,7 +104,7 @@ IEnumerable CreateNamespaceToc(INamespaceSymbol ns) var existingNodeHasNoLeafNode = idExists && !node.containsLeafNodes; - node.items ??= new(); + node.items ??= []; node.symbols.Add((symbol, compilation)); foreach (var child in ns.GetNamespaceMembers()) @@ -164,7 +164,7 @@ IEnumerable CreateNamedTypeToc(INamedTypeSymbol type) if (config.MemberLayout is MemberLayout.SeparatePages && type.TypeKind is TypeKind.Class or TypeKind.Interface or TypeKind.Struct) { - node.items ??= new(); + node.items ??= []; foreach (var member in type.GetMembers()) node.items.AddRange(CreateToc(member, compilation)); } diff --git a/src/Docfx.Dotnet/Filters/AttributeFilterInfo.cs b/src/Docfx.Dotnet/Filters/AttributeFilterInfo.cs index 63b3ddb6737..20aef537058 100644 --- a/src/Docfx.Dotnet/Filters/AttributeFilterInfo.cs +++ b/src/Docfx.Dotnet/Filters/AttributeFilterInfo.cs @@ -14,7 +14,7 @@ internal class AttributeFilterInfo public List ConstructorArguments { get; set; } [YamlMember(Alias = "ctorNamedArguments")] - public Dictionary ConstructorNamedArguments { get; set; } = new(); + public Dictionary ConstructorNamedArguments { get; set; } = []; public bool ContainedIn(SymbolFilterData symbol) { diff --git a/src/Docfx.Dotnet/Filters/ConfigFilterRule.cs b/src/Docfx.Dotnet/Filters/ConfigFilterRule.cs index e07f033e7ef..0e12bc07c39 100644 --- a/src/Docfx.Dotnet/Filters/ConfigFilterRule.cs +++ b/src/Docfx.Dotnet/Filters/ConfigFilterRule.cs @@ -10,10 +10,10 @@ namespace Docfx.Dotnet; internal class ConfigFilterRule { [YamlMember(Alias = "apiRules")] - public List ApiRules { get; set; } = new(); + public List ApiRules { get; set; } = []; [YamlMember(Alias = "attributeRules")] - public List AttributeRules { get; set; } = new(); + public List AttributeRules { get; set; } = []; public bool CanVisitApi(SymbolFilterData symbol) { diff --git a/src/Docfx.Dotnet/ManagedReference/Models/ItemViewModel.cs b/src/Docfx.Dotnet/ManagedReference/Models/ItemViewModel.cs index 406d47e1aaa..5ac4b6b9b68 100644 --- a/src/Docfx.Dotnet/ManagedReference/Models/ItemViewModel.cs +++ b/src/Docfx.Dotnet/ManagedReference/Models/ItemViewModel.cs @@ -72,7 +72,7 @@ public class ItemViewModel : IOverwriteDocumentViewModel, IItemWithMetadata [ExtensibleMember(Constants.ExtensionMemberPrefix.Name)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList Names { get; set; } = new(); + public SortedList Names { get; set; } = []; [YamlIgnore] [Newtonsoft.Json.JsonIgnore] @@ -128,7 +128,7 @@ public string NameForVB [ExtensibleMember(Constants.ExtensionMemberPrefix.NameWithType)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList NamesWithType { get; set; } = new(); + public SortedList NamesWithType { get; set; } = []; [YamlIgnore] [Newtonsoft.Json.JsonIgnore] @@ -184,7 +184,7 @@ public string NameWithTypeForVB [ExtensibleMember(Constants.ExtensionMemberPrefix.FullName)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList FullNames { get; set; } = new(); + public SortedList FullNames { get; set; } = []; [YamlIgnore] [Newtonsoft.Json.JsonIgnore] @@ -373,7 +373,7 @@ public string FullNameForVB [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] [System.Text.Json.Serialization.JsonPropertyName("__metadata__")] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; [EditorBrowsable(EditorBrowsableState.Never)] [YamlIgnore] diff --git a/src/Docfx.Dotnet/ManagedReference/Models/PageViewModel.cs b/src/Docfx.Dotnet/ManagedReference/Models/PageViewModel.cs index dfe564a80da..a872eacb0de 100644 --- a/src/Docfx.Dotnet/ManagedReference/Models/PageViewModel.cs +++ b/src/Docfx.Dotnet/ManagedReference/Models/PageViewModel.cs @@ -14,14 +14,14 @@ public class PageViewModel [YamlMember(Alias = "items")] [JsonProperty("items")] [JsonPropertyName("items")] - public List Items { get; set; } = new(); + public List Items { get; set; } = []; [YamlMember(Alias = "references")] [JsonProperty("references")] [JsonPropertyName("references")] [UniqueIdentityReferenceIgnore] [MarkdownContentIgnore] - public List References { get; set; } = new(); + public List References { get; set; } = []; [YamlMember(Alias = "shouldSkipMarkup")] [JsonProperty("shouldSkipMarkup")] @@ -36,5 +36,5 @@ public class PageViewModel [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.Dotnet/ManagedReference/Models/SyntaxDetailViewModel.cs b/src/Docfx.Dotnet/ManagedReference/Models/SyntaxDetailViewModel.cs index 8aa49b39a22..57d78edeb93 100644 --- a/src/Docfx.Dotnet/ManagedReference/Models/SyntaxDetailViewModel.cs +++ b/src/Docfx.Dotnet/ManagedReference/Models/SyntaxDetailViewModel.cs @@ -22,7 +22,7 @@ public class SyntaxDetailViewModel [ExtensibleMember(Constants.ExtensionMemberPrefix.Content)] [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public SortedList Contents { get; set; } = new(); + public SortedList Contents { get; set; } = []; [YamlIgnore] [Newtonsoft.Json.JsonIgnore] diff --git a/src/Docfx.Dotnet/ManagedReference/Resolvers/ResolveReference.cs b/src/Docfx.Dotnet/ManagedReference/Resolvers/ResolveReference.cs index 9f3c6eab950..f946b36b8df 100644 --- a/src/Docfx.Dotnet/ManagedReference/Resolvers/ResolveReference.cs +++ b/src/Docfx.Dotnet/ManagedReference/Resolvers/ResolveReference.cs @@ -20,7 +20,7 @@ public void Run(MetadataModel yaml, ResolverContext context) if (current.Type.IsPageLevel()) { page = current; - current.References = new Dictionary(); + current.References = []; } else { diff --git a/src/Docfx.Dotnet/ManagedReference/Resolvers/SetDerivedClass.cs b/src/Docfx.Dotnet/ManagedReference/Resolvers/SetDerivedClass.cs index 3f380805f2a..cb23287b342 100644 --- a/src/Docfx.Dotnet/ManagedReference/Resolvers/SetDerivedClass.cs +++ b/src/Docfx.Dotnet/ManagedReference/Resolvers/SetDerivedClass.cs @@ -7,7 +7,7 @@ namespace Docfx.Dotnet; internal class SetDerivedClass : IResolverPipeline { - private readonly Dictionary> _derivedClassMapping = new(); + private readonly Dictionary> _derivedClassMapping = []; public void Run(MetadataModel yaml, ResolverContext context) { @@ -41,7 +41,7 @@ private void UpdateDerivedClassMapping(List items, Dictionary { item.Name }); + _derivedClassMapping.Add(superClass, [item.Name]); } } } diff --git a/src/Docfx.Dotnet/ManagedReference/Resolvers/YamlMetadataResolver.cs b/src/Docfx.Dotnet/ManagedReference/Resolvers/YamlMetadataResolver.cs index f8001c4132c..57eda24d1df 100644 --- a/src/Docfx.Dotnet/ManagedReference/Resolvers/YamlMetadataResolver.cs +++ b/src/Docfx.Dotnet/ManagedReference/Resolvers/YamlMetadataResolver.cs @@ -8,8 +8,8 @@ namespace Docfx.Dotnet; internal static class YamlMetadataResolver { // Order matters - private static readonly List pipelines = new() - { + private static readonly List pipelines = + [ new LayoutCheckAndCleanup(), new SetParent(), new ResolveReference(), @@ -17,7 +17,7 @@ internal static class YamlMetadataResolver new BuildMembers(), new SetDerivedClass(), new BuildToc() - }; + ]; /// /// TODO: input Namespace list instead; @@ -33,7 +33,7 @@ public static MetadataModel ResolveMetadata( MetadataModel viewModel = new() { TocYamlViewModel = GenerateToc(allMembers, allReferences, namespaceLayout), - Members = new List(), + Members = [], }; ResolverContext context = new() { @@ -74,9 +74,9 @@ private static MetadataItem GenerateNestedTocStructure(IEnumerable namespacedItems = new(); + Dictionary namespacedItems = []; var dotsPerNamespace = namespaces.ToDictionary(x => x.Key, x => x.Value.Name.Where(y => y == '.').Count()); foreach (var member in namespaces @@ -95,10 +95,10 @@ private static MetadataItem GenerateNestedTocStructure(IEnumerable private static readonly IReadOnlyList EmptyListOfString = Array.Empty(); private readonly Compilation _compilation; private readonly YamlModelGenerator _generator; - private readonly Dictionary _references = new(); + private readonly Dictionary _references = []; private readonly IMethodSymbol[] _extensionMethods; private readonly ExtractMetadataConfig _config; private readonly SymbolFilter _filter; @@ -31,7 +31,7 @@ public SymbolVisitorAdapter(Compilation compilation, YamlModelGenerator generato _generator = generator; _filter = filter; _config = config; - _extensionMethods = extensionMethods?.Where(_filter.IncludeApi).ToArray() ?? Array.Empty(); + _extensionMethods = extensionMethods?.Where(_filter.IncludeApi).ToArray() ?? []; } public override MetadataItem DefaultVisit(ISymbol symbol) @@ -45,13 +45,13 @@ public override MetadataItem DefaultVisit(ISymbol symbol) { Name = VisitorHelper.GetId(symbol), CommentId = VisitorHelper.GetCommentId(symbol), - DisplayNames = new SortedList(), - DisplayNamesWithType = new SortedList(), - DisplayQualifiedNames = new SortedList(), + DisplayNames = [], + DisplayNamesWithType = [], + DisplayQualifiedNames = [], Source = _config.DisableGitFeatures ? null : VisitorHelper.GetSourceDetail(symbol, _compilation), }; var assemblyName = symbol.ContainingAssembly?.Name; - item.AssemblyNameList = string.IsNullOrEmpty(assemblyName) || assemblyName is "?" ? null : new List { assemblyName }; + item.AssemblyNameList = string.IsNullOrEmpty(assemblyName) || assemblyName is "?" ? null : [assemblyName]; if (symbol is not INamespaceSymbol) { var namespaceName = VisitorHelper.GetId(symbol.ContainingNamespace); @@ -155,10 +155,10 @@ public override MetadataItem VisitNamedType(INamedTypeSymbol symbol) } item.Type = VisitorHelper.GetMemberTypeFromTypeKind(symbol.TypeKind); - item.Syntax ??= new SyntaxDetail { Content = new SortedList() }; + item.Syntax ??= new SyntaxDetail { Content = [] }; if (item.Syntax.Content == null) { - item.Syntax.Content = new SortedList(); + item.Syntax.Content = []; } _generator.GenerateSyntax(symbol, item.Syntax, _filter); @@ -166,7 +166,7 @@ public override MetadataItem VisitNamedType(INamedTypeSymbol symbol) { if (item.Syntax.TypeParameters == null) { - item.Syntax.TypeParameters = new List(); + item.Syntax.TypeParameters = []; } foreach (var p in symbol.TypeParameters) @@ -182,7 +182,7 @@ public override MetadataItem VisitNamedType(INamedTypeSymbol symbol) AddMethodSyntax(symbol.DelegateInvokeMethod, item, typeGenericParameters, EmptyListOfString); } - item.Items = new List(); + item.Items = []; foreach ( var member in symbol.GetMembers() .Where(static s => @@ -212,13 +212,13 @@ public override MetadataItem VisitMethod(IMethodSymbol symbol) { return null; } - result.Syntax ??= new SyntaxDetail { Content = new SortedList() }; + result.Syntax ??= new SyntaxDetail { Content = [] }; if (symbol.TypeParameters.Length > 0) { if (result.Syntax.TypeParameters == null) { - result.Syntax.TypeParameters = new List(); + result.Syntax.TypeParameters = []; } foreach (var p in symbol.TypeParameters) @@ -236,7 +236,7 @@ public override MetadataItem VisitMethod(IMethodSymbol symbol) if (result.Syntax.Content == null) { - result.Syntax.Content = new SortedList(); + result.Syntax.Content = []; } _generator.GenerateSyntax(symbol, result.Syntax, _filter); @@ -264,10 +264,10 @@ public override MetadataItem VisitField(IFieldSymbol symbol) { return null; } - result.Syntax ??= new SyntaxDetail { Content = new SortedList() }; + result.Syntax ??= new SyntaxDetail { Content = [] }; if (result.Syntax.Content == null) { - result.Syntax.Content = new SortedList(); + result.Syntax.Content = []; } _generator.GenerateSyntax(symbol, result.Syntax, _filter); @@ -289,10 +289,10 @@ public override MetadataItem VisitEvent(IEventSymbol symbol) { return null; } - result.Syntax ??= new SyntaxDetail { Content = new SortedList() }; + result.Syntax ??= new SyntaxDetail { Content = [] }; if (result.Syntax.Content == null) { - result.Syntax.Content = new SortedList(); + result.Syntax.Content = []; } _generator.GenerateSyntax(symbol, result.Syntax, _filter); @@ -323,14 +323,14 @@ public override MetadataItem VisitProperty(IPropertySymbol symbol) { return null; } - result.Syntax ??= new SyntaxDetail { Content = new SortedList() }; + result.Syntax ??= new SyntaxDetail { Content = [] }; if (result.Syntax.Parameters == null) { - result.Syntax.Parameters = new List(); + result.Syntax.Parameters = []; } if (result.Syntax.Content == null) { - result.Syntax.Content = new SortedList(); + result.Syntax.Content = []; } _generator.GenerateSyntax(symbol, result.Syntax, _filter); @@ -387,9 +387,9 @@ public string AddReference(string id, string commentId) var reference = new ReferenceItem { CommentId = commentId }; if (DocumentationCommentId.GetFirstSymbolForDeclarationId(commentId, _compilation) is { } symbol) { - reference.NameParts = new(); - reference.NameWithTypeParts = new(); - reference.QualifiedNameParts = new(); + reference.NameParts = []; + reference.NameWithTypeParts = []; + reference.QualifiedNameParts = []; reference.IsDefinition = symbol.IsDefinition; _generator.GenerateReference(symbol, reference, asOverload: false, _filter); @@ -549,7 +549,7 @@ private void GenerateInheritance(INamedTypeSymbol symbol, MetadataItem item) { var type = symbol; var inheritance = new List(); - dict = new Dictionary(); + dict = []; var typeParameterNames = symbol.IsGenericType ? symbol.Accept(TypeGenericParameterNameVisitor.Instance) : EmptyListOfString; while (type != null) { @@ -587,7 +587,7 @@ where _filter.IncludeApi(t) } else if (symbol.TypeKind == TypeKind.Interface) { - dict = new Dictionary(); + dict = []; var typeParameterNames = symbol.IsGenericType ? symbol.Accept(TypeGenericParameterNameVisitor.Instance) : EmptyListOfString; AddInheritedMembers(symbol, symbol, dict, typeParameterNames); for (int i = 0; i < symbol.AllInterfaces.Length; i++) @@ -692,7 +692,7 @@ private void AddMethodSyntax(IMethodSymbol symbol, MetadataItem result, IReadOnl { if (result.Syntax.Parameters == null) { - result.Syntax.Parameters = new List(); + result.Syntax.Parameters = []; } foreach (var p in symbol.Parameters) @@ -719,7 +719,7 @@ private XmlCommentParserContext GetXmlCommentParserContext(MetadataItem item) void AddReferenceDelegate(string id, string commentId) { var r = AddReference(id, commentId); - item.References ??= new Dictionary(); + item.References ??= []; // only record the id now, the value would be fed at later phase after merge item.References[id] = null; diff --git a/src/Docfx.Dotnet/ManagedReference/Visitors/TypeGenericParameterNameVisitor.cs b/src/Docfx.Dotnet/ManagedReference/Visitors/TypeGenericParameterNameVisitor.cs index fabeabcf217..e3e4f436222 100644 --- a/src/Docfx.Dotnet/ManagedReference/Visitors/TypeGenericParameterNameVisitor.cs +++ b/src/Docfx.Dotnet/ManagedReference/Visitors/TypeGenericParameterNameVisitor.cs @@ -27,7 +27,7 @@ public override List VisitNamedType(INamedTypeSymbol symbol) } if (symbol.TypeParameters.Length > 0) { - result ??= new List(); + result ??= []; for (int i = 0; i < symbol.TypeParameters.Length; i++) { result.Add(symbol.TypeParameters[i].Name); diff --git a/src/Docfx.Dotnet/ManagedReference/Visitors/YamlModelGenerator.cs b/src/Docfx.Dotnet/ManagedReference/Visitors/YamlModelGenerator.cs index 79d205e1f36..889f9a36f96 100644 --- a/src/Docfx.Dotnet/ManagedReference/Visitors/YamlModelGenerator.cs +++ b/src/Docfx.Dotnet/ManagedReference/Visitors/YamlModelGenerator.cs @@ -33,22 +33,22 @@ public void DefaultVisit(ISymbol symbol, MetadataItem item) public void GenerateReference(ISymbol symbol, ReferenceItem reference, bool asOverload, SymbolFilter filter) { if (!reference.NameParts.ContainsKey(SyntaxLanguage.CSharp)) - reference.NameParts.Add(SyntaxLanguage.CSharp, new()); + reference.NameParts.Add(SyntaxLanguage.CSharp, []); if (!reference.NameWithTypeParts.ContainsKey(SyntaxLanguage.CSharp)) - reference.NameWithTypeParts.Add(SyntaxLanguage.CSharp, new()); + reference.NameWithTypeParts.Add(SyntaxLanguage.CSharp, []); if (!reference.QualifiedNameParts.ContainsKey(SyntaxLanguage.CSharp)) - reference.QualifiedNameParts.Add(SyntaxLanguage.CSharp, new()); + reference.QualifiedNameParts.Add(SyntaxLanguage.CSharp, []); reference.NameParts[SyntaxLanguage.CSharp] = SymbolFormatter.GetNameParts(symbol, SyntaxLanguage.CSharp, nullableReferenceType: false, asOverload).ToLinkItems(_compilation, _memberLayout, _allAssemblies, asOverload, filter); reference.NameWithTypeParts[SyntaxLanguage.CSharp] = SymbolFormatter.GetNameWithTypeParts(symbol, SyntaxLanguage.CSharp, nullableReferenceType: false, asOverload).ToLinkItems(_compilation, _memberLayout, _allAssemblies, asOverload, filter); reference.QualifiedNameParts[SyntaxLanguage.CSharp] = SymbolFormatter.GetQualifiedNameParts(symbol, SyntaxLanguage.CSharp, nullableReferenceType: false, asOverload).ToLinkItems(_compilation, _memberLayout, _allAssemblies, asOverload, filter); if (!reference.NameParts.ContainsKey(SyntaxLanguage.VB)) - reference.NameParts.Add(SyntaxLanguage.VB, new()); + reference.NameParts.Add(SyntaxLanguage.VB, []); if (!reference.NameWithTypeParts.ContainsKey(SyntaxLanguage.VB)) - reference.NameWithTypeParts.Add(SyntaxLanguage.VB, new()); + reference.NameWithTypeParts.Add(SyntaxLanguage.VB, []); if (!reference.QualifiedNameParts.ContainsKey(SyntaxLanguage.VB)) - reference.QualifiedNameParts.Add(SyntaxLanguage.VB, new()); + reference.QualifiedNameParts.Add(SyntaxLanguage.VB, []); reference.NameParts[SyntaxLanguage.VB] = SymbolFormatter.GetNameParts(symbol, SyntaxLanguage.VB, nullableReferenceType: false, asOverload).ToLinkItems(_compilation, _memberLayout, _allAssemblies, asOverload, filter); reference.NameWithTypeParts[SyntaxLanguage.VB] = SymbolFormatter.GetNameWithTypeParts(symbol, SyntaxLanguage.VB, nullableReferenceType: false, asOverload).ToLinkItems(_compilation, _memberLayout, _allAssemblies, asOverload, filter); @@ -66,9 +66,9 @@ public string AddReference(ISymbol symbol, Dictionary ref var id = VisitorHelper.GetId(symbol); var reference = new ReferenceItem { - NameParts = new(), - NameWithTypeParts = new(), - QualifiedNameParts = new(), + NameParts = [], + NameWithTypeParts = [], + QualifiedNameParts = [], IsDefinition = symbol.IsDefinition, CommentId = VisitorHelper.GetCommentId(symbol) }; @@ -87,9 +87,9 @@ public string AddOverloadReference(ISymbol symbol, Dictionary { "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr" }; + _voidElements = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]; } public override void WriteEndElement() diff --git a/src/Docfx.Dotnet/SymbolUrlResolver.SourceLink.cs b/src/Docfx.Dotnet/SymbolUrlResolver.SourceLink.cs index d7ba0c49a09..ed54a5c4e88 100644 --- a/src/Docfx.Dotnet/SymbolUrlResolver.SourceLink.cs +++ b/src/Docfx.Dotnet/SymbolUrlResolver.SourceLink.cs @@ -18,7 +18,7 @@ namespace Docfx.Dotnet; partial class SymbolUrlResolver { - private static readonly ConditionalWeakTable s_sourceLinkProviders = new(); + private static readonly ConditionalWeakTable s_sourceLinkProviders = []; public static string? GetPdbSourceLinkUrl(Compilation compilation, ISymbol symbol) { diff --git a/src/Docfx.Dotnet/YamlViewModelExtensions.cs b/src/Docfx.Dotnet/YamlViewModelExtensions.cs index d0f534122a0..5c910db7eb9 100644 --- a/src/Docfx.Dotnet/YamlViewModelExtensions.cs +++ b/src/Docfx.Dotnet/YamlViewModelExtensions.cs @@ -42,7 +42,7 @@ public static MetadataItem ShrinkToSimpleToc(this MetadataItem item) { foreach (var i in item.Items) { - shrinkedItem.Items ??= new List(); + shrinkedItem.Items ??= []; if (i.IsInvalid) { @@ -77,7 +77,7 @@ public static MetadataItem ShrinkToSimpleTocWithNamespaceNotEmpty(this MetadataI { foreach (var i in item.Items) { - shrinkedItem.Items ??= new List(); + shrinkedItem.Items ??= []; if (i.IsInvalid) { diff --git a/src/Docfx.Glob/FileGlob.cs b/src/Docfx.Glob/FileGlob.cs index 2fd54a43982..3ce3e43cfd1 100644 --- a/src/Docfx.Glob/FileGlob.cs +++ b/src/Docfx.Glob/FileGlob.cs @@ -9,7 +9,7 @@ public static IEnumerable GetFiles(string cwd, IEnumerable patte { if (patterns == null) { - return Enumerable.Empty(); + return []; } if (string.IsNullOrEmpty(cwd)) @@ -18,7 +18,7 @@ public static IEnumerable GetFiles(string cwd, IEnumerable patte } var globArray = patterns.Select(s => new GlobMatcher(s, options)).ToArray(); var excludeGlobArray = excludePatterns == null ? - Array.Empty() : + [] : excludePatterns.Select(s => new GlobMatcher(s, options)).ToArray(); return GetFilesCore(cwd, globArray, excludeGlobArray); } diff --git a/src/Docfx.Glob/GlobMatcher.cs b/src/Docfx.Glob/GlobMatcher.cs index 084e59e4e94..c1dc15a237a 100644 --- a/src/Docfx.Glob/GlobMatcher.cs +++ b/src/Docfx.Glob/GlobMatcher.cs @@ -12,7 +12,7 @@ public partial class GlobMatcher : IEquatable { #region Private fields private static readonly StringComparer Comparer = FilePathComparer.OSPlatformSensitiveStringComparer; - private static readonly string[] EmptyString = Array.Empty(); + private static readonly string[] EmptyString = []; private const char NegateChar = '!'; private const string GlobStar = "**"; private const string ReplacerGroupName = "replacer"; @@ -120,7 +120,7 @@ private IEnumerable Compile(string pattern) if (Options.HasFlag(GlobMatcherOptions.AllowExpand)) { globs = ExpandGroup(pattern, Options); - if (globs.Length == 0) return Enumerable.Empty(); + if (globs.Length == 0) return []; } else { @@ -558,8 +558,7 @@ public override GlobNode FinishLevel() } public override List Flatten() { - List result = new(1); - result.Add(_builder); + List result = [_builder]; return result; } } @@ -569,7 +568,7 @@ public class ChoiceNode : GlobNode public ChoiceNode(GlobNode parentNode) : base(parentNode) { - _nodes = new List(); + _nodes = []; } public override GlobNode AddChar(char c) { @@ -594,7 +593,7 @@ public override GlobNode FinishLevel() } public override List Flatten() { - List result = new(); + List result = []; foreach (GlobNode node in _nodes) { foreach (StringBuilder builder in node.Flatten()) @@ -611,7 +610,7 @@ public class SequenceNode : GlobNode public SequenceNode(GlobNode parentNode) : base(parentNode) { - _nodes = new List(); + _nodes = []; } public override GlobNode AddChar(char c) { @@ -635,11 +634,10 @@ public override GlobNode FinishLevel() } public override List Flatten() { - List result = new(); - result.Add(new StringBuilder()); + List result = [new StringBuilder()]; foreach (GlobNode node in _nodes) { - List tmp = new(); + List tmp = []; foreach (StringBuilder builder in node.Flatten()) { foreach (StringBuilder sb in result) diff --git a/src/Docfx.MarkdigEngine.Extensions/CodeSnippet/HtmlCodeSnippetRenderer.cs b/src/Docfx.MarkdigEngine.Extensions/CodeSnippet/HtmlCodeSnippetRenderer.cs index 7cbd512a00d..fa6c849dbf9 100644 --- a/src/Docfx.MarkdigEngine.Extensions/CodeSnippet/HtmlCodeSnippetRenderer.cs +++ b/src/Docfx.MarkdigEngine.Extensions/CodeSnippet/HtmlCodeSnippetRenderer.cs @@ -110,17 +110,17 @@ public class HtmlCodeSnippetRenderer : HtmlObjectRenderer { "vb", new string[] {"vbnet", "vbscript", "bas", "vbs", "vba" } } }; - private static readonly Dictionary s_languageByFileExtension = new(); + private static readonly Dictionary s_languageByFileExtension = []; // If we ever come across a language that has not been defined above, we shouldn't break the build. // We can at least try it with a default language, "C#" for now, and try and resolve the code snippet. - private static readonly HashSet s_defaultExtractors = new(); + private static readonly HashSet s_defaultExtractors = []; // Language names and aliases follow http://highlightjs.readthedocs.org/en/latest/css-classes-reference.html#language-names-and-aliases // Language file extensions follow https://github.com/github/linguist/blob/master/lib/linguist/languages.yml // Currently only supports parts of the language names, aliases and extensions // Later we can move the repository's supported/custom language names, aliases, extensions and corresponding comments regexes to docfx build configuration - private static readonly Dictionary> s_languageExtractors = new(); + private static readonly Dictionary> s_languageExtractors = []; private readonly MarkdownContext _context; @@ -198,7 +198,7 @@ static void AddExtractorItem(string language, CodeSnippetExtractor extractor) } else { - s_languageExtractors[language] = new HashSet { extractor }; + s_languageExtractors[language] = [extractor]; } } } @@ -299,22 +299,22 @@ public string GetContent(string content, CodeSnippet obj) var tagWithPrefix = TagPrefix + obj.TagName; foreach (var extractor in extractors) { - HashSet tagLines = new(); + HashSet tagLines = []; var tagToCodeRangeMapping = extractor.GetAllTags(allLines, ref tagLines); if (tagToCodeRangeMapping.TryGetValue(obj.TagName, out var cr) || tagToCodeRangeMapping.TryGetValue(tagWithPrefix, out cr)) { - return GetCodeLines(allLines, obj, new List { cr }, tagLines); + return GetCodeLines(allLines, obj, [cr], tagLines); } } } else if (obj.BookMarkRange != null) { - return GetCodeLines(allLines, obj, new List { obj.BookMarkRange }); + return GetCodeLines(allLines, obj, [obj.BookMarkRange]); } else if (obj.StartEndRange != null) { - return GetCodeLines(allLines, obj, new List { obj.StartEndRange }); + return GetCodeLines(allLines, obj, [obj.StartEndRange]); } else if (obj.CodeRanges != null) { @@ -322,7 +322,7 @@ public string GetContent(string content, CodeSnippet obj) } else { - return GetCodeLines(allLines, obj, new List { new() { Start = 0, End = allLines.Length } }); + return GetCodeLines(allLines, obj, [new() { Start = 0, End = allLines.Length }]); } return string.Empty; @@ -340,7 +340,7 @@ private static IEnumerable ReadAllLines(string content) private static string GetCodeLines(string[] allLines, CodeSnippet obj, List codeRanges, HashSet ignoreLines = null) { - List codeLines = new(); + List codeLines = []; StringBuilder showCode = new(); int commonIndent = int.MaxValue; @@ -458,7 +458,7 @@ public static bool TryGetLineRanges(string query, out List codeRanges return false; } - codeRanges ??= new List(); + codeRanges ??= []; codeRanges.Add(codeRange); } diff --git a/src/Docfx.MarkdigEngine.Extensions/TabGroup/ActiveAndVisibleRewriter.cs b/src/Docfx.MarkdigEngine.Extensions/TabGroup/ActiveAndVisibleRewriter.cs index adce056fc14..04c4d8712f8 100644 --- a/src/Docfx.MarkdigEngine.Extensions/TabGroup/ActiveAndVisibleRewriter.cs +++ b/src/Docfx.MarkdigEngine.Extensions/TabGroup/ActiveAndVisibleRewriter.cs @@ -10,7 +10,7 @@ namespace Docfx.MarkdigEngine.Extensions; public class ActiveAndVisibleRewriter : IMarkdownObjectRewriter { private readonly MarkdownContext _context; - private readonly List tabSelectionInfo = new(); + private readonly List tabSelectionInfo = []; public ActiveAndVisibleRewriter(MarkdownContext context) { diff --git a/src/Docfx.Plugins/FileModel.cs b/src/Docfx.Plugins/FileModel.cs index 6c5b6e7adc6..c49cd10fe16 100644 --- a/src/Docfx.Plugins/FileModel.cs +++ b/src/Docfx.Plugins/FileModel.cs @@ -67,9 +67,9 @@ public string File public string Key { get; } - public ImmutableHashSet LinkToFiles { get; set; } = ImmutableHashSet.Empty; + public ImmutableHashSet LinkToFiles { get; set; } = []; - public ImmutableHashSet LinkToUids { get; set; } = ImmutableHashSet.Empty; + public ImmutableHashSet LinkToUids { get; set; } = []; public ImmutableDictionary> UidLinkSources { get; set; } = ImmutableDictionary>.Empty; diff --git a/src/Docfx.Plugins/GroupInfo.cs b/src/Docfx.Plugins/GroupInfo.cs index f1a2eaea0d5..46de030df40 100644 --- a/src/Docfx.Plugins/GroupInfo.cs +++ b/src/Docfx.Plugins/GroupInfo.cs @@ -9,5 +9,5 @@ public class GroupInfo public string Destination { get; set; } - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.Plugins/Manifest.cs b/src/Docfx.Plugins/Manifest.cs index 729c8b853c6..3af14a535d6 100644 --- a/src/Docfx.Plugins/Manifest.cs +++ b/src/Docfx.Plugins/Manifest.cs @@ -27,7 +27,7 @@ public Manifest() { } [JsonProperty("files")] [JsonPropertyName("files")] - public List Files { get; init; } = new(); + public List Files { get; init; } = []; [JsonProperty("groups")] [JsonPropertyName("groups")] diff --git a/src/Docfx.Plugins/ManifestGroupInfo.cs b/src/Docfx.Plugins/ManifestGroupInfo.cs index 0bf3b2b5edf..c123eadf3c2 100644 --- a/src/Docfx.Plugins/ManifestGroupInfo.cs +++ b/src/Docfx.Plugins/ManifestGroupInfo.cs @@ -22,7 +22,7 @@ public class ManifestGroupInfo [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; // Default constructor for System.Text.Json deserialization public ManifestGroupInfo() { } diff --git a/src/Docfx.Plugins/ManifestItem.cs b/src/Docfx.Plugins/ManifestItem.cs index 003278e7a7a..8f684435026 100644 --- a/src/Docfx.Plugins/ManifestItem.cs +++ b/src/Docfx.Plugins/ManifestItem.cs @@ -18,7 +18,7 @@ public class ManifestItem [JsonProperty("output")] [JsonPropertyName("output")] - public Dictionary Output { get; init; } = new(); + public Dictionary Output { get; init; } = []; [JsonProperty("version")] [JsonPropertyName("version")] @@ -30,5 +30,5 @@ public class ManifestItem [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.Plugins/OutputFileInfo.cs b/src/Docfx.Plugins/OutputFileInfo.cs index 3779d0357e5..ad4c0e8bbda 100644 --- a/src/Docfx.Plugins/OutputFileInfo.cs +++ b/src/Docfx.Plugins/OutputFileInfo.cs @@ -18,5 +18,5 @@ public class OutputFileInfo [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.Plugins/TreeItem.cs b/src/Docfx.Plugins/TreeItem.cs index fa53c634788..302c6c691a2 100644 --- a/src/Docfx.Plugins/TreeItem.cs +++ b/src/Docfx.Plugins/TreeItem.cs @@ -14,5 +14,5 @@ public class TreeItem [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/src/Docfx.Plugins/XRefSpec.cs b/src/Docfx.Plugins/XRefSpec.cs index 7fad3792ed8..7f20872794f 100644 --- a/src/Docfx.Plugins/XRefSpec.cs +++ b/src/Docfx.Plugins/XRefSpec.cs @@ -17,7 +17,7 @@ public sealed class XRefSpec : IDictionary public XRefSpec() { - _dict = new Dictionary(); + _dict = []; } public XRefSpec(IDictionary dictionary) diff --git a/src/Docfx.YamlSerialization/NodeDeserializers/EmitGenericCollectionNodeDeserializer.cs b/src/Docfx.YamlSerialization/NodeDeserializers/EmitGenericCollectionNodeDeserializer.cs index 791becbd3c7..58f5dd74ff2 100644 --- a/src/Docfx.YamlSerialization/NodeDeserializers/EmitGenericCollectionNodeDeserializer.cs +++ b/src/Docfx.YamlSerialization/NodeDeserializers/EmitGenericCollectionNodeDeserializer.cs @@ -19,10 +19,8 @@ public class EmitGenericCollectionNodeDeserializer : INodeDeserializer private static readonly MethodInfo DeserializeHelperMethod = typeof(EmitGenericCollectionNodeDeserializer).GetMethod(nameof(DeserializeHelper))!; private readonly IObjectFactory _objectFactory; - private readonly Dictionary _gpCache = - new(); - private readonly Dictionary, object?>> _actionCache = - new(); + private readonly Dictionary _gpCache = []; + private readonly Dictionary, object?>> _actionCache = []; public EmitGenericCollectionNodeDeserializer(IObjectFactory objectFactory) { diff --git a/src/Docfx.YamlSerialization/NodeDeserializers/EmitGenericDictionaryNodeDeserializer.cs b/src/Docfx.YamlSerialization/NodeDeserializers/EmitGenericDictionaryNodeDeserializer.cs index 6d0fbc26658..8294a3dd44d 100644 --- a/src/Docfx.YamlSerialization/NodeDeserializers/EmitGenericDictionaryNodeDeserializer.cs +++ b/src/Docfx.YamlSerialization/NodeDeserializers/EmitGenericDictionaryNodeDeserializer.cs @@ -16,10 +16,8 @@ public class EmitGenericDictionaryNodeDeserializer : INodeDeserializer private static readonly MethodInfo DeserializeHelperMethod = typeof(EmitGenericDictionaryNodeDeserializer).GetMethod(nameof(DeserializeHelper))!; private readonly IObjectFactory _objectFactory; - private readonly Dictionary _gpCache = - new(); - private readonly Dictionary, Action, object?>> _actionCache = - new(); + private readonly Dictionary _gpCache = []; + private readonly Dictionary, Action, object?>> _actionCache = []; public EmitGenericDictionaryNodeDeserializer(IObjectFactory objectFactory) { diff --git a/src/Docfx.YamlSerialization/ObjectFactories/DefaultEmitObjectFactory.cs b/src/Docfx.YamlSerialization/ObjectFactories/DefaultEmitObjectFactory.cs index f5466f1d099..5cef58e0f1e 100644 --- a/src/Docfx.YamlSerialization/ObjectFactories/DefaultEmitObjectFactory.cs +++ b/src/Docfx.YamlSerialization/ObjectFactories/DefaultEmitObjectFactory.cs @@ -10,7 +10,7 @@ namespace Docfx.YamlSerialization.ObjectFactories; public class DefaultEmitObjectFactory : ObjectFactoryBase { - private readonly Dictionary> _cache = new(); + private readonly Dictionary> _cache = []; private static Type[] EmptyTypes => Type.EmptyTypes; public override object Create(Type type) diff --git a/src/Docfx.YamlSerialization/ObjectGraphTraversalStrategies/FullObjectGraphTraversalStrategy.cs b/src/Docfx.YamlSerialization/ObjectGraphTraversalStrategies/FullObjectGraphTraversalStrategy.cs index 3b391c61600..29dfdfab69a 100644 --- a/src/Docfx.YamlSerialization/ObjectGraphTraversalStrategies/FullObjectGraphTraversalStrategy.cs +++ b/src/Docfx.YamlSerialization/ObjectGraphTraversalStrategies/FullObjectGraphTraversalStrategy.cs @@ -28,10 +28,8 @@ public class FullObjectGraphTraversalStrategy : IObjectGraphTraversalStrategy private readonly ITypeInspector _typeDescriptor; private readonly ITypeResolver _typeResolver; private readonly INamingConvention _namingConvention; - private readonly Dictionary, Action> _behaviorCache = - new(); - private readonly Dictionary, Action> _traverseGenericDictionaryCache = - new(); + private readonly Dictionary, Action> _behaviorCache = []; + private readonly Dictionary, Action> _traverseGenericDictionaryCache = []; public FullObjectGraphTraversalStrategy(YamlSerializer serializer, ITypeInspector typeDescriptor, ITypeResolver typeResolver, int maxRecursion, INamingConvention? namingConvention) { diff --git a/src/Docfx.YamlSerialization/TypeInspectors/EmitTypeInspector.cs b/src/Docfx.YamlSerialization/TypeInspectors/EmitTypeInspector.cs index f557111176c..bd893e48aed 100644 --- a/src/Docfx.YamlSerialization/TypeInspectors/EmitTypeInspector.cs +++ b/src/Docfx.YamlSerialization/TypeInspectors/EmitTypeInspector.cs @@ -68,9 +68,9 @@ private CachingItem() { } public Exception? Error { get; private set; } - public List Properties { get; } = new(); + public List Properties { get; } = []; - public List ExtensibleProperties { get; } = new(); + public List ExtensibleProperties { get; } = []; public static CachingItem Create(Type type) { diff --git a/src/Docfx.YamlSerialization/YamlDeserializer.cs b/src/Docfx.YamlSerialization/YamlDeserializer.cs index 94b61385596..221e8b70d56 100644 --- a/src/Docfx.YamlSerialization/YamlDeserializer.cs +++ b/src/Docfx.YamlSerialization/YamlDeserializer.cs @@ -85,8 +85,8 @@ public YamlDeserializer( _converters.Add(yamlTypeConverter); } - NodeDeserializers = new List - { + NodeDeserializers = + [ new TypeConverterNodeDeserializer(_converters), new NullNodeDeserializer(), new ScalarNodeDeserializer(attemptUnknownTypeDeserialization: false, _reflectionTypeConverter, YamlFormatter.Default, NullNamingConvention.Instance), @@ -97,14 +97,14 @@ public YamlDeserializer( new CollectionNodeDeserializer(objectFactory, NullNamingConvention.Instance), new EnumerableNodeDeserializer(), new ExtensibleObjectNodeDeserializer(objectFactory, _typeDescriptor, ignoreUnmatched) - }; + ]; _tagMappings = new Dictionary(PredefinedTagMappings); - TypeResolvers = new List - { + TypeResolvers = + [ new TagNodeTypeResolver(_tagMappings), new DefaultContainersNodeTypeResolver(), new ScalarYamlNodeTypeResolver() - }; + ]; NodeValueDeserializer nodeValueDeserializer = new(NodeDeserializers, TypeResolvers, _reflectionTypeConverter, NullNamingConvention.Instance); if (ignoreNotFoundAnchor) diff --git a/src/docfx/Models/BuildCommand.cs b/src/docfx/Models/BuildCommand.cs index 4dcc87189a3..4ac804afbc7 100644 --- a/src/docfx/Models/BuildCommand.cs +++ b/src/docfx/Models/BuildCommand.cs @@ -56,7 +56,7 @@ internal static void MergeOptionsToConfig(BuildCommandOptions options, BuildJson { config.Xref = new ListWithStringFallback( - (config.Xref ?? new ListWithStringFallback()) + (config.Xref ?? []) .Concat(options.XRefMaps) .Where(x => !string.IsNullOrWhiteSpace(x)) .Distinct()); @@ -100,7 +100,7 @@ void SetGlobalMetadataFromCommandLineArgs() { if (options.Metadata != null) { - config.GlobalMetadata ??= new(); + config.GlobalMetadata ??= []; foreach (var metadata in options.Metadata) { var (key, value) = ParseMetadata(metadata); diff --git a/src/docfx/Models/TemplateCommand.cs b/src/docfx/Models/TemplateCommand.cs index 2961c3d8857..b30ce1d4566 100644 --- a/src/docfx/Models/TemplateCommand.cs +++ b/src/docfx/Models/TemplateCommand.cs @@ -53,7 +53,7 @@ public override int Execute(CommandContext context, Options options) foreach (var template in templates) { - var manager = new TemplateManager(new List { template }, null, null); + var manager = new TemplateManager([template], null, null); if (manager.TryExportTemplateFiles(Path.Combine(outputFolder, template))) { Logger.LogInfo($"{template} is exported to {outputFolder}"); diff --git a/test/Docfx.Build.Common.Tests/MarkdownReaderTest.cs b/test/Docfx.Build.Common.Tests/MarkdownReaderTest.cs index a8c47d11e89..5e5da0a699e 100644 --- a/test/Docfx.Build.Common.Tests/MarkdownReaderTest.cs +++ b/test/Docfx.Build.Common.Tests/MarkdownReaderTest.cs @@ -26,7 +26,7 @@ public void TestReadMarkdownAsOverwrite() var fileName = "ut_ReadMarkdownAsOverwrite.md"; var fullPath = Path.Combine(baseDir, fileName); File.WriteAllText(fullPath, content); - var host = new HostService(Enumerable.Empty()) + var host = new HostService([]) { MarkdownService = new MarkdigMarkdownService(new MarkdownServiceParameters { BasePath = string.Empty }), SourceFiles = ImmutableDictionary.Create() diff --git a/test/Docfx.Build.Common.Tests/ModelAttributeHandlerTest.cs b/test/Docfx.Build.Common.Tests/ModelAttributeHandlerTest.cs index 4db7ad6775f..79047dc6bb0 100644 --- a/test/Docfx.Build.Common.Tests/ModelAttributeHandlerTest.cs +++ b/test/Docfx.Build.Common.Tests/ModelAttributeHandlerTest.cs @@ -20,7 +20,7 @@ public void TestSimpleModelWithUniqueIdentityReferenceAttributeShouldSucceed() var model = new SimpleModel { Identity = "Identity1", - Identities = new List { "Identity2" } + Identities = ["Identity2"] }; var context = Handle(model); @@ -61,7 +61,7 @@ public void TestModelWithInvalidItemTypeShouldThrow() { var model = new InvalidModel2 { - Identities = new List { 0 } + Identities = [0] }; Assert.Throws( () => Handle(model) @@ -73,23 +73,23 @@ public void TestComplexModelWithUniqueIdentityReferenceAttributeShouldSucceed() { var model = new ComplexModel { - Identities = new List { "1", "2", "3" }, + Identities = ["1", "2", "3"], Identity = "0", Inner = new ComplexModel { - Identities = new List { "1.1", "1.2", "1.3" }, + Identities = ["1.1", "1.2", "1.3"], Identity = "0.0", OtherProperty = "innerothers", Inner = new ComplexModel { - Identities = new List { "1.1.1", "1.1.2" }, + Identities = ["1.1.1", "1.1.2"], Identity = "0.0.0", OtherProperty = "innersinner" } }, OtherProperty = "others", - InnerModels = new List - { + InnerModels = + [ new() { Identity = "2.1", @@ -100,7 +100,7 @@ public void TestComplexModelWithUniqueIdentityReferenceAttributeShouldSucceed() Identity = "2.2", CrefType = TestCrefType.Href } - } + ] }; var context = Handle(model); @@ -238,7 +238,7 @@ public void TesteModelWithIListMarkdownContentAttributeShouldSucceed() { var model = new MarkdownModelWithIList { - ListContent = new List { "*list*" }, + ListContent = ["*list*"], ArrayContent = ["@xref", "*content"] }; @@ -295,7 +295,7 @@ private static HandleModelAttributesContext GetDefaultContext() { return new HandleModelAttributesContext { - Host = new HostService(Enumerable.Empty()) + Host = new HostService([]) { MarkdownService = new MarkdigMarkdownService(new MarkdownServiceParameters { BasePath = string.Empty }), SourceFiles = new Dictionary diff --git a/test/Docfx.Build.OverwriteDocuments.Tests/OverwriteDocumentModelCreatorTest.cs b/test/Docfx.Build.OverwriteDocuments.Tests/OverwriteDocumentModelCreatorTest.cs index b4f82ef9148..01dbcbe25ee 100644 --- a/test/Docfx.Build.OverwriteDocuments.Tests/OverwriteDocumentModelCreatorTest.cs +++ b/test/Docfx.Build.OverwriteDocuments.Tests/OverwriteDocumentModelCreatorTest.cs @@ -58,7 +58,7 @@ public void ContentConvertTest() }); } - var contentsMetadata = new OverwriteDocumentModelCreator("test.yml.md").ConvertContents(new Dictionary(), contents); + var contentsMetadata = new OverwriteDocumentModelCreator("test.yml.md").ConvertContents([], contents); Assert.Equal(3, contentsMetadata.Count); Assert.Equal("summary,return,function", ExtractDictionaryKeys(contentsMetadata)); Assert.Equal(2, ((Dictionary)contentsMetadata["return"]).Count); @@ -79,26 +79,27 @@ public void ContentConvertTest() public void DuplicateOPathInMarkdownSectionTest() { var testOPath = "function/parameters"; - var contents = new List(); - - contents.Add(new MarkdownPropertyModel - { - PropertyName = testOPath, - PropertyNameSource = Markdown.Parse($"## `{testOPath}`")[0], - PropertyValue = Markdown.Parse("test1").ToList() - }); - contents.Add(new MarkdownPropertyModel + var contents = new List { - PropertyName = testOPath, - PropertyNameSource = Markdown.Parse($"## `{testOPath}`")[0], - PropertyValue = Markdown.Parse("test2").ToList() - }); + new MarkdownPropertyModel + { + PropertyName = testOPath, + PropertyNameSource = Markdown.Parse($"## `{testOPath}`")[0], + PropertyValue = Markdown.Parse("test1").ToList() + }, + new MarkdownPropertyModel + { + PropertyName = testOPath, + PropertyNameSource = Markdown.Parse($"## `{testOPath}`")[0], + PropertyValue = Markdown.Parse("test2").ToList() + } + }; Dictionary contentsMetadata; Logger.RegisterListener(_listener); try { - contentsMetadata = new OverwriteDocumentModelCreator("test.yml.md").ConvertContents(new Dictionary(), contents); + contentsMetadata = new OverwriteDocumentModelCreator("test.yml.md").ConvertContents([], contents); } finally { @@ -188,7 +189,7 @@ public void InvalidOPathsTest1() }); } - var ex = Assert.Throws(() => new OverwriteDocumentModelCreator("test.yml.md").ConvertContents(new Dictionary(), contents)); + var ex = Assert.Throws(() => new OverwriteDocumentModelCreator("test.yml.md").ConvertContents([], contents)); Assert.Equal( "A(parameters) is not expected to be an array like \"A[c=d]/B\", however it is used as an array in line 0 with `parameters[id=\"para1\"]/...`", ex.Message); @@ -215,7 +216,7 @@ public void InvalidOPathsTest2() }); } - var ex = Assert.Throws(() => new OverwriteDocumentModelCreator("test.yml.md").ConvertContents(new Dictionary(), contents)); + var ex = Assert.Throws(() => new OverwriteDocumentModelCreator("test.yml.md").ConvertContents([], contents)); Assert.Equal( "A(parameters) is not expected to be an object like \"A/B\", however it is used as an object in line 0 with `parameters/...`", ex.Message); diff --git a/test/Docfx.Build.RestApi.WithPlugins.Tests/SplitRestApiToOperationLevelTest.cs b/test/Docfx.Build.RestApi.WithPlugins.Tests/SplitRestApiToOperationLevelTest.cs index 4f9f8656300..db65cfef4c8 100644 --- a/test/Docfx.Build.RestApi.WithPlugins.Tests/SplitRestApiToOperationLevelTest.cs +++ b/test/Docfx.Build.RestApi.WithPlugins.Tests/SplitRestApiToOperationLevelTest.cs @@ -36,7 +36,7 @@ public SplitRestApiToOperationLevelTest() RawModelExportSettings = { Export = true }, TransformDocument = true, }; - _templateManager = new TemplateManager(new List { "template" }, null, "TestData/"); + _templateManager = new TemplateManager(["template"], null, "TestData/"); } [Fact] diff --git a/test/Docfx.Build.SchemaDriven.Tests/SchemaFragmentsIteratorTest.cs b/test/Docfx.Build.SchemaDriven.Tests/SchemaFragmentsIteratorTest.cs index 35f256a0879..a0d6cbcb63b 100644 --- a/test/Docfx.Build.SchemaDriven.Tests/SchemaFragmentsIteratorTest.cs +++ b/test/Docfx.Build.SchemaDriven.Tests/SchemaFragmentsIteratorTest.cs @@ -24,7 +24,7 @@ public void TestSchemaFragmentsIterator() } // act - iterator.Traverse(yamlStream.Documents[0].RootNode, new Dictionary(), schema); + iterator.Traverse(yamlStream.Documents[0].RootNode, [], schema); // assert Assert.Single(counter.ExistingUids); diff --git a/test/Docfx.Build.Tests/ConceptualDocumentProcessorTest.cs b/test/Docfx.Build.Tests/ConceptualDocumentProcessorTest.cs index 4d4c7961e93..27bd7e80e49 100644 --- a/test/Docfx.Build.Tests/ConceptualDocumentProcessorTest.cs +++ b/test/Docfx.Build.Tests/ConceptualDocumentProcessorTest.cs @@ -44,7 +44,7 @@ public ConceptualDocumentProcessorTest() // Prepare conceptual template var templateCreator = new FileCreator(_templateFolder); var file = templateCreator.CreateFile("{{{conceptual}}}", "conceptual.html.tmpl", "default"); - _templateManager = new TemplateManager(new List { "default" }, null, _templateFolder); + _templateManager = new TemplateManager(["default"], null, _templateFolder); } public override void Dispose() diff --git a/test/Docfx.Build.Tests/DocumentBuilderTest.cs b/test/Docfx.Build.Tests/DocumentBuilderTest.cs index 67b4ae138f4..69ec1562538 100644 --- a/test/Docfx.Build.Tests/DocumentBuilderTest.cs +++ b/test/Docfx.Build.Tests/DocumentBuilderTest.cs @@ -48,19 +48,17 @@ public void TestBuild() CreateFile("conceptual.html.primary.tmpl", "{{{conceptual}}}", _templateFolder); var tocFile = CreateFile("toc.md", - new[] - { + [ "# [test1](test.md#bookmark)", "## [test2](test/test.md)", "## [GitHub](GitHub.md?shouldBeAbbreviated=true#test)", "# Api", "## [Console](@System.Console)", "## [ConsoleColor](xref:System.ConsoleColor)", - }, + ], _inputFolder); var conceptualFile = CreateFile("test.md", - new[] - { + [ "---", "uid: XRef1", "a: b", @@ -96,11 +94,10 @@ public void TestBuild() "Test href generator: [Git](Git.md?shouldBeAbbreviated=true#test)", "

", "test", - }, + ], _inputFolder); var conceptualFile2 = CreateFile("test/test.md", - new[] - { + [ "---", "uid: XRef2", "a: b", @@ -112,11 +109,10 @@ public void TestBuild() "Test link: [link text](../test.md)", "

", "test", - }, + ], _inputFolder); var conceptualFile3 = CreateFile("check-xrefmap.md", - new[] - { + [ "---", "uid: XRef1", "a: b", @@ -125,11 +121,10 @@ public void TestBuild() "---", "# Hello World", "Test xrefmap with duplicate uid in different files: XRef1 should be recorded with file check-xrefmap.md" - }, + ], _inputFolder); var conceptualFile4 = CreateFile("test/verify-xrefmap.md", - new[] - { + [ "---", "uid: XRef2", "a: b", @@ -138,7 +133,7 @@ public void TestBuild() "---", "# Hello World", "Test xrefmap with duplicate uid in different files: XRef2 should be recorded with file test/test.md" - }, + ], _inputFolder); FileCollection files = new(Directory.GetCurrentDirectory()); @@ -320,34 +315,32 @@ public void TestBuildConceptualWithTemplateShouldSucceed() ", _templateFolder); CreateFile("conceptual.html.tmpl", "{{.}}", _templateFolder); var conceptualFile = CreateFile("test.md", - new[] - { + [ "---", "uid: XRef1", "---", "# Hello World", "Test link: [link text](test/test.md)", "test", - }, + ], _inputFolder); var conceptualFile2 = CreateFile("test/test.md", - new[] - { + [ "---", "uid: XRef2", "---", "test", - }, + ], _inputFolder); - var tocFile = CreateFile("toc.md", new[] - { + var tocFile = CreateFile("toc.md", + [ "#[Test](test.md)" - }, + ], _inputFolder); - var tocFile2 = CreateFile("test/toc.md", new[] - { + var tocFile2 = CreateFile("test/toc.md", + [ "#[Test](test.md)" - }, + ], _inputFolder); FileCollection files = new(Directory.GetCurrentDirectory()); files.Add(DocumentType.Article, new[] { conceptualFile, conceptualFile2, tocFile, tocFile2 }); @@ -517,15 +510,13 @@ public void TestBuildWithInvalidPath() CreateFile("conceptual.html.primary.tmpl", "{{{conceptual}}}", _templateFolder); var tocFile = CreateFile("toc.md", - new[] - { + [ "# [test1](test.md)", "## [test2](test/test.md)", - }, + ], _inputFolder); var conceptualFile = CreateFile("test.md", - new[] - { + [ "# Hello World", "Test link: [link 1](test/test.md)", "Test link: [link 2](http://www.microsoft.com)", @@ -537,14 +528,13 @@ public void TestBuildWithInvalidPath() "Test link: [link 8](test/test.md#top)", "Test link: [link 9](a.md#top)", "Test link: [link 10](#top)", - }, + ], _inputFolder); var conceptualFile2 = CreateFile("test/test.md", - new[] - { + [ "# Hello World", "Test link: [link 1](../test.md)", - }, + ], _inputFolder); FileCollection files = new(Directory.GetCurrentDirectory()); @@ -630,19 +620,17 @@ public void TestBuildWithInvalidPathWithTokenAndMapping() CreateFile("conceptual.html.primary.tmpl", "{{{conceptual}}}", _templateFolder); var conceptualFile = CreateFile("a/a.md", - new[] - { + [ "[link a](invalid-a.md)", "[link b](../b/invalid-b.md)", "[!include[](../b/token.md)]", - }, + ], _inputFolder); var tokenFile = CreateFile("b/token.md", - new[] - { + [ "[link a](../a/invalid-a.md)", "[link b](invalid-b.md)", - }, + ], _inputFolder); FileCollection files = new(Directory.GetCurrentDirectory()); @@ -651,7 +639,7 @@ public void TestBuildWithInvalidPathWithTokenAndMapping() BuildDocument( files, - new Dictionary(), + [], templateFolder: _templateFolder); { @@ -672,7 +660,7 @@ public void TestBuildWithInvalidPathWithTokenAndMapping() private class FakeResponseHandler : DelegatingHandler { - private readonly Dictionary _fakeResponses = new(); + private readonly Dictionary _fakeResponses = []; protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { @@ -703,7 +691,7 @@ public void TestBuildWithMultipleVersion() BuildDocument( files, - new Dictionary(), + [], templateFolder: _templateFolder, versionDir: versionDir); @@ -740,10 +728,10 @@ private void BuildDocument( OutputBaseDir = Path.Combine(Directory.GetCurrentDirectory(), _outputFolder), ApplyTemplateSettings = applyTemplateSettings, Metadata = metadata?.ToImmutableDictionary(), - TemplateManager = new TemplateManager(new List { _templateFolder }, null, null), + TemplateManager = new TemplateManager([_templateFolder], null, null), TemplateDir = templateFolder, VersionDir = versionDir, - XRefMaps = ImmutableArray.Create("TestData/xrefmap.yml"), + XRefMaps = ["TestData/xrefmap.yml"], }; builder.Build(parameters); } diff --git a/test/Docfx.Build.Tests/DocumentProcessors/YamlDocumentModel.cs b/test/Docfx.Build.Tests/DocumentProcessors/YamlDocumentModel.cs index d05c828c08e..8623653babe 100644 --- a/test/Docfx.Build.Tests/DocumentProcessors/YamlDocumentModel.cs +++ b/test/Docfx.Build.Tests/DocumentProcessors/YamlDocumentModel.cs @@ -20,10 +20,10 @@ public class YamlDocumentModel [ExtensibleMember] [Newtonsoft.Json.JsonExtensionData] [System.Text.Json.Serialization.JsonExtensionData] - public Dictionary Data { get; set; } = new(); + public Dictionary Data { get; set; } = []; [YamlMember(Alias = "metadata")] [JsonProperty("metadata")] [JsonPropertyName("metadata")] - public Dictionary Metadata { get; set; } = new(); + public Dictionary Metadata { get; set; } = []; } diff --git a/test/Docfx.Build.Tests/FileMetadataHelperTest.cs b/test/Docfx.Build.Tests/FileMetadataHelperTest.cs index 0c3fd561d31..2768b57ea0a 100644 --- a/test/Docfx.Build.Tests/FileMetadataHelperTest.cs +++ b/test/Docfx.Build.Tests/FileMetadataHelperTest.cs @@ -122,18 +122,24 @@ public void TestGetChangedGlobs_CrossGlobsChanged() var patterns = new string[] { "*md", "*.m", "abc", "/[]\\*.cs", "*/*.cs", "**" }; var left = new FileMetadata(baseDir, new Dictionary> { - ["meta"] = ImmutableArray.Create( + ["meta"] = + + [ new FileMetadataItem(new GlobMatcher(patterns[0]), "meta", 1L), new FileMetadataItem(new GlobMatcher(patterns[1]), "meta", true) - ) +, + ] }); var right = new FileMetadata(baseDir, new Dictionary> { - ["meta"] = ImmutableArray.Create( + ["meta"] = + + [ new FileMetadataItem(new GlobMatcher(patterns[1]), "meta", true), new FileMetadataItem(new GlobMatcher(patterns[2]), "meta", "string") - ) +, + ] }); var actualResults = FileMetadataHelper.GetChangedGlobs(left, right).ToList(); @@ -150,17 +156,18 @@ public void TestGetChangedGlobs_ReduceGlobsChanged() var patterns = new string[] { "*md", "*.m", "abc", "/[]\\*.cs", "*/*.cs", "**" }; var left = new FileMetadata(baseDir, new Dictionary> { - ["meta"] = ImmutableArray.Create( + ["meta"] = + + [ new FileMetadataItem(new GlobMatcher(patterns[0]), "meta", 1L), new FileMetadataItem(new GlobMatcher(patterns[1]), "meta", true) - ) +, + ] }); var right = new FileMetadata(baseDir, new Dictionary> { - ["meta"] = ImmutableArray.Create( - new FileMetadataItem(new GlobMatcher(patterns[0]), "meta", 1L) - ) + ["meta"] = [new FileMetadataItem(new GlobMatcher(patterns[0]), "meta", 1L)] }); var actualResults = FileMetadataHelper.GetChangedGlobs(left, right).ToList(); @@ -176,19 +183,25 @@ public void TestGetChangedGlobs_IncreaseGlobsChanged() var patterns = new string[] { "*md", "*.m", "abc" }; var left = new FileMetadata(baseDir, new Dictionary> { - ["meta"] = ImmutableArray.Create( + ["meta"] = + + [ new FileMetadataItem(new GlobMatcher(patterns[0]), "meta", 1L), new FileMetadataItem(new GlobMatcher(patterns[1]), "meta", true) - ) +, + ] }); var right = new FileMetadata(baseDir, new Dictionary> { - ["meta"] = ImmutableArray.Create( + ["meta"] = + + [ new FileMetadataItem(new GlobMatcher(patterns[0]), "meta", 1L), new FileMetadataItem(new GlobMatcher(patterns[1]), "meta", true), new FileMetadataItem(new GlobMatcher(patterns[2]), "meta", "string") - ) +, + ] }); var actualResults = FileMetadataHelper.GetChangedGlobs(left, right).ToList(); @@ -204,12 +217,15 @@ public void TestGetChangedGlobs_Changed() var patterns = new string[] { "*md", "*.m", "abc", "/[]\\*.cs", "*/*.cs", "**" }; var left = new FileMetadata(baseDir, new Dictionary> { - ["meta"] = ImmutableArray.Create( + ["meta"] = + + [ new FileMetadataItem(new GlobMatcher(patterns[0]), "meta", 1L), new FileMetadataItem(new GlobMatcher(patterns[1]), "meta", true), new FileMetadataItem(new GlobMatcher(patterns[3]), "meta", new Dictionary { ["key"] = "2" }), new FileMetadataItem(new GlobMatcher(patterns[5]), "meta", new Dictionary { ["key"] = new object[] { "1", "2" } }) - ) +, + ] }); var right = new FileMetadata(baseDir, new Dictionary> @@ -238,18 +254,20 @@ public void TestGetChangedGlobs_Changed_Reverse() var patterns = new string[] { "*md", "*.m" }; var left = new FileMetadata(baseDir, new Dictionary> { - ["meta"] = ImmutableArray.Create( + ["meta"] = + [ new FileMetadataItem(new GlobMatcher(patterns[0]), "meta", 1L), new FileMetadataItem(new GlobMatcher(patterns[1]), "meta", true) - ) + ] }); var right = new FileMetadata(baseDir, new Dictionary> { - ["meta"] = ImmutableArray.Create( + ["meta"] = + [ new FileMetadataItem(new GlobMatcher(patterns[1]), "meta", true), - new FileMetadataItem(new GlobMatcher(patterns[0]), "meta", 1L) - ) + new FileMetadataItem(new GlobMatcher(patterns[0]), "meta", 1L), + ] }); var actualResults = FileMetadataHelper.GetChangedGlobs(left, right).ToList(); diff --git a/test/Docfx.Build.Tests/JintProcessorHelperTest.cs b/test/Docfx.Build.Tests/JintProcessorHelperTest.cs index e520143599f..ff772e00a34 100644 --- a/test/Docfx.Build.Tests/JintProcessorHelperTest.cs +++ b/test/Docfx.Build.Tests/JintProcessorHelperTest.cs @@ -52,6 +52,6 @@ private sealed class TestData public Dictionary ValueDict { get; set; } = new() { [1] = "Value1", ["key"] = 2 }; - public List ValueList { get; set; } = new() { "ValueA", "ValueB" }; + public List ValueList { get; set; } = ["ValueA", "ValueB"]; } } diff --git a/test/Docfx.Build.Tests/TemplateProcessorUnitTest.cs b/test/Docfx.Build.Tests/TemplateProcessorUnitTest.cs index afa8b8cfbc1..097a821e3e6 100644 --- a/test/Docfx.Build.Tests/TemplateProcessorUnitTest.cs +++ b/test/Docfx.Build.Tests/TemplateProcessorUnitTest.cs @@ -61,6 +61,6 @@ private ManifestItem Process(string documentType, string fileName, object conten LocalPathFromRoot = fileName, Content = content, }; - return processor.Process(new List { inputItem }, new ApplyTemplateSettings(_inputFolder, _outputFolder))[0]; + return processor.Process([inputItem], new ApplyTemplateSettings(_inputFolder, _outputFolder))[0]; } } diff --git a/test/Docfx.Build.Tests/TocDocumentProcessorTest.cs b/test/Docfx.Build.Tests/TocDocumentProcessorTest.cs index 6b2dbc2ca47..335eb94e64a 100644 --- a/test/Docfx.Build.Tests/TocDocumentProcessorTest.cs +++ b/test/Docfx.Build.Tests/TocDocumentProcessorTest.cs @@ -60,15 +60,15 @@ public void ProcessMarkdownTocWithComplexHrefShouldSucceed() var model = JsonUtility.Deserialize(outputRawModelPath); var expectedModel = new TocItemViewModel { - Items = new List - { + Items = + [ new() { Name = "Constructor", Href = $"{href}.md", TopicHref = $"{href}.md", } - } + ] }; AssertTocEqual(expectedModel, model); @@ -94,27 +94,27 @@ public void ProcessMarkdownTocWithAbsoluteHrefShouldSucceed() var model = JsonUtility.Deserialize(outputRawModelPath); var expectedModel = new TocItemViewModel { - Items = new List - { + Items = + [ new() { Name = "Topic1 Language", Href = "/href1", TopicHref = "/href1", - Items = new List - { + Items = + [ new() { Name = "Topic1.1 Language C#", - Items = new List - { + Items = + [ new() { Name = "Topic1.1.1", Href = "/href1.1.1", TopicHref = "/href1.1.1" } - } + ] }, new() { @@ -122,7 +122,7 @@ public void ProcessMarkdownTocWithAbsoluteHrefShouldSucceed() Href = string.Empty, TopicHref = string.Empty } - } + ] }, new() { @@ -130,7 +130,7 @@ public void ProcessMarkdownTocWithAbsoluteHrefShouldSucceed() Href = "http://href.com", TopicHref = "http://href.com" } - } + ] }; AssertTocEqual(expectedModel, model); @@ -158,29 +158,29 @@ public void ProcessMarkdownTocWithRelativeHrefShouldSucceed() var model = JsonUtility.Deserialize(outputRawModelPath); var expectedModel = new TocItemViewModel { - Items = new List - { + Items = + [ new() { Name = "Topic1", Href = "/href1", TopicHref = "/href1", - Items = new List - { + Items = + [ new() { Name = "Topic1.1", Href = file1, TopicHref = file1, - Items = new List - { + Items = + [ new() { Name = "Topic1.1.1", Href = file2, TopicHref = file2 } - } + ] }, new() { @@ -188,7 +188,7 @@ public void ProcessMarkdownTocWithRelativeHrefShouldSucceed() Href = string.Empty, TopicHref = string.Empty } - } + ] }, new() { @@ -202,7 +202,7 @@ public void ProcessMarkdownTocWithRelativeHrefShouldSucceed() Href = "invalid.md", TopicHref = "invalid.md" } - } + ] }; AssertTocEqual(expectedModel, model); @@ -238,15 +238,15 @@ public void ProcessYamlTocWithFolderShouldSucceed() var model = JsonUtility.Deserialize(outputRawModelPath); var expectedModel = new TocItemViewModel { - Items = new List - { + Items = + [ new() { Name = "Topic1", Href = file1, TopicHref = file1, - Items = new List - { + Items = + [ new() { Name = "Topic1.1", @@ -262,7 +262,7 @@ public void ProcessYamlTocWithFolderShouldSucceed() TopicHref = file1, TocHref = "sub/toc.md", } - } + ] }, new() { @@ -271,7 +271,7 @@ public void ProcessYamlTocWithFolderShouldSucceed() TopicHref = file2, TocHref = "sub/toc.md", } - } + ] }; AssertTocEqual(expectedModel, model); @@ -317,24 +317,24 @@ public void ProcessYamlTocWithMetadataShouldSucceed() var expectedModel = new TocItemViewModel { - Items = new List - { + Items = + [ new() { Name = "Topic1", Href = file1, TopicHref = file1, - Items = new List - { + Items = + [ new() { Name = "Topic1.1", Href = file1, // For relative file, href keeps unchanged TopicHref = file1, } - } + ] } - } + ] }; AssertTocEqual(expectedModel, model); } @@ -386,23 +386,23 @@ public void ProcessYamlTocWithReferencedTocShouldSucceed() var model = JsonUtility.Deserialize(outputRawModelPath); var expectedModel = new TocItemViewModel { - Items = new List - { + Items = + [ new() { Name = "Topic1", Href = file1, TopicHref = file1, - Items = new List - { + Items = + [ new() { Name = "Topic1.1", IncludedFrom = "~/sub1/toc.md", Href = null, // For referenced toc, the content from the referenced toc is expanded as the items of current toc, and href is cleared TopicHref = null, - Items = new List - { + Items = + [ new() { Name = "Topic", @@ -413,8 +413,8 @@ public void ProcessYamlTocWithReferencedTocShouldSucceed() { Name = "ReferencedToc", IncludedFrom = "~/sub1/sub2/toc.yml", - Items = new List - { + Items = + [ new() { Name = "Topic", @@ -427,22 +427,22 @@ public void ProcessYamlTocWithReferencedTocShouldSucceed() Href = "sub1/sub2/a/b/c.md", TopicHref = "sub1/sub2/a/b/c.md", } - } + ] }, new() { Name = "ReferencedToc2", IncludedFrom = "~/sub1/sub3/toc.md", - Items = new List - { + Items = + [ new() { Name = "Not-existed-md", Href = "sub1/sub3/sub2/notexist.md", TopicHref = "sub1/sub3/sub2/notexist.md", }, - } + ] }, new() { @@ -450,7 +450,7 @@ public void ProcessYamlTocWithReferencedTocShouldSucceed() Href = "sub1/sub2/notexist.md", TopicHref = "sub1/sub2/notexist.md", } - } + ] }, new() { @@ -459,8 +459,8 @@ public void ProcessYamlTocWithReferencedTocShouldSucceed() TopicHref = file1, IncludedFrom = "~/sub1/toc.md", Homepage = file1, - Items = new List - { + Items = + [ new() { Name = "Topic", @@ -471,8 +471,8 @@ public void ProcessYamlTocWithReferencedTocShouldSucceed() { Name = "ReferencedToc", IncludedFrom = "~/sub1/sub2/toc.yml", - Items = new List - { + Items = + [ new() { Name = "Topic", @@ -485,21 +485,21 @@ public void ProcessYamlTocWithReferencedTocShouldSucceed() Href = "sub1/sub2/a/b/c.md", TopicHref = "sub1/sub2/a/b/c.md", } - } + ] }, new() { Name = "ReferencedToc2", IncludedFrom = "~/sub1/sub3/toc.md", - Items = new List - { + Items = + [ new() { Name = "Not-existed-md", Href = "sub1/sub3/sub2/notexist.md", TopicHref = "sub1/sub3/sub2/notexist.md", } - } + ] }, new() { @@ -507,17 +507,17 @@ public void ProcessYamlTocWithReferencedTocShouldSucceed() Href = "sub1/sub2/notexist.md", TopicHref = "sub1/sub2/notexist.md", } - } + ] } - } + ] }, new() { Name = "Topic2", IncludedFrom = "~/sub1/sub2/toc.yml", Href = null, - Items = new List - { + Items = + [ new() { Name = "Topic", @@ -530,9 +530,9 @@ public void ProcessYamlTocWithReferencedTocShouldSucceed() Href = "sub1/sub2/a/b/c.md", TopicHref = "sub1/sub2/a/b/c.md", } - } + ] } - } + ] }; AssertTocEqual(expectedModel, model); @@ -575,7 +575,7 @@ public void ProcessMarkdownTocWithNonExistentReferencedTocShouldLogError() var files = new FileCollection(_inputFolder); files.Add(DocumentType.Article, new[] { toc }); - var listener = TestLoggerListener.CreateLoggerListenerWithCodesFilter(new List { WarningCodes.Build.InvalidTocInclude }); + var listener = TestLoggerListener.CreateLoggerListenerWithCodesFilter([WarningCodes.Build.InvalidTocInclude]); Logger.RegisterListener(listener); BuildDocument(files); @@ -599,7 +599,7 @@ public void ProcessYamlTocWithNonExistentReferencedTocShouldLogError() var files = new FileCollection(_inputFolder); files.Add(DocumentType.Article, new[] { toc }); - var listener = TestLoggerListener.CreateLoggerListenerWithCodesFilter(new List { WarningCodes.Build.InvalidTocInclude }); + var listener = TestLoggerListener.CreateLoggerListenerWithCodesFilter([WarningCodes.Build.InvalidTocInclude]); Logger.RegisterListener(listener); BuildDocument(files); Logger.UnregisterListener(listener); @@ -645,8 +645,8 @@ public void ProcessYamlTocWithTocHrefShouldSucceed() var model = JsonUtility.Deserialize(outputRawModelPath); var expectedModel = new TocItemViewModel { - Items = new List - { + Items = + [ new() { Name = "Topic1", @@ -654,8 +654,8 @@ public void ProcessYamlTocWithTocHrefShouldSucceed() TocHref = "/Topic1/", Homepage = "/Topic1/index.html", TopicHref = "/Topic1/index.html", - Items = new List - { + Items = + [ new() { Name = "Topic1.1", @@ -672,7 +672,7 @@ public void ProcessYamlTocWithTocHrefShouldSucceed() Homepage = "/Topic1.2/index.html", TopicHref = "/Topic1.2/index.html", } - } + ] }, new() { @@ -682,7 +682,7 @@ public void ProcessYamlTocWithTocHrefShouldSucceed() TopicHref = file2, Homepage = file2, } - } + ] }; AssertTocEqual(expectedModel, model); @@ -813,7 +813,7 @@ public void WarningShouldBeFromIncludedToc() // Act var listener = TestLoggerListener.CreateLoggerListenerWithCodesFilter( - new List { WarningCodes.Build.InvalidFileLink, WarningCodes.Build.UidNotFound }); + [WarningCodes.Build.InvalidFileLink, WarningCodes.Build.UidNotFound]); Logger.RegisterListener(listener); BuildDocument(files); Logger.UnregisterListener(listener); @@ -841,7 +841,7 @@ public void UrlDecodeHrefInYamlToc() // Act var listener = TestLoggerListener.CreateLoggerListenerWithCodesFilter( - new List { WarningCodes.Build.InvalidFileLink }); + [WarningCodes.Build.InvalidFileLink]); Logger.RegisterListener(listener); BuildDocument(files); Logger.UnregisterListener(listener); @@ -863,7 +863,7 @@ public void UrlDecodeHrefInMarkdownToc() // Act var listener = TestLoggerListener.CreateLoggerListenerWithCodesFilter( - new List { WarningCodes.Build.InvalidFileLink }); + [WarningCodes.Build.InvalidFileLink]); Logger.RegisterListener(listener); BuildDocument(files); Logger.UnregisterListener(listener); diff --git a/test/Docfx.Build.Tests/TocRestructureTest.cs b/test/Docfx.Build.Tests/TocRestructureTest.cs index b25c761b68f..f1308faf7c9 100644 --- a/test/Docfx.Build.Tests/TocRestructureTest.cs +++ b/test/Docfx.Build.Tests/TocRestructureTest.cs @@ -259,7 +259,7 @@ private TocItemViewModel GetTocItem(string layout) } var root = new TocItemViewModel { - Items = new() + Items = [] }; var stack = new Stack>(); stack.Push(Tuple.Create(new LineInfo @@ -280,7 +280,7 @@ private TocItemViewModel GetTocItem(string layout) var parent = stack.Peek(); if (parent.Item2.Items == null) { - parent.Item2.Items = new(); + parent.Item2.Items = []; } parent.Item2.Items.Add(item); @@ -291,8 +291,8 @@ private TocItemViewModel GetTocItem(string layout) private IEnumerable GetLines(string layout) { - return layout.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries) - .SelectMany(s => s.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries)) + return layout.Split(["\r\n"], StringSplitOptions.RemoveEmptyEntries) + .SelectMany(s => s.Split(["\n"], StringSplitOptions.RemoveEmptyEntries)) .Where(s => !string.IsNullOrWhiteSpace(s)).Select(GetLineInfo); } diff --git a/test/Docfx.Build.Tests/XRefMapSerializationTest.cs b/test/Docfx.Build.Tests/XRefMapSerializationTest.cs index 6925b4234f0..8ab4489200b 100644 --- a/test/Docfx.Build.Tests/XRefMapSerializationTest.cs +++ b/test/Docfx.Build.Tests/XRefMapSerializationTest.cs @@ -19,16 +19,16 @@ public void XRefMapSerializationRoundTripTest() BaseUrl = "http://localhost", Sorted = true, HrefUpdated = null, - Redirections = new List - { + Redirections = + [ new() { Href = "Dummy", UidPrefix = "Dummy" }, - }, - References = new List - { + ], + References = + [ new(new Dictionary { ["Additional1"] = "Dummy", @@ -40,7 +40,7 @@ public void XRefMapSerializationRoundTripTest() CommentId ="Dummy", IsSpec = true, }, - }, + ], Others = new Dictionary { ["StringValue"] = "Dummy", diff --git a/test/Docfx.Build.UniversalReference.Tests/UniversalReferenceDocumentProcessorTest.cs b/test/Docfx.Build.UniversalReference.Tests/UniversalReferenceDocumentProcessorTest.cs index 04240ae3d34..acad455356f 100644 --- a/test/Docfx.Build.UniversalReference.Tests/UniversalReferenceDocumentProcessorTest.cs +++ b/test/Docfx.Build.UniversalReference.Tests/UniversalReferenceDocumentProcessorTest.cs @@ -34,7 +34,7 @@ public UniversalReferenceDocumentProcessorTest() RawModelExportSettings = { Export = true }, TransformDocument = true, }; - _templateManager = new TemplateManager(new List { "template" }, null, "TestData/"); + _templateManager = new TemplateManager(["template"], null, "TestData/"); } #region Python diff --git a/test/Docfx.Common.Tests/CompositeDictionaryTest.cs b/test/Docfx.Common.Tests/CompositeDictionaryTest.cs index 2bbe7ee86b0..ff8f6e735bf 100644 --- a/test/Docfx.Common.Tests/CompositeDictionaryTest.cs +++ b/test/Docfx.Common.Tests/CompositeDictionaryTest.cs @@ -105,9 +105,9 @@ public void TestThrowCaseForCompositeDictionary() private sealed class C { - public Dictionary D1 { get; } = new(); - public SortedDictionary D2 { get; } = new(); - public SortedList D3 { get; } = new(); + public Dictionary D1 { get; } = []; + public SortedDictionary D2 { get; } = []; + public SortedList D3 { get; } = []; private CompositeDictionary _cd; public CompositeDictionary CD { diff --git a/test/Docfx.Common.Tests/ConvertToObjectHelperTest.cs b/test/Docfx.Common.Tests/ConvertToObjectHelperTest.cs index 138b4c9795f..bb39a7e9f56 100644 --- a/test/Docfx.Common.Tests/ConvertToObjectHelperTest.cs +++ b/test/Docfx.Common.Tests/ConvertToObjectHelperTest.cs @@ -30,8 +30,8 @@ public void ConvertComplexTypeToObjectShouldWork() var complexType = new ComplexType { String = "String", - List = new List(), - IntDictionary = new Dictionary() + List = [], + IntDictionary = [] }; var result = ConvertToObjectHelper.ConvertStrongTypeToObject(complexType); Assert.Equal(typeof(Dictionary), result.GetType()); @@ -45,8 +45,8 @@ public void ConvertComplexTypeWithJsonAttributeToObjectShouldUseAttributeAsPrope var complexType = new ComplexTypeWithJson { String = "String", - List = new List(), - IntDictionary = new Dictionary() + List = [], + IntDictionary = [] }; var result = ConvertToObjectHelper.ConvertStrongTypeToObject(complexType); Assert.Equal(typeof(Dictionary), result.GetType()); diff --git a/test/Docfx.Common.Tests/PathUtilityTest.cs b/test/Docfx.Common.Tests/PathUtilityTest.cs index aaceedef989..5dba7472edd 100644 --- a/test/Docfx.Common.Tests/PathUtilityTest.cs +++ b/test/Docfx.Common.Tests/PathUtilityTest.cs @@ -46,10 +46,10 @@ private static class TestData { "/temp/dir", "/temp/dir/subdir/", "subdir/"}, // If target path endsWith directory separator char. resolved path should contain directory separator. }; - public static TheoryData EscapedPaths = new() - { + public static TheoryData EscapedPaths = + [ "EscapedHypen(%2D).md", // Contains escaped hypen char "EscapedSpace(%20)_with_NonAsciiChar(α).md", // Contains escaped space char and non-unicode char - }; + ]; } } diff --git a/test/Docfx.Common.Tests/YamlSerializationTest.cs b/test/Docfx.Common.Tests/YamlSerializationTest.cs index a2b1315ffce..74fb179a5c3 100644 --- a/test/Docfx.Common.Tests/YamlSerializationTest.cs +++ b/test/Docfx.Common.Tests/YamlSerializationTest.cs @@ -325,11 +325,11 @@ public void TestListOfClassWithExtensibleMembers() public class ClassWithExtensibleMembers : BasicClass { [ExtensibleMember("s.")] - public SortedDictionary StringExtensions { get; } = new(); + public SortedDictionary StringExtensions { get; } = []; [ExtensibleMember("i.")] - public SortedList IntegerExtensions { get; } = new(); + public SortedList IntegerExtensions { get; } = []; [ExtensibleMember()] - public Dictionary ObjectExtensions { get; } = new(); + public Dictionary ObjectExtensions { get; } = []; } [Fact] @@ -364,7 +364,7 @@ public void TestClassWithInterfaceMember() var sw = new StringWriter(); YamlUtility.Serialize(sw, new ClassWithInterfaceMember { - List = new List { "a" }, + List = ["a"], ReadOnlyList = new[] { "b" }, Collection = new Collection { "c" }, ReadOnlyCollection = ImmutableList.Create("d"), diff --git a/test/Docfx.Dotnet.Tests/ApiFilterUnitTest.cs b/test/Docfx.Dotnet.Tests/ApiFilterUnitTest.cs index 7f7babdf6d3..0a1f3a32b08 100644 --- a/test/Docfx.Dotnet.Tests/ApiFilterUnitTest.cs +++ b/test/Docfx.Dotnet.Tests/ApiFilterUnitTest.cs @@ -10,7 +10,7 @@ namespace Docfx.Dotnet.Tests; [Collection("docfx STA")] public class ApiFilterUnitTest { - private static readonly Dictionary EmptyMSBuildProperties = new(); + private static readonly Dictionary EmptyMSBuildProperties = []; [Fact] public void TestApiFilter() diff --git a/test/Docfx.Dotnet.Tests/GenerateMetadataFromCSUnitTest.cs b/test/Docfx.Dotnet.Tests/GenerateMetadataFromCSUnitTest.cs index 862bdf0d125..fbad40a99f4 100644 --- a/test/Docfx.Dotnet.Tests/GenerateMetadataFromCSUnitTest.cs +++ b/test/Docfx.Dotnet.Tests/GenerateMetadataFromCSUnitTest.cs @@ -12,7 +12,7 @@ namespace Docfx.Dotnet.Tests; [Collection("docfx STA")] public class GenerateMetadataFromCSUnitTest { - private static readonly Dictionary EmptyMSBuildProperties = new(); + private static readonly Dictionary EmptyMSBuildProperties = []; private static MetadataItem Verify(string code, ExtractMetadataConfig config = null, IDictionary msbuildProperties = null, MetadataReference[] references = null) { diff --git a/test/Docfx.Dotnet.Tests/GenerateMetadataFromVBUnitTest.cs b/test/Docfx.Dotnet.Tests/GenerateMetadataFromVBUnitTest.cs index 502a6144ca7..41c5d2d378d 100644 --- a/test/Docfx.Dotnet.Tests/GenerateMetadataFromVBUnitTest.cs +++ b/test/Docfx.Dotnet.Tests/GenerateMetadataFromVBUnitTest.cs @@ -11,7 +11,7 @@ namespace Docfx.Dotnet.Tests; [Collection("docfx STA")] public class GenerateMetadataFromVBUnitTest { - private static readonly Dictionary EmptyMSBuildProperties = new(); + private static readonly Dictionary EmptyMSBuildProperties = []; private static MetadataItem Verify(string code, ExtractMetadataConfig config = null, IDictionary msbuildProperties = null, MetadataReference[] references = null) { diff --git a/test/Docfx.MarkdigEngine.Extensions.Tests/TestUtility.cs b/test/Docfx.MarkdigEngine.Extensions.Tests/TestUtility.cs index 32d6ac85ba1..96c98606e4b 100644 --- a/test/Docfx.MarkdigEngine.Extensions.Tests/TestUtility.cs +++ b/test/Docfx.MarkdigEngine.Extensions.Tests/TestUtility.cs @@ -23,9 +23,9 @@ public static string VerifyMarkup( Dictionary notes = null, PlantUmlOptions plantUml = null) { - errors ??= Array.Empty(); - tokens ??= new Dictionary(); - files ??= new Dictionary(); + errors ??= []; + tokens ??= []; + files ??= []; optionalExtensions ??= []; var actualErrors = new List(); diff --git a/test/Docfx.MarkdigEngine.Tests/TestUtility/TestLoggerListener.cs b/test/Docfx.MarkdigEngine.Tests/TestUtility/TestLoggerListener.cs index f1f562fdcbb..5b3c1e0354f 100644 --- a/test/Docfx.MarkdigEngine.Tests/TestUtility/TestLoggerListener.cs +++ b/test/Docfx.MarkdigEngine.Tests/TestUtility/TestLoggerListener.cs @@ -7,7 +7,7 @@ namespace Docfx.MarkdigEngine.Tests; internal class TestLoggerListener : ILoggerListener { - public List Items { get; } = new(); + public List Items { get; } = []; public void Dispose() { diff --git a/test/Docfx.Tests.Common/TestBase.cs b/test/Docfx.Tests.Common/TestBase.cs index 77abe916218..b778e191d4f 100644 --- a/test/Docfx.Tests.Common/TestBase.cs +++ b/test/Docfx.Tests.Common/TestBase.cs @@ -8,7 +8,7 @@ namespace Docfx.Tests.Common; public class TestBase : IClassFixture, IDisposable { - private readonly List _folderCollection = new(); + private readonly List _folderCollection = []; private readonly object _locker = new(); protected string GetRandomFolder() diff --git a/test/Docfx.Tests.Common/TestListenerScope.cs b/test/Docfx.Tests.Common/TestListenerScope.cs index 9607a8c084c..13c43b8bc32 100644 --- a/test/Docfx.Tests.Common/TestListenerScope.cs +++ b/test/Docfx.Tests.Common/TestListenerScope.cs @@ -15,7 +15,7 @@ public class TestListenerScope : ILoggerListener, IDisposable public TestListenerScope(LogLevel logLevel = LogLevel.Warning) { _logLevel = logLevel; - s_items.Value = new(); + s_items.Value = []; Logger.RegisterListener(this); } diff --git a/test/Docfx.Tests.Common/TestLoggerListener.cs b/test/Docfx.Tests.Common/TestLoggerListener.cs index f284e2d53ca..c2cd6beaa8b 100644 --- a/test/Docfx.Tests.Common/TestLoggerListener.cs +++ b/test/Docfx.Tests.Common/TestLoggerListener.cs @@ -7,7 +7,7 @@ namespace Docfx.Tests.Common; public class TestLoggerListener : ILoggerListener { - public List Items { get; } = new(); + public List Items { get; } = []; private readonly Func _filter;