Skip to content

Commit

Permalink
use some collection expressions (OrchardCMS#15250)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Feb 4, 2024
1 parent 6baa536 commit 0555ff2
Show file tree
Hide file tree
Showing 59 changed files with 85 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public async Task<IActionResult> List(ContentOptions options, PagerParameters pa

var startIndex = pager.GetStartIndex();
var pageSize = pager.PageSize;
IEnumerable<Models.AdminMenu> results = new List<Models.AdminMenu>();
IEnumerable<Models.AdminMenu> results = [];

// todo: handle the case where there is a deserialization exception on some of the presets.
// load at least the ones without error. Provide a way to delete the ones on error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override IDisplayResult Edit(ContentPickerField field, BuildFieldEditorCo
model.Part = context.ContentPart;
model.PartFieldDefinition = context.PartFieldDefinition;
model.SelectedItems = new List<VueMultiselectItemViewModel>();
model.SelectedItems = [];
var settings = context.PartFieldDefinition.GetSettings<ContentPickerFieldSettings>();
foreach (var contentItemId in field.ContentItemIds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override IDisplayResult Edit(LocalizationSetContentPickerField field, Bui
model.Part = context.ContentPart;
model.PartFieldDefinition = context.PartFieldDefinition;
model.SelectedItems = new List<VueMultiselectItemViewModel>();
model.SelectedItems = [];
foreach (var kvp in await _contentLocalizationManager.GetFirstItemIdForSetsAsync(field.LocalizationSets))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class EditUserPickerFieldViewModel
public ContentTypePartDefinition TypePartDefinition { get; set; }

[BindNever]
public IList<VueMultiselectUserViewModel> SelectedUsers { get; set; } = new List<VueMultiselectUserViewModel>();
public IList<VueMultiselectUserViewModel> SelectedUsers { get; set; } = [];
}

public class VueMultiselectUserViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@{
var allRoutableContentTypes = await RoutableContentTypeCoordinator.ListRoutableTypeDefinitionsAsync();

var selectedContentTypes = Model.Value.ContentTypes ?? new ContentTypeSitemapEntry[] { };
var selectedContentTypes = Model.Value.ContentTypes ?? [];

var selectedDisplayNames = allRoutableContentTypes
.Where(ctd => selectedContentTypes.Any(sct => sct.ContentTypeName == ctd.Name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected ContentEvent(IContentManager contentManager, IWorkflowScriptEvaluator

public IList<string> ContentTypeFilter
{
get => GetProperty<IList<string>>(defaultValue: () => new List<string>());
get => GetProperty<IList<string>>(defaultValue: () => []);
set => SetProperty(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public ContentEventViewModel(T activity)
}

public IList<ContentTypeDefinition> ContentTypeFilter { get; set; }
public IList<string> SelectedContentTypeNames { get; set; } = new List<string>();
public IList<string> SelectedContentTypeNames { get; set; } = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private class ModelStateTransferValue
public string Key { get; set; }
public string AttemptedValue { get; set; }
public object RawValue { get; set; }
public ICollection<string> ErrorMessages { get; set; } = new List<string>();
public ICollection<string> ErrorMessages { get; set; } = [];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace OrchardCore.OpenId.ViewModels
{
public class OpenIdApplicationsIndexViewModel
{
public IList<OpenIdApplicationEntry> Applications { get; } = new List<OpenIdApplicationEntry>();
public IList<OpenIdApplicationEntry> Applications { get; } = [];
public dynamic Pager { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace OrchardCore.OpenId.ViewModels
{
public class OpenIdScopeIndexViewModel
{
public IList<OpenIdScopeEntry> Scopes { get; } = new List<OpenIdScopeEntry>();
public IList<OpenIdScopeEntry> Scopes { get; } = [];
public dynamic Pager { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class OpenIdServerSettingsViewModel
public StoreLocation? SigningCertificateStoreLocation { get; set; }
public StoreName? SigningCertificateStoreName { get; set; }
public string SigningCertificateThumbprint { get; set; }
public IList<CertificateInfo> AvailableCertificates { get; } = new List<CertificateInfo>();
public IList<CertificateInfo> AvailableCertificates { get; } = [];
public bool EnableTokenEndpoint { get; set; }
public bool EnableAuthorizationEndpoint { get; set; }
public bool EnableLogoutEndpoint { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async Task<IActionResult> Index(ContentOptions options, PagerParameters p

var model = new QueriesIndexViewModel
{
Queries = new List<QueryEntry>(),
Queries = [],
Options = options,
Pager = await _shapeFactory.PagerAsync(pager, queries.Count(), routeData),
QuerySourceNames = _querySources.Select(x => x.Name).ToList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class ConditionOperatorConfigureOptions : IConfigureOptions<ConditionOper
{
public void Configure(ConditionOperatorOptions options)
{
options.Operators.AddRange(new List<ConditionOperatorOption>
{
options.Operators.AddRange(
[
new ConditionOperatorOption<ConditionOperatorConfigureOptions>(
(S) => S["Equals"],
new StringEqualsOperatorComparer(),
Expand Down Expand Up @@ -58,7 +58,7 @@ public void Configure(ConditionOperatorOptions options)
typeof(StringNotContainsOperator),
new ConditionOperatorFactory<StringNotContainsOperator>()
)
});
]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ await _luceneIndexManager.SearchAsync(luceneQuery.Index, async searcher =>
if (luceneQuery.ReturnContentItems)
{
// We always return an empty collection if the bottom lines queries have no results.
luceneQueryResults.Items = new List<ContentItem>();
luceneQueryResults.Items = [];
// Load corresponding content item versions
var indexedContentItemVersionIds = docs.TopDocs.ScoreDocs.Select(x => searcher.Doc(x.Doc).Get("ContentItemVersionId")).ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class LuceneSearchQueryService : ILuceneSearchQueryService
{
private readonly LuceneIndexManager _luceneIndexManager;

private static readonly HashSet<string> _idSet = new(new string[] { "ContentItemId" });
private static readonly HashSet<string> _idSet = [..new string[] {"ContentItemId"}];

public LuceneSearchQueryService(LuceneIndexManager luceneIndexManager)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public class SecurityHeadersOptions
{
public SecurityHeadersOptions()
{
HeaderPolicyProviders = new List<IHeaderPolicyProvider>
{
HeaderPolicyProviders =
[
new ContentSecurityPolicyHeaderPolicyProvider { Options = this },
new ContentTypeOptionsHeaderPolicyProvider { Options = this },
new PermissionsHeaderPolicyProvider { Options = this },
new ReferrerHeaderPolicyProvider { Options = this }
};
];
}

public string[] ContentSecurityPolicy { get; set; } = SecurityHeaderDefaults.ContentSecurityPolicy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class TwoFactorAuthenticationViewModel
public bool CanDisableTwoFactor { get; set; }

[BindNever]
public IList<IShape> AuthenticationMethods { get; } = new List<IShape>();
public IList<IShape> AuthenticationMethods { get; } = [];

[BindNever]
public IUser User { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace OrchardCore.Workflows.UserTasks.ViewModels
public class UserTaskEventViewModel
{
public string Actions { get; set; }
public IList<string> Roles { get; set; } = new List<string>();
public IList<string> Roles { get; set; } = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Application(IHostEnvironment environment, IEnumerable<Module> modules)

Assembly = Assembly.Load(new AssemblyName(Name));

_modules = new List<Module>(modules);
_modules = [..modules];
_modulesByName = _modules.ToDictionary(m => m.Name, m => m);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ public StartupActions(int order)

public int Order { get; }

public ICollection<Action<IServiceCollection, IServiceProvider>> ConfigureServicesActions { get; } =
new List<Action<IServiceCollection, IServiceProvider>>();
public ICollection<Action<IServiceCollection, IServiceProvider>> ConfigureServicesActions { get; } = [];

public ICollection<Action<IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider>> ConfigureActions { get; } =
new List<Action<IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider>>();
public ICollection<Action<IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider>> ConfigureActions { get; } = [];

public ICollection<Func<IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider, ValueTask>> AsyncConfigureActions { get; } =
new List<Func<IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider, ValueTask>>();
public ICollection<Func<IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider, ValueTask>> AsyncConfigureActions { get; } = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public class ShellDescriptor
/// <summary>
/// Gets or sets the list of features in the shell.
/// </summary>
public IList<ShellFeature> Features { get; set; } = new List<ShellFeature>();
public IList<ShellFeature> Features { get; set; } = [];

/// <summary>
/// Gets or sets the list of installed features in the shell.
/// </summary>
public IList<InstalledShellFeature> Installed { get; set; } = new List<InstalledShellFeature>();
public IList<InstalledShellFeature> Installed { get; set; } = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ContentItemMetadata
public RouteValueDictionary RemoveRouteValues { get; set; }
public RouteValueDictionary AdminRouteValues { get; set; }

public readonly IList<GroupInfo> DisplayGroupInfo = new List<GroupInfo>();
public readonly IList<GroupInfo> EditorGroupInfo = new List<GroupInfo>();
public readonly IList<GroupInfo> DisplayGroupInfo = [];
public readonly IList<GroupInfo> EditorGroupInfo = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ContentPartDefinitionBuilder(ContentPartDefinition existing)

if (existing == null)
{
_fields = new List<ContentPartFieldDefinition>();
_fields = [];
_settings = [];
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ContentTypeDefinitionBuilder(ContentTypeDefinition existing)

if (existing == null)
{
_parts = new List<ContentTypePartDefinition>();
_parts = [];
_settings = [];
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class ContentDefinitionRecord : Document
{
public ContentDefinitionRecord()
{
ContentTypeDefinitionRecords = new List<ContentTypeDefinitionRecord>();
ContentPartDefinitionRecords = new List<ContentPartDefinitionRecord>();
ContentTypeDefinitionRecords = [];
ContentPartDefinitionRecords = [];
}

public IList<ContentTypeDefinitionRecord> ContentTypeDefinitionRecords { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public class ContainedContentItemsAspect
/// <summary>
/// Json accessors to provide a list of contained content items.
/// </summary>
public IList<Func<JsonObject, JsonArray>> Accessors { get; set; } = new List<Func<JsonObject, JsonArray>>();
public IList<Func<JsonObject, JsonArray>> Accessors { get; set; } = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public DeploymentPlanResult(IFileBuilder fileBuilder, RecipeDescriptor recipeDes
}

public JsonObject Recipe { get; }
public IList<JsonObject> Steps { get; init; } = new List<JsonObject>();
public IList<JsonObject> Steps { get; init; } = [];
public IFileBuilder FileBuilder { get; }
public async Task FinalizeAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static async ValueTask<Completion> WriteToAsync(string identifier, List<F
// such that the tag helper can be matched based on the expected attribute names.
if (DefaultArgumentsMapping.TryGetValue(identifier, out var mapping))
{
arguments = new List<FilterArgument>(arguments);
arguments = [..arguments];
arguments[0] = new FilterArgument(mapping, arguments[0].Expression);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task<ShapeTable> GetShapeTableAsync(string themeId)
// Here we don't use a lock for thread safety but for atomicity.
lock (_syncLock)
{
excludedFeatures = new HashSet<string>(_shapeDescriptors.Select(kv => kv.Value.Feature.Id));
excludedFeatures = [.._shapeDescriptors.Select(kv => kv.Value.Feature.Id)];
}

var shapeDescriptors = new Dictionary<string, FeatureShapeDescriptor>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace OrchardCore.DisplayManagement.Descriptors
{
public class ShapeTableBuilder
{
private readonly IList<ShapeAlterationBuilder> _alterationBuilders = new List<ShapeAlterationBuilder>();
private readonly IList<ShapeAlterationBuilder> _alterationBuilders = [];
private readonly IFeatureInfo _feature;

public ShapeTableBuilder(IFeatureInfo feature, IReadOnlyCollection<string> excludedFeatureIds = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public class ShapeTemplateOptions
/// At startup, this is initialized to include an instance of <see cref="PhysicalFileProvider"/> that is
/// rooted at the application root.
/// </remarks>
public IList<IFileProvider> FileProviders { get; } = new List<IFileProvider>();
public IList<IFileProvider> FileProviders { get; } = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async ValueTask<IShape> CreateAsync(string shapeType, Func<ValueTask<ISha
New = this,
ShapeFactory = this,
ShapeType = shapeType,
OnCreated = new List<Func<ShapeCreatedContext, Task>>(),
OnCreated = [],
CreateAsync = shapeFactory
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Notifier : INotifier

public Notifier(ILogger<Notifier> logger)
{
_entries = new List<NotifyEntry>();
_entries = [];
_logger = logger;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class RazorShapeTemplateViewEngine : IShapeTemplateViewEngine
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ViewContextAccessor _viewContextAccessor;
private readonly ITempDataProvider _tempDataProvider;
private readonly List<string> _templateFileExtensions = new(new[] { RazorViewEngine.ViewExtension });
private readonly List<string> _templateFileExtensions = [..new[] {RazorViewEngine.ViewExtension}];

public RazorShapeTemplateViewEngine(
IOptions<MvcViewOptions> options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ShapeMetadata()
{
Wrappers = [];
Alternates = [];
BindingSources = new List<string>();
BindingSources = [];
Displaying = [];
Displayed = [];
ProcessingAsync = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace OrchardCore.Feeds.Models
public class FeedResponse
{
public XElement Element { get; set; }
public IList<FeedItem> Items { get; } = new List<FeedItem>();
public IList<Action<ContextualizeContext>> Contextualizers { get; } = new List<Action<ContextualizeContext>>();
public IList<FeedItem> Items { get; } = [];
public IList<Action<ContextualizeContext>> Contextualizers { get; } = [];
public void Contextualize(Action<ContextualizeContext> contextualizer)
{
Contextualizers.Add(contextualizer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,15 @@ protected virtual void ExpandDependencies(
List<string> dependencies = null;
if (resource.Dependencies != null)
{
dependencies = new List<string>(resource.Dependencies);
dependencies = [..resource.Dependencies];
if (settings.Dependencies != null)
{
dependencies.AddRange(settings.Dependencies);
}
}
else if (settings.Dependencies != null)
{
dependencies = new List<string>(settings.Dependencies);
dependencies = [..settings.Dependencies];
}

// Settings is given so they can cascade down into dependencies. For example, if Foo depends on Bar, and Foo's required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task ProcessContentItemsAsync(params string[] indexNames)

if (indexNames == null || indexNames.Length == 0)
{
indexSettings = new List<AzureAISearchIndexSettings>(indexesDocument.IndexSettings.Values);
indexSettings = [..indexesDocument.IndexSettings.Values];
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task<IQueryResults> ExecuteQueryAsync(Query query, IDictionary<stri
if (elasticQuery.ReturnContentItems)
{
// We always return an empty collection if the bottom lines queries have no results.
elasticQueryResults.Items = new List<ContentItem>();
elasticQueryResults.Items = [];

// Load corresponding content item versions
var topDocs = docs.TopDocs.Where(x => x != null).ToList();
Expand Down
Loading

0 comments on commit 0555ff2

Please sign in to comment.