Skip to content

Commit

Permalink
Simplify new expression (IDE0090) (OrchardCMS#15188)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored and urbanit committed Mar 18, 2024
1 parent 4cc65fd commit 70fec71
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public async Task<AuditTrailEventQueryResult> QueryAsync(int page, int pageSize,
var startOfWeek = CultureInfo.CurrentUICulture.DateTimeFormat.FirstDayOfWeek;
options.AuditTrailDates = new List<SelectListItem>()
{
new SelectListItem(S["Any date"], string.Empty, options.Date == string.Empty),
new(S["Any date"], string.Empty, options.Date == string.Empty),
};

var dateTimeValue = ">@now-1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override IDisplayResult Edit(ContentOptionsViewModel model, IUpdateModel
var supportedCultures = await _localizationService.GetSupportedCulturesAsync();
var cultures = new List<SelectListItem>
{
new SelectListItem() { Text = S["All cultures"], Value = "", Selected = string.IsNullOrEmpty(m.SelectedCulture) }
new() { Text = S["All cultures"], Value = "", Selected = string.IsNullOrEmpty(m.SelectedCulture) }
};
cultures.AddRange(supportedCultures.Select(culture => new SelectListItem() { Text = culture, Value = culture, Selected = culture == m.SelectedCulture }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override void ConfigureServices(IServiceCollection services)
Hidden = false,
PartOptions = new GraphQLContentPartOption[] {
// Content Part options attached to Content Type
new GraphQLContentPartOption("TestContentPartA")
new("TestContentPartA")
{
Collapse = false,
Hidden = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public async Task<IActionResult> Create(string suggestion, string returnUrl = nu
return Forbid();
}

var template = new PlacementNode[] { new PlacementNode() };
var template = new PlacementNode[] { new() };

var viewModel = new EditShapePlacementViewModel
{
Expand All @@ -146,7 +146,7 @@ public async Task<IActionResult> Edit(string shapeType, string displayType = nul

var placementNodes = (await _placementsManager.GetShapePlacementsAsync(shapeType))?.ToList() ?? new List<PlacementNode>();

if (!placementNodes.Any() || ShouldCreateNode(placementNodes, displayType, contentType, contentPart, differentiator))
if (placementNodes.Count == 0 || ShouldCreateNode(placementNodes, displayType, contentType, contentPart, differentiator))
{
var generatedNode = new PlacementNode
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public override async Task<IDisplayResult> EditAsync(ContentOptionsViewModel mod
PopulateTermEntries(termEntries, taxonomy.As<TaxonomyPart>().Terms, 0);
var terms = new List<SelectListItem>
{
new SelectListItem { Text = S["Clear filter"], Value = "" },
new SelectListItem { Text = S["Show all"], Value = "Taxonomy:" + taxonomy.ContentItemId }
new() { Text = S["Clear filter"], Value = "" },
new() { Text = S["Show all"], Value = "Taxonomy:" + taxonomy.ContentItemId }
};
foreach (var term in termEntries)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public OrchardCoreBuilder RegisterStartup<T>() where T : class, IStartup

/// <summary>
/// This method gets called for each tenant. Use this method to add services to the container.
/// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
/// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940.
/// </summary>
/// <param name="configure">The action to execute when configuring the services for a tenant.</param>
/// <param name="order">The order of the action to execute. Lower values will be executed first.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private IEnumerable<Module> GetModules()
{
var modules = new ConcurrentBag<Module>
{
new Module(_environment.ApplicationName, true),
new(_environment.ApplicationName, true),
};

var names = _moduleNamesProviders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ public void Describe(DescribeContext<ContentItem> context)
var results = new List<AutoroutePartIndex>
{
// If the part is disabled or was removed, a record is still added but with a null path.
new AutoroutePartIndex
{
new() {
ContentItemId = contentItem.ContentItemId,
Path = !partRemoved && !part.Disabled ? part.Path : null,
Published = contentItem.Published,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public override void Describe(DescribeContext<User> context)
{
return new UserByRoleNameIndex[]
{
new UserByRoleNameIndex
{
new() {
RoleName = NormalizeKey("Authenticated"),
Count = 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@ private static class Log
{
public static class EventIds
{
public static readonly EventId CleanupCycleStart = new EventId(100, "CleanupCycleStart");
public static readonly EventId CleanupCycleEnd = new EventId(101, "CleanupCycleEnd");
public static readonly EventId CleanupItemFailed = new EventId(102, "CleanupItemFailed");
public static readonly EventId HandlerExpired = new EventId(103, "HandlerExpired");
public static readonly EventId CleanupCycleStart = new(100, "CleanupCycleStart");
public static readonly EventId CleanupCycleEnd = new(101, "CleanupCycleEnd");
public static readonly EventId CleanupItemFailed = new(102, "CleanupItemFailed");
public static readonly EventId HandlerExpired = new(103, "HandlerExpired");
}

private static readonly Action<ILogger, int, Exception?> _cleanupCycleStart = LoggerMessage.Define<int>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private ValueStopwatch(long startTimestamp)
_startTimestamp = startTimestamp;
}

public static ValueStopwatch StartNew() => new ValueStopwatch(Stopwatch.GetTimestamp());
public static ValueStopwatch StartNew() => new(Stopwatch.GetTimestamp());

public TimeSpan GetElapsedTime()
{
Expand Down
4 changes: 2 additions & 2 deletions test/OrchardCore.Tests/Localization/CultureDictionaryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public void EnumerateCultureDictionary()
var dictionary = new CultureDictionary("ar", PluralizationRule.Arabic);
dictionary.MergeTranslations(new List<CultureDictionaryRecord>
{
new CultureDictionaryRecord("Hello", "مرحبا"),
new CultureDictionaryRecord("Bye", "مع السلامة")
new("Hello", "مرحبا"),
new("Bye", "مع السلامة")
});

// Act & Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public void LocalizerReturnsCorrectPluralFormIfMultiplePluraflFormsAreSpecified(
{
SetupDictionary("en", new CultureDictionaryRecord[]
{
new CultureDictionaryRecord("míč", "ball", "{0} balls")
new("míč", "ball", "{0} balls")
}, PluralizationRule.English);

var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, true, _logger.Object);
Expand All @@ -280,7 +280,7 @@ public void LocalizerFallBackToParentCultureIfFallBackToParentUICulturesIsTrue(b
{
SetupDictionary("ar", new CultureDictionaryRecord[]
{
new CultureDictionaryRecord("hello", "مرحبا")
new("hello", "مرحبا")
}, PluralizationRule.Arabic);

SetupDictionary("ar-YE", Array.Empty<CultureDictionaryRecord>(), PluralizationRule.Arabic);
Expand All @@ -301,16 +301,16 @@ public void LocalizerReturnsGetAllStrings(bool includeParentCultures, string[] e
{
SetupDictionary("ar", new CultureDictionaryRecord[]
{
new CultureDictionaryRecord("Blog", "مدونة"),
new CultureDictionaryRecord("Menu", "قائمة"),
new CultureDictionaryRecord("Page", "صفحة"),
new CultureDictionaryRecord("Article", "مقالة")
new("Blog", "مدونة"),
new("Menu", "قائمة"),
new("Page", "صفحة"),
new("Article", "مقالة")
}, PluralizationRule.Arabic);

SetupDictionary("ar-YE", new CultureDictionaryRecord[]
{
new CultureDictionaryRecord("Blog", "مدونة"),
new CultureDictionaryRecord("Product", "منتج")
new("Blog", "مدونة"),
new("Product", "منتج")
}, PluralizationRule.Arabic);

var localizer = new PortableObjectStringLocalizer(null, _localizationManager.Object, false, _logger.Object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public async Task GrantsRolesPermissions(string required, bool authenticated, bo
{
RoleName = "Anonymous",
RoleClaims = new List<RoleClaim> {
new RoleClaim { ClaimType = Permission.ClaimType, ClaimValue = "AllowAnonymous" }
new() { ClaimType = Permission.ClaimType, ClaimValue = "AllowAnonymous" }
}
},
new Role
{
RoleName = "Authenticated",
RoleClaims = new List<RoleClaim> {
new RoleClaim { ClaimType = Permission.ClaimType, ClaimValue = "AllowAuthenticated" }
new() { ClaimType = Permission.ClaimType, ClaimValue = "AllowAuthenticated" }
}
}
);
Expand Down Expand Up @@ -73,7 +73,7 @@ public async Task GrantsInheritedPermissions()
{
RoleName = "Anonymous",
RoleClaims = new List<RoleClaim> {
new RoleClaim { ClaimType = Permission.ClaimType, ClaimValue = "Implicit2" }
new() { ClaimType = Permission.ClaimType, ClaimValue = "Implicit2" }
}
}
);
Expand All @@ -98,14 +98,14 @@ public async Task IsCaseIsensitive(string required, bool authenticated)
{
RoleName = "Anonymous",
RoleClaims = new List<RoleClaim> {
new RoleClaim { ClaimType = Permission.ClaimType, ClaimValue = "aLlOwAnOnYmOuS" }
new() { ClaimType = Permission.ClaimType, ClaimValue = "aLlOwAnOnYmOuS" }
}
},
new Role
{
RoleName = "Authenticated",
RoleClaims = new List<RoleClaim> {
new RoleClaim { ClaimType = Permission.ClaimType, ClaimValue = "aLlOwAuThEnTiCaTeD" }
new() { ClaimType = Permission.ClaimType, ClaimValue = "aLlOwAuThEnTiCaTeD" }
}
}
);
Expand Down
30 changes: 15 additions & 15 deletions test/OrchardCore.Tests/Routing/AutorouteEntriesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public async Task ShouldGetContainedEntryByPath()
// Act
var initialEntries = new List<AutorouteEntry>()
{
new AutorouteEntry("container", "container-path"),
new AutorouteEntry("container", "contained-path", "contained")
new("container", "container-path"),
new("container", "contained-path", "contained")
};
entries.AddEntries(initialEntries);
Expand Down Expand Up @@ -56,8 +56,8 @@ public async Task ShouldGetEntryByContainedContentItemId()
// Act
var initialEntries = new List<AutorouteEntry>()
{
new AutorouteEntry("container", "container-path"),
new AutorouteEntry("container", "contained-path", "contained")
new("container", "container-path"),
new("container", "contained-path", "contained")
};
entries.AddEntries(initialEntries);
Expand Down Expand Up @@ -90,8 +90,8 @@ public async Task RemovesContainedEntriesWhenContainerRemoved()
// Act
var initialEntries = new List<AutorouteEntry>()
{
new AutorouteEntry("container", "container-path"),
new AutorouteEntry("container", "contained-path", "contained")
new("container", "container-path"),
new("container", "contained-path", "contained")
};
entries.AddEntries(initialEntries);
Expand Down Expand Up @@ -125,17 +125,17 @@ public async Task RemovesContainedEntriesWhenDeleted()
// Act
var initialEntries = new List<AutorouteEntry>()
{
new AutorouteEntry("container", "container-path"),
new AutorouteEntry("container", "contained-path1", "contained1"),
new AutorouteEntry("container", "contained-path2", "contained2")
new("container", "container-path"),
new("container", "contained-path1", "contained1"),
new("container", "contained-path2", "contained2")
};
entries.AddEntries(initialEntries);
var updatedEntries = new List<AutorouteEntry>()
{
new AutorouteEntry("container", "container-path"),
new AutorouteEntry("container", "contained-path1", "contained1")
new("container", "container-path"),
new("container", "contained-path1", "contained1")
};
entries.AddEntries(updatedEntries);
Expand Down Expand Up @@ -167,16 +167,16 @@ public async Task RemovesOldContainedPaths()
// Act
var initialEntries = new List<AutorouteEntry>()
{
new AutorouteEntry("container", "container-path"),
new AutorouteEntry("container", "contained-path-old", "contained")
new("container", "container-path"),
new("container", "contained-path-old", "contained")
};
entries.AddEntries(initialEntries);
var updatedEntries = new List<AutorouteEntry>()
{
new AutorouteEntry("container", "container-path"),
new AutorouteEntry("container", "contained-path-new", "contained")
new("container", "container-path"),
new("container", "contained-path-new", "contained")
};
entries.AddEntries(updatedEntries);
Expand Down
10 changes: 5 additions & 5 deletions test/OrchardCore.Tests/Workflows/WorkflowManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ public async Task CanExecuteSimpleWorkflow()
WorkflowTypeId = IdGenerator.GenerateId(),
Activities = new List<ActivityRecord>
{
new ActivityRecord { ActivityId = "1", IsStart = true, Name = addTask.Name, Properties = JObject.FromObject( new
new() { ActivityId = "1", IsStart = true, Name = addTask.Name, Properties = JObject.FromObject( new
{
A = new WorkflowExpression<double>("input(\"A\")"),
B = new WorkflowExpression<double>("input(\"B\")"),
}) },
new ActivityRecord { ActivityId = "2", Name = writeLineTask.Name, Properties = JObject.FromObject( new { Text = new WorkflowExpression<string>("lastResult().toString()") }) },
new ActivityRecord { ActivityId = "3", Name = setOutputTask.Name, Properties = JObject.FromObject( new { Value = new WorkflowExpression<string>("lastResult()"), OutputName = "Sum" }) }
new() { ActivityId = "2", Name = writeLineTask.Name, Properties = JObject.FromObject( new { Text = new WorkflowExpression<string>("lastResult().toString()") }) },
new() { ActivityId = "3", Name = setOutputTask.Name, Properties = JObject.FromObject( new { Value = new WorkflowExpression<string>("lastResult()"), OutputName = "Sum" }) }
},
Transitions = new List<Transition>
{
new Transition{ SourceActivityId = "1", SourceOutcomeName = "Done", DestinationActivityId = "2" },
new Transition{ SourceActivityId = "2", SourceOutcomeName = "Done", DestinationActivityId = "3" }
new() { SourceActivityId = "1", SourceOutcomeName = "Done", DestinationActivityId = "2" },
new() { SourceActivityId = "2", SourceOutcomeName = "Done", DestinationActivityId = "3" }
}
};

Expand Down

0 comments on commit 70fec71

Please sign in to comment.