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 language keywords instead of framework type names for type references (IDE0049) #14273

Merged
merged 7 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dotnet_style_qualification_for_event = false : suggestion

# Use language keywords instead of framework type names for type references
dotnet_style_predefined_type_for_locals_parameters_members = true : suggestion
dotnet_style_predefined_type_for_member_access = false : suggestion
dotnet_style_predefined_type_for_member_access = true : suggestion

# Suggest more modern language features when available
csharp_style_pattern_matching_over_is_with_cast_check = true : none
Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Admin/AdminMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public AdminMenu(IStringLocalizer<AdminMenu> localizer)

public Task BuildNavigationAsync(string name, NavigationBuilder builder)
{
if (!String.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
{
return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task<ThemeSelectorResult> GetThemeAsync()
if (AdminAttribute.IsApplied(_httpContextAccessor.HttpContext))
{
string adminThemeName = await _adminThemeService.GetAdminThemeNameAsync();
if (String.IsNullOrEmpty(adminThemeName))
if (string.IsNullOrEmpty(adminThemeName))
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public AdminThemeService(
public async Task<IExtensionInfo> GetAdminThemeAsync()
{
string currentThemeName = await GetAdminThemeNameAsync();
if (String.IsNullOrEmpty(currentThemeName))
if (string.IsNullOrEmpty(currentThemeName))
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public AdminMenu(AdminMenuNavigationProvidersCoordinator adminMenuNavigationProv

public async Task BuildNavigationAsync(string name, NavigationBuilder builder)
{
if (!String.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public LinkAdminNodeNavigationBuilder(
public Task BuildNavigationAsync(MenuItem menuItem, NavigationBuilder builder, IEnumerable<IAdminNodeNavigationBuilder> treeNodeBuilders)
{
var node = menuItem as LinkAdminNode;
if (node == null || String.IsNullOrEmpty(node.LinkText) || !node.Enabled)
if (node == null || string.IsNullOrEmpty(node.LinkText) || !node.Enabled)
{
return Task.CompletedTask;
}

return builder.AddAsync(new LocalizedString(node.LinkText, node.LinkText), async itemBuilder =>
{
var nodeLinkUrl = node.LinkUrl;
if (!String.IsNullOrEmpty(nodeLinkUrl) && nodeLinkUrl[0] != '/' && !nodeLinkUrl.Contains("://"))
if (!string.IsNullOrEmpty(nodeLinkUrl) && nodeLinkUrl[0] != '/' && !nodeLinkUrl.Contains("://"))
{
if (nodeLinkUrl.StartsWith("~/", StringComparison.Ordinal))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Task BuildNavigationAsync(MenuItem menuItem, NavigationBuilder builder, I
{
var node = menuItem as PlaceholderAdminNode;

if (node == null || String.IsNullOrEmpty(node.LinkText) || !node.Enabled)
if (node == null || string.IsNullOrEmpty(node.LinkText) || !node.Enabled)
{
return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public async Task<IActionResult> List(ContentOptions options, PagerParameters pa

var adminMenuList = (await _adminMenuService.GetAdminMenuListAsync()).AdminMenu;

if (!String.IsNullOrWhiteSpace(options.Search))
if (!string.IsNullOrWhiteSpace(options.Search))
{
adminMenuList = adminMenuList.Where(x => x.Name.Contains(options.Search, StringComparison.OrdinalIgnoreCase)).ToList();
}
Expand Down Expand Up @@ -254,7 +254,7 @@ public async Task<ActionResult> IndexPost(ViewModels.ContentOptions options, IEn
case ContentsBulkAction.Remove:
foreach (var item in checkedContentItems)
{
var adminMenu = adminMenuList.FirstOrDefault(x => String.Equals(x.Id, item.Id, StringComparison.OrdinalIgnoreCase));
var adminMenu = adminMenuList.FirstOrDefault(x => string.Equals(x.Id, item.Id, StringComparison.OrdinalIgnoreCase));
await _adminMenuService.DeleteAsync(adminMenu);
}
await _notifier.SuccessAsync(H["Admin menus successfully removed."]);
Expand Down
4 changes: 2 additions & 2 deletions src/OrchardCore.Modules/OrchardCore.AdminMenu/Permissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public IEnumerable<PermissionStereotype> GetDefaultStereotypes()
public static Permission CreatePermissionForAdminMenu(string name)
{
return new Permission(
String.Format(_viewAdminMenu.Name, name),
String.Format(_viewAdminMenu.Description, name),
string.Format(_viewAdminMenu.Name, name),
string.Format(_viewAdminMenu.Description, name),
_viewAdminMenu.ImpliedBy
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public AdminMenuStep(IAdminMenuService adminMenuService)

public async Task ExecuteAsync(RecipeExecutionContext context)
{
if (!String.Equals(context.Name, "AdminMenu", StringComparison.OrdinalIgnoreCase))
if (!string.Equals(context.Name, "AdminMenu", StringComparison.OrdinalIgnoreCase))
{
return;
}
Expand All @@ -37,7 +37,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
var adminMenu = token.ToObject<Models.AdminMenu>(serializer);

// When the id is not supplied generate an id, otherwise replace the menu if it exists, or create a new menu.
if (String.IsNullOrEmpty(adminMenu.Id))
if (string.IsNullOrEmpty(adminMenu.Id))
{
adminMenu.Id = Guid.NewGuid().ToString("n");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public AdminMenuNavigationProvidersCoordinator(
// todo: use a public constant for the string
public async Task BuildNavigationAsync(string name, NavigationBuilder builder)
{
if (!String.Equals(name, "adminMenu", StringComparison.OrdinalIgnoreCase))
if (!string.Equals(name, "adminMenu", StringComparison.OrdinalIgnoreCase))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task SaveAsync(Models.AdminMenu tree)
{
var adminMenuList = await LoadAdminMenuListAsync();

var preexisting = adminMenuList.AdminMenu.FirstOrDefault(x => String.Equals(x.Id, tree.Id, StringComparison.OrdinalIgnoreCase));
var preexisting = adminMenuList.AdminMenu.FirstOrDefault(x => string.Equals(x.Id, tree.Id, StringComparison.OrdinalIgnoreCase));

// it's new? add it
if (preexisting == null)
Expand All @@ -44,14 +44,14 @@ public async Task SaveAsync(Models.AdminMenu tree)

public Models.AdminMenu GetAdminMenuById(AdminMenuList adminMenuList, string id)
{
return adminMenuList.AdminMenu.FirstOrDefault(x => String.Equals(x.Id, id, StringComparison.OrdinalIgnoreCase));
return adminMenuList.AdminMenu.FirstOrDefault(x => string.Equals(x.Id, id, StringComparison.OrdinalIgnoreCase));
}

public async Task<int> DeleteAsync(Models.AdminMenu tree)
{
var adminMenuList = await LoadAdminMenuListAsync();

var count = adminMenuList.AdminMenu.RemoveAll(x => String.Equals(x.Id, tree.Id, StringComparison.OrdinalIgnoreCase));
var count = adminMenuList.AdminMenu.RemoveAll(x => string.Equals(x.Id, tree.Id, StringComparison.OrdinalIgnoreCase));

await _documentManager.UpdateAsync(adminMenuList);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public AliasPartHandler(
public override async Task ValidatingAsync(ValidateContentContext context, AliasPart part)
{
// Only validate the alias if it's not empty.
if (String.IsNullOrWhiteSpace(part.Alias))
if (string.IsNullOrWhiteSpace(part.Alias))
{
return;
}
Expand All @@ -56,14 +56,14 @@ public override async Task ValidatingAsync(ValidateContentContext context, Alias
public async override Task UpdatedAsync(UpdateContentContext context, AliasPart part)
{
// Compute the Alias only if it's empty.
if (!String.IsNullOrEmpty(part.Alias))
if (!string.IsNullOrEmpty(part.Alias))
{
return;
}

var pattern = GetPattern(part);

if (!String.IsNullOrEmpty(pattern))
if (!string.IsNullOrEmpty(pattern))
{
var model = new AliasPartViewModel()
{
Expand All @@ -75,7 +75,7 @@ public async override Task UpdatedAsync(UpdateContentContext context, AliasPart
part.Alias = await _liquidTemplateManager.RenderStringAsync(pattern, NullEncoder.Default, model,
new Dictionary<string, FluidValue>() { [nameof(ContentItem)] = new ObjectValue(model.ContentItem) });

part.Alias = part.Alias.Replace("\r", String.Empty).Replace("\n", String.Empty);
part.Alias = part.Alias.Replace("\r", string.Empty).Replace("\n", string.Empty);

if (part.Alias?.Length > AliasPart.MaxAliasLength)
{
Expand Down Expand Up @@ -125,7 +125,7 @@ public override async Task CloningAsync(CloneContentContext context, AliasPart p
private string GetPattern(AliasPart part)
{
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType);
var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => String.Equals(x.PartDefinition.Name, nameof(AliasPart)));
var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, nameof(AliasPart)));
var pattern = contentTypePartDefinition.GetSettings<AliasPartSettings>().Pattern;

return pattern;
Expand All @@ -137,7 +137,7 @@ private async Task<string> GenerateUniqueAliasAsync(string alias, AliasPart cont
var unversionedAlias = alias;

var versionSeparatorPosition = alias.LastIndexOf('-');
if (versionSeparatorPosition > -1 && Int32.TryParse(alias[versionSeparatorPosition..].TrimStart('-'), out version))
if (versionSeparatorPosition > -1 && int.TryParse(alias[versionSeparatorPosition..].TrimStart('-'), out version))
{
unversionedAlias = alias[..versionSeparatorPosition];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void Describe(DescribeContext<ContentItem> context)
}

var part = contentItem.As<AliasPart>();
if (part == null || String.IsNullOrEmpty(part.Alias))
if (part == null || string.IsNullOrEmpty(part.Alias))
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class AliasPartRazorHelperExtensions
/// <returns>A content item id or <c>null</c> if it was not found.</returns>
public static async Task<string> GetContentItemIdByAliasAsync(this IOrchardHelper orchardHelper, string alias)
{
if (String.IsNullOrEmpty(alias))
if (string.IsNullOrEmpty(alias))
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public override async Task<IDisplayResult> UpdateAsync(ContentTypePartDefinition

if (await context.Updater.TryUpdateModelAsync(model, Prefix, m => m.Pattern, m => m.Options))
{
if (!String.IsNullOrEmpty(model.Pattern) && !_templateManager.Validate(model.Pattern, out var errors))
if (!string.IsNullOrEmpty(model.Pattern) && !_templateManager.Validate(model.Pattern, out var errors))
{
context.Updater.ModelState.AddModelError(nameof(model.Pattern), S["Pattern doesn't contain a valid Liquid expression. Details: {0}", String.Join(" ", errors)]);
context.Updater.ModelState.AddModelError(nameof(model.Pattern), S["Pattern doesn't contain a valid Liquid expression. Details: {0}", string.Join(" ", errors)]);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding;

namespace OrchardCore.Alias.Settings
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public AdminMenu(IStringLocalizer<AdminMenu> localizer)

public Task BuildNavigationAsync(string name, NavigationBuilder builder)
{
if (!String.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
{
return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private async Task ExecuteAsync(HttpContext context, ISchemaFactory schemaServic

var queryToExecute = request.Query;

if (!String.IsNullOrEmpty(request.NamedQuery))
if (!string.IsNullOrEmpty(request.NamedQuery))
{
var namedQueries = context.RequestServices.GetServices<INamedQueryProvider>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async Task<ISchema> GetSchemaAsync()
var identifier = await builder.GetIdentifierAsync();

// Null being a valid value not yet updated.
if (identifier != String.Empty)
if (identifier != string.Empty)
{
_identifiers[builder] = identifier;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task<ActionResult> Index([ModelBinder(BinderType = typeof(AuditTrai
};

// This is used by Contents feature for routing so needs to be passed into the options.
if (!String.IsNullOrEmpty(correlationId))
if (!string.IsNullOrEmpty(correlationId))
{
options.CorrelationId = correlationId;
options.CorrelationIdFromRoute = true;
Expand Down Expand Up @@ -129,7 +129,7 @@ public async Task<ActionResult> IndexFilterPOST(AuditTrailIndexOptions options)
{
await _auditTrailOptionsDisplayManager.UpdateEditorAsync(options, _updateModelAccessor.ModelUpdater, false, "", "");
// When the user has typed something into the search input no further evaluation of the form post is required.
if (!String.Equals(options.SearchText, options.OriginalSearchText, StringComparison.OrdinalIgnoreCase))
if (!string.Equals(options.SearchText, options.OriginalSearchText, StringComparison.OrdinalIgnoreCase))
{
return RedirectToAction(nameof(Index), new RouteValueDictionary { { "q", options.SearchText } });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public AuditTrailAdminMenu(IStringLocalizer<AuditTrailAdminMenu> stringLocalizer

public Task BuildNavigationAsync(string name, NavigationBuilder builder)
{
if (!String.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
{
return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public AuditTrailSettingsAdminMenu(IStringLocalizer<AuditTrailSettingsAdminMenu>

public Task BuildNavigationAsync(string name, NavigationBuilder builder)
{
if (!String.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase))
{
return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public AuditTrailManager(

public async Task RecordEventAsync<TEvent>(AuditTrailContext<TEvent> context) where TEvent : class, new()
{
if (_shellSettings.IsInitializing() && String.IsNullOrEmpty(context.UserName))
if (_shellSettings.IsInitializing() && string.IsNullOrEmpty(context.UserName))
{
var feature = _httpContextAccessor.HttpContext.Features.Get<RecipeEnvironmentFeature>();
if (feature != null && feature.Properties.TryGetValue(SetupConstants.AdminUsername, out var adminUsername))
Expand Down Expand Up @@ -96,8 +96,8 @@ public AuditTrailManager(
CorrelationId = createContext.CorrelationId,
UserId = createContext.UserId,
UserName = createContext.UserName ?? "",
NormalizedUserName = String.IsNullOrEmpty(createContext.UserName) ? "" : _keyNormalizer.NormalizeName(createContext.UserName),
ClientIpAddress = String.IsNullOrEmpty(createContext.ClientIpAddress)
NormalizedUserName = string.IsNullOrEmpty(createContext.UserName) ? "" : _keyNormalizer.NormalizeName(createContext.UserName),
ClientIpAddress = string.IsNullOrEmpty(createContext.ClientIpAddress)
? await GetClientIpAddressAsync()
: createContext.ClientIpAddress,
CreatedUtc = createContext.CreatedUtc ?? _clock.UtcNow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class CorrelationIdFilterNode : TermOperationNode
}

public override string ToNormalizedString()
=> String.Empty;
=> string.Empty;

public override string ToString()
=> String.Empty;
=> string.Empty;
}
}
Loading