Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use some collection expressions #10292

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static object CreateInstance(Type type, Type[] typeArguments, Type[] argu
ArgumentNullException.ThrowIfNull(arguments);

var func = _createInstanceCache.GetOrAdd(
Tuple.Create(type, typeArguments ?? Type.EmptyTypes, argumentTypes),
Tuple.Create(type, typeArguments ?? [], argumentTypes),
GetCreateInstanceFunc);
return func(arguments);
}
Expand Down Expand Up @@ -150,7 +150,7 @@ public static IEnumerable<PropertyInfo> GetPublicProperties(Type type)
{
if (!type.IsVisible)
{
return Enumerable.Empty<PropertyInfo>();
return [];
}
return GetProperties(type, BindingFlags.Public | BindingFlags.Instance);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build.Common/Reference/OverwriteDocumentModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class OverwriteDocumentModel
[YamlIgnore]
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public ImmutableArray<string> Dependency { get; set; } = ImmutableArray<string>.Empty;
public ImmutableArray<string> Dependency { get; set; } = [];

public T ConvertTo<T>() where T : class
{
Expand Down
4 changes: 2 additions & 2 deletions src/Docfx.Build.Common/YamlHtmlPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public class YamlHtmlPart

public int EndLine { get; set; }

public ImmutableArray<string> LinkToFiles { get; set; } = ImmutableArray<string>.Empty;
public ImmutableArray<string> LinkToFiles { get; set; } = [];

public ImmutableHashSet<string> LinkToUids { get; set; } = ImmutableHashSet<string>.Empty;
public ImmutableHashSet<string> LinkToUids { get; set; } = [];

public ImmutableDictionary<string, object> YamlHeader { get; set; } = ImmutableDictionary<string, object>.Empty;

Expand Down
4 changes: 2 additions & 2 deletions src/Docfx.Build/DocumentBuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ from u in parameters.XRefMaps
#region Constructors that used by test code.

internal DocumentBuildContext(string buildOutputFolder)
: this(buildOutputFolder, Enumerable.Empty<FileAndType>(), ImmutableArray<string>.Empty, ImmutableArray<string>.Empty, 1, Directory.GetCurrentDirectory(), string.Empty, null, null) { }
: this(buildOutputFolder, [], [], [], 1, Directory.GetCurrentDirectory(), string.Empty, null, null) { }

private DocumentBuildContext(string buildOutputFolder, IEnumerable<FileAndType> allSourceFiles, ImmutableArray<string> externalReferencePackages, ImmutableArray<string> xrefMaps, int maxParallelism, string baseFolder, string versionName, ApplyTemplateSettings applyTemplateSetting, string rootTocPath)
: this(buildOutputFolder, allSourceFiles, externalReferencePackages, xrefMaps, maxParallelism, baseFolder, versionName, applyTemplateSetting, rootTocPath, null, null) { }
Expand Down Expand Up @@ -114,7 +114,7 @@ from u in xrefMaps

public ApplyTemplateSettings ApplyTemplateSettings { get; set; }

public ImmutableArray<string> ExternalReferencePackages { get; } = ImmutableArray<string>.Empty;
public ImmutableArray<string> ExternalReferencePackages { get; } = [];

public ImmutableDictionary<string, FileAndType> AllSourceFiles { get; }

Expand Down
4 changes: 2 additions & 2 deletions src/Docfx.Build/DocumentBuildParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public class DocumentBuildParameters

public string OutputBaseDir { get; set; }

public ImmutableArray<string> XRefMaps { get; set; } = ImmutableArray<string>.Empty;
public ImmutableArray<string> XRefMaps { get; set; } = [];

public ImmutableDictionary<string, object> Metadata { get; set; } = ImmutableDictionary<string, object>.Empty;

public FileMetadata FileMetadata { get; set; }

public ImmutableArray<string> PostProcessors { get; set; } = ImmutableArray<string>.Empty;
public ImmutableArray<string> PostProcessors { get; set; } = [];

public TemplateManager TemplateManager { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build/ResourceFiles/ResourceDocumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public override FileModel Load(FileAndType file, ImmutableDictionary<string, obj
{
return new FileModel(file, new Dictionary<string, object>())
{
Uids = ImmutableArray<UidDefinition>.Empty,
Uids = [],
LocalPathFromRoot = PathUtility.MakeRelativePath(
EnvironmentContext.BaseDirectory,
EnvironmentContext.FileAbstractLayer.GetPhysicalPath(file.File)),
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Common/CompositeDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CompositeDictionary

public CompositeDictionary()
{
_entries = ImmutableArray<Entry>.Empty;
_entries = [];
}

private CompositeDictionary(ImmutableArray<Entry> entries)
Expand Down
4 changes: 2 additions & 2 deletions src/Docfx.Dotnet/SymbolFormatter.Symbols.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ private class ParameterSymbol : IParameterSymbol

public NullableAnnotation NullableAnnotation => default;

public ImmutableArray<CustomModifier> CustomModifiers => ImmutableArray<CustomModifier>.Empty;
public ImmutableArray<CustomModifier> CustomModifiers => [];

public ImmutableArray<CustomModifier> RefCustomModifiers => ImmutableArray<CustomModifier>.Empty;
public ImmutableArray<CustomModifier> RefCustomModifiers => [];

public int Ordinal => 0;

Expand Down
4 changes: 2 additions & 2 deletions src/Docfx.Dotnet/SymbolFormatter.Syntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private void AddModifiersIfNeeded(ISymbol symbol)
private ImmutableArray<SymbolDisplayPart> RemoveNamedTypeConstraints(ISymbol symbol)
{
if (symbol.Kind is not SymbolKind.NamedType)
return ImmutableArray<SymbolDisplayPart>.Empty;
return [];

var result = ImmutableArray.CreateBuilder<SymbolDisplayPart>();

Expand Down Expand Up @@ -524,7 +524,7 @@ private ImmutableArray<SymbolDisplayPart> GetDisplayParts(ISymbol symbol, Symbol
}
catch
{
return ImmutableArray<SymbolDisplayPart>.Empty;
return [];
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Docfx.Dotnet/SymbolFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static ImmutableArray<SymbolDisplayPart> GetSyntaxParts(ISymbol symbol, S
}
catch (InvalidOperationException)
{
return ImmutableArray<SymbolDisplayPart>.Empty;
return [];
}
}

Expand Down Expand Up @@ -168,7 +168,7 @@ private static ImmutableArray<SymbolDisplayPart> GetDisplayParts(
}
catch
{
return ImmutableArray<SymbolDisplayPart>.Empty;
return [];
}

static ImmutableArray<SymbolDisplayPart> GetCastOperatorOverloadDisplayParts(ImmutableArray<SymbolDisplayPart> parts)
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Plugins/FileModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ public string File

public string DocumentType { get; set; }

public ImmutableArray<UidDefinition> Uids { get; set; } = ImmutableArray<UidDefinition>.Empty;
public ImmutableArray<UidDefinition> Uids { get; set; } = [];
}
6 changes: 3 additions & 3 deletions src/Docfx.Plugins/MarkupResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public class MarkupResult
{
public string Html { get; set; }
public ImmutableDictionary<string, object> YamlHeader { get; set; } = ImmutableDictionary<string, object>.Empty;
public ImmutableArray<string> LinkToFiles { get; set; } = ImmutableArray<string>.Empty;
public ImmutableHashSet<string> LinkToUids { get; set; } = ImmutableHashSet<string>.Empty;
public ImmutableArray<string> Dependency { get; set; } = ImmutableArray<string>.Empty;
public ImmutableArray<string> LinkToFiles { get; set; } = [];
public ImmutableHashSet<string> LinkToUids { get; set; } = [];
public ImmutableArray<string> Dependency { get; set; } = [];
public ImmutableDictionary<string, ImmutableList<LinkSourceInfo>> UidLinkSources { get; set; } = ImmutableDictionary<string, ImmutableList<LinkSourceInfo>>.Empty;
public ImmutableDictionary<string, ImmutableList<LinkSourceInfo>> FileLinkSources { get; set; } = ImmutableDictionary<string, ImmutableList<LinkSourceInfo>>.Empty;

Expand Down
8 changes: 4 additions & 4 deletions src/Docfx.Plugins/SaveResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public class SaveResult
public string DocumentType { get; set; }
public string FileWithoutExtension { get; set; }
public string ResourceFile { get; set; }
public ImmutableHashSet<string> LinkToUids { get; set; } = ImmutableHashSet<string>.Empty;
public ImmutableArray<string> LinkToFiles { get; set; } = ImmutableArray<string>.Empty;
public ImmutableArray<XRefSpec> XRefSpecs { get; set; } = ImmutableArray<XRefSpec>.Empty;
public ImmutableArray<XRefSpec> ExternalXRefSpecs { get; set; } = ImmutableArray<XRefSpec>.Empty;
public ImmutableHashSet<string> LinkToUids { get; set; } = [];
public ImmutableArray<string> LinkToFiles { get; set; } = [];
public ImmutableArray<XRefSpec> XRefSpecs { get; set; } = [];
public ImmutableArray<XRefSpec> ExternalXRefSpecs { get; set; } = [];
public ImmutableDictionary<string, ImmutableList<LinkSourceInfo>> UidLinkSources { get; set; } = ImmutableDictionary<string, ImmutableList<LinkSourceInfo>>.Empty;
public ImmutableDictionary<string, ImmutableList<LinkSourceInfo>> FileLinkSources { get; set; } = ImmutableDictionary<string, ImmutableList<LinkSourceInfo>>.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ public ManagedReferenceDocumentProcessorTest()
_outputFolder = GetRandomFolder();
string inputFolder = GetRandomFolder();
_defaultFiles = new FileCollection(Directory.GetCurrentDirectory());
_defaultFiles.Add(DocumentType.Article, new[] { "TestData/mref/CatLibrary.Cat-2.yml" }, "TestData/");
_defaultFiles.Add(DocumentType.Article, ["TestData/mref/CatLibrary.Cat-2.yml"], "TestData/");
_applyTemplateSettings = new ApplyTemplateSettings(inputFolder, _outputFolder)
{
RawModelExportSettings = { Export = true },
TransformDocument = true,
};

_templateManager = new TemplateManager(new List<string> { "template" }, null, "TestData/");
_templateManager = new TemplateManager(["template"], null, "TestData/");
}

[Fact]
Expand Down Expand Up @@ -93,7 +93,7 @@ public void ProcessMrefWithComplexFileNameShouldSucceed()
{
FileCollection files = new(_defaultFiles);
files.RemoveAll(s => true);
files.Add(DocumentType.Article, new string[] { "TestData/mref/Namespace1.Class1`2.yml", "TestData/mref/Namespace1.Class1`2.#ctor.yml" }, "TestData/");
files.Add(DocumentType.Article, ["TestData/mref/Namespace1.Class1`2.yml", "TestData/mref/Namespace1.Class1`2.#ctor.yml"], "TestData/");
BuildDocument(files);

var outputRawModelPath = GetRawModelFilePath("Namespace1.Class1`2.yml");
Expand Down Expand Up @@ -129,7 +129,7 @@ public void ProcessMrefWithXRefMapShouldSucceed()
public void ProcessMrefWithDefaultOverwriteShouldSucceed()
{
FileCollection files = new(_defaultFiles);
files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/mref.overwrite.default.md" });
files.Add(DocumentType.Overwrite, ["TestData/overwrite/mref.overwrite.default.md"]);
BuildDocument(files);
{
var outputRawModelPath = GetRawModelFilePath("CatLibrary.Cat-2.yml");
Expand All @@ -144,7 +144,7 @@ public void ProcessMrefWithDefaultOverwriteShouldSucceed()
public void ProcessMrefWithSimpleOverwriteShouldSucceed()
{
FileCollection files = new(_defaultFiles);
files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/mref.overwrite.simple.md" });
files.Add(DocumentType.Overwrite, ["TestData/overwrite/mref.overwrite.simple.md"]);
BuildDocument(files);
var outputRawModelPath = GetRawModelFilePath("CatLibrary.Cat-2.yml");
Assert.True(File.Exists(outputRawModelPath));
Expand All @@ -157,7 +157,7 @@ public void ProcessMrefWithSimpleOverwriteShouldSucceed()
public void ProcessMrefWithParametersOverwriteShouldSucceed()
{
var files = new FileCollection(_defaultFiles);
files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/mref.overwrite.parameters.md" });
files.Add(DocumentType.Overwrite, ["TestData/overwrite/mref.overwrite.parameters.md"]);
BuildDocument(files);
var outputRawModelPath = GetRawModelFilePath("CatLibrary.Cat-2.yml");
Assert.True(File.Exists(outputRawModelPath));
Expand All @@ -176,7 +176,7 @@ public void ProcessMrefWithParametersOverwriteShouldSucceed()
public void ProcessMrefWithNotPredefinedOverwriteShouldSucceed()
{
FileCollection files = new(_defaultFiles);
files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/mref.overwrite.not.predefined.md" });
files.Add(DocumentType.Overwrite, ["TestData/overwrite/mref.overwrite.not.predefined.md"]);
BuildDocument(files);
{
var outputRawModelPath = GetRawModelFilePath("CatLibrary.Cat-2.yml");
Expand All @@ -193,7 +193,7 @@ public void ProcessMrefWithDynamicDevLangsShouldSucceed()
{
FileCollection files = new(_defaultFiles);
files.RemoveAll(s => true);
files.Add(DocumentType.Article, new[] { "TestData/mref/System.String.yml" }, "TestData/");
files.Add(DocumentType.Article, ["TestData/mref/System.String.yml"], "TestData/");

BuildDocument(files);

Expand All @@ -214,8 +214,8 @@ public void ProcessMrefWithDynamicDevLangsShouldSucceed()
public void ProcessMrefWithInvalidCrossReferenceShouldWarn()
{
var files = new FileCollection(Directory.GetCurrentDirectory());
files.Add(DocumentType.Article, new[] { "TestData/mref/System.String.yml" }, "TestData/");
files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/mref.overwrite.invalid.ref.md" });
files.Add(DocumentType.Article, ["TestData/mref/System.String.yml"], "TestData/");
files.Add(DocumentType.Overwrite, ["TestData/overwrite/mref.overwrite.invalid.ref.md"]);

using var listener = new TestListenerScope(LogLevel.Info);

Expand All @@ -238,15 +238,15 @@ public void ProcessMrefWithInvalidCrossReferenceShouldWarn()
public void ProcessMrefWithInvalidOverwriteShouldFail()
{
FileCollection files = new(_defaultFiles);
files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/mref.overwrite.invalid.md" });
files.Add(DocumentType.Overwrite, ["TestData/overwrite/mref.overwrite.invalid.md"]);
Assert.Throws<DocumentException>(() => BuildDocument(files));
}

[Fact]
public void ProcessMrefWithRemarksOverwriteShouldSucceed()
{
var files = new FileCollection(_defaultFiles);
files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/mref.overwrite.remarks.md" });
files.Add(DocumentType.Overwrite, ["TestData/overwrite/mref.overwrite.remarks.md"]);
BuildDocument(files);
{
var outputRawModelPath = GetRawModelFilePath("CatLibrary.Cat-2.yml");
Expand All @@ -261,7 +261,7 @@ public void ProcessMrefWithRemarksOverwriteShouldSucceed()
public void ProcessMrefWithMultiUidOverwriteShouldSucceed()
{
var files = new FileCollection(_defaultFiles);
files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/mref.overwrite.multi.uid.md" });
files.Add(DocumentType.Overwrite, ["TestData/overwrite/mref.overwrite.multi.uid.md"]);
BuildDocument(files);
{
var outputRawModelPath = GetRawModelFilePath("CatLibrary.Cat-2.yml");
Expand Down Expand Up @@ -323,7 +323,7 @@ private void BuildDocument(FileCollection files)
TemplateManager = _templateManager
};

using var builder = new DocumentBuilder(LoadAssemblies(), ImmutableArray<string>.Empty);
using var builder = new DocumentBuilder(LoadAssemblies(), []);
builder.Build(parameters);
}

Expand Down
Loading