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 'var' instead of explicit type (IDE0007 and IDE0008) #15189

Merged
merged 1 commit into from
Jan 28, 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 @@ -28,7 +28,7 @@ public async Task<ThemeSelectorResult> GetThemeAsync()
{
if (AdminAttribute.IsApplied(_httpContextAccessor.HttpContext))
{
string adminThemeName = await _adminThemeService.GetAdminThemeNameAsync();
var adminThemeName = await _adminThemeService.GetAdminThemeNameAsync();
if (string.IsNullOrEmpty(adminThemeName))
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public AdminThemeService(

public async Task<IExtensionInfo> GetAdminThemeAsync()
{
string currentThemeName = await GetAdminThemeNameAsync();
var currentThemeName = await GetAdminThemeNameAsync();
if (string.IsNullOrEmpty(currentThemeName))
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public IEnumerable<Endpoint> FindEndpoints(RouteValuesAddress address)
}

// Try to get the contained item first, then the container content item
string contentItemId = address.ExplicitValues[_options.ContainedContentItemIdKey]?.ToString();
var contentItemId = address.ExplicitValues[_options.ContainedContentItemIdKey]?.ToString();
if (string.IsNullOrEmpty(contentItemId))
{
contentItemId = address.ExplicitValues[_options.ContentItemIdKey]?.ToString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace OrchardCore.ContentTypes.Services;
namespace OrchardCore.ContentTypes.Services;

public class StereotypeDescription
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void Configure(OpenIddictValidationOptions options)
{
options.TokenValidationParameters.IssuerValidator = (issuer, token, parameters) =>
{
if (!Uri.TryCreate(issuer, UriKind.Absolute, out Uri uri))
if (!Uri.TryCreate(issuer, UriKind.Absolute, out var uri))
{
throw new SecurityTokenInvalidIssuerException("The token issuer is not valid.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ public static async Task UpdateDescriptorFromSettings(this IOpenIdApplicationMan
}

descriptor.PostLogoutRedirectUris.Clear();
foreach (Uri uri in
foreach (var uri in
(from uri in model.PostLogoutRedirectUris?.Split(new[] { " ", "," }, StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>()
select new Uri(uri, UriKind.Absolute)))
{
descriptor.PostLogoutRedirectUris.Add(uri);
}

descriptor.RedirectUris.Clear();
foreach (Uri uri in
foreach (var uri in
(from uri in model.RedirectUris?.Split(new[] { " ", "," }, StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>()
select new Uri(uri, UriKind.Absolute)))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override async Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecuti

if (u is User user)
{
foreach(var role in Roles)
foreach (var role in Roles)
{
if (user.RoleNames.Contains(role))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public override async Task<IDisplayResult> UpdateAsync(ISite site, UpdateEditorC
site.ResourceDebugMode = model.ResourceDebugMode;
site.AppendVersion = model.AppendVersion;
site.CacheMode = model.CacheMode;

if (model.PageSize.Value < 1)
{
context.Updater.ModelState.AddModelError(Prefix, nameof(model.PageSize), S["The page size must be greater than zero."]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
var model = context.Step;
var site = await _siteService.LoadSiteSettingsAsync();

foreach (JProperty property in model.Properties())
foreach (var property in model.Properties())
{
switch (property.Name)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public IEnumerable<Endpoint> FindEndpoints(RouteValuesAddress address)
return Enumerable.Empty<Endpoint>();
}

string sitemapId = address.ExplicitValues[_options.SitemapIdKey]?.ToString();
var sitemapId = address.ExplicitValues[_options.SitemapIdKey]?.ToString();

if (string.IsNullOrEmpty(sitemapId))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public SiteThemeSelector(ISiteThemeService siteThemeService)

public async Task<ThemeSelectorResult> GetThemeAsync()
{
string currentThemeName = await _siteThemeService.GetSiteThemeNameAsync();
var currentThemeName = await _siteThemeService.GetSiteThemeNameAsync();
if (string.IsNullOrEmpty(currentThemeName))
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public SiteThemeService(

public async Task<IExtensionInfo> GetSiteThemeAsync()
{
string currentThemeName = await GetSiteThemeNameAsync();
var currentThemeName = await GetSiteThemeNameAsync();
if (string.IsNullOrEmpty(currentThemeName))
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context)

var allUsers = await _session.Query<User>().ListAsync();

foreach (JObject userCustomUserSettings in customUserSettingsList.Cast<JObject>())
foreach (var userCustomUserSettings in customUserSettingsList.Cast<JObject>())
{
var userId = userCustomUserSettings
.Properties()
Expand All @@ -58,7 +58,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
.FirstOrDefault(p => p.Name == "user-custom-user-settings")
?.Value;

foreach (JObject userSetting in userSettings.Cast<JObject>())
foreach (var userSetting in userSettings.Cast<JObject>())
{
var contentItem = userSetting.ToObject<ContentItem>();
user.Properties[contentItem.ContentType] = userSetting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<IActionResult> BuildEditor(string id, string prefix, string pr

contentItem.Weld(new WidgetMetadata());

string cardCollectionType = nameof(WidgetsListPart);
var cardCollectionType = nameof(WidgetsListPart);

//Create a Card Shape
dynamic contentCard = await _shapeFactory.New.ContentCard(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task BindModelAsync(ModelBindingContext bindingContext)
var bodyTextContent = string.Empty;
// For some reasons we can't use XElement.LoadAsync. This method fails on big request body. I tested this with a picture with 2 MB of size.
// This code is maybe bad. Because if someone send a very big XML to this endpoint the server will die a out of memory exception.
using (StreamReader reader = new StreamReader(bindingContext.HttpContext.Request.Body, Encoding.UTF8, true, 1024, true))
using (var reader = new StreamReader(bindingContext.HttpContext.Request.Body, Encoding.UTF8, true, 1024, true))
{
bodyTextContent = await reader.ReadToEndAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void SearchUsedAlias(string propertyPath)

// Check if there's an alias for the full path
// aliasPart.Alias -> AliasFieldIndex.Alias
if (_aliases.TryGetValue(propertyPath, out string alias))
if (_aliases.TryGetValue(propertyPath, out var alias))
{
_usedAliases.Add(alias);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ public static class CssOrchardHelperExtensions
{
public static IHtmlContent GetLimitedWidthWrapperClasses(this IOrchardHelper helper, params string[] additionalClasses)
=> GetHtmlContentBuilder(helper.GetThemeOptions().LimitedWidthWrapperClasses, additionalClasses);

public static IHtmlContent GetLimitedWidthClasses(this IOrchardHelper helper, params string[] additionalClasses)
=> GetHtmlContentBuilder(helper.GetThemeOptions().LimitedWidthClasses, additionalClasses);

public static IHtmlContent GetStartClasses(this IOrchardHelper helper, params string[] additionalClasses)
=> GetHtmlContentBuilder(helper.GetThemeOptions().StartClasses, additionalClasses);

public static IHtmlContent GetEndClasses(this IOrchardHelper helper, params string[] additionalClasses)
=> GetHtmlContentBuilder(helper.GetThemeOptions().EndClasses, additionalClasses);

public static IHtmlContent GetLabelClasses(this IOrchardHelper helper, params string[] additionalClasses)
=> GetHtmlContentBuilder(helper.GetThemeOptions().LabelClasses, additionalClasses);

public static IHtmlContent GetWrapperClasses(this IOrchardHelper helper, params string[] additionalClasses)
=> GetHtmlContentBuilder(helper.GetThemeOptions().WrapperClasses, additionalClasses);

public static IHtmlContent GetEndClasses(this IOrchardHelper helper, bool withOffset, params string[] additionalClasses)
{
var options = helper.GetThemeOptions();
Expand All @@ -47,31 +47,31 @@ public static IHtmlContent GetEndClasses(this IOrchardHelper helper, bool withOf

public static IHtmlContent GetOffsetClasses(this IOrchardHelper helper, params string[] additionalClasses)
=> GetHtmlContentBuilder(helper.GetThemeOptions().OffsetClasses, additionalClasses);

[Obsolete($"Please use {nameof(GetLimitedWidthWrapperClasses)} instead, as this method is deprecated and will be removed in upcoming versions.")]
public static string GetLimitedWidthWrapperCssClasses(this IOrchardHelper helper, params string[] additionalClasses)
=> string.Join(' ', Combine(helper.GetThemeOptions().LimitedWidthWrapperClasses, additionalClasses));

[Obsolete($"Please use {nameof(GetLimitedWidthClasses)} instead, as this method is deprecated and will be removed in upcoming versions.")]
public static string GetLimitedWidthCssClasses(this IOrchardHelper helper, params string[] additionalClasses)
=> string.Join(' ', Combine(helper.GetThemeOptions().LimitedWidthClasses, additionalClasses));

[Obsolete($"Please use {nameof(GetLabelClasses)} instead, as this method is deprecated and will be removed in upcoming versions.")]
public static string GetLabelCssClasses(this IOrchardHelper helper, params string[] additionalClasses)
=> string.Join(' ', Combine(helper.GetThemeOptions().LabelClasses, additionalClasses));

[Obsolete($"Please use {nameof(GetStartClasses)} instead, as this method is deprecated and will be removed in upcoming versions.")]
public static string GetStartCssClasses(this IOrchardHelper helper, params string[] additionalClasses)
=> string.Join(' ', Combine(helper.GetThemeOptions().StartClasses, additionalClasses));

[Obsolete($"Please use {nameof(GetEndClasses)} instead, as this method is deprecated and will be removed in upcoming versions.")]
public static string GetEndCssClasses(this IOrchardHelper helper, params string[] additionalClasses)
=> string.Join(' ', Combine(helper.GetThemeOptions().EndClasses, additionalClasses));

[Obsolete($"Please use {nameof(GetWrapperClasses)} instead, as this method is deprecated and will be removed in upcoming versions.")]
public static string GetWrapperCssClasses(this IOrchardHelper helper, params string[] additionalClasses)
=> string.Join(' ', Combine(helper.GetThemeOptions().WrapperClasses, additionalClasses));


[Obsolete($"Please use {nameof(GetEndClasses)} instead, as this method is deprecated and will be removed in upcoming versions.")]
public static string GetEndCssClasses(this IOrchardHelper helper, bool withOffset, params string[] additionalClasses)
Expand All @@ -94,7 +94,7 @@ public static string GetEndCssClasses(this IOrchardHelper helper, bool withOffse
[Obsolete($"Please use {nameof(GetOffsetClasses)} instead, as this method is deprecated and will be removed in upcoming versions.")]
public static string GetOffsetCssClasses(this IOrchardHelper helper, params string[] additionalClasses)
=> string.Join(' ', Combine(helper.GetThemeOptions().OffsetClasses, additionalClasses));

public static TheAdminThemeOptions GetThemeOptions(this IOrchardHelper helper)
=> helper.HttpContext.RequestServices.GetService<IOptions<TheAdminThemeOptions>>().Value;

Expand All @@ -111,7 +111,7 @@ private static IEnumerable<string> Combine(string optionClasses, string[] additi
private static HtmlContentBuilder GetHtmlContentBuilder(string optionClasses, IList<string> values)
{
var builder = new HtmlContentBuilder();

builder.Append(optionClasses);

builder.AppendSeparatedValues(values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public async override Task ProcessAsync(TagHelperContext context, TagHelperOutpu
dynamic shape = await _shapeFactory.CreateAsync(shapeType);
shape.Utc = Utc;
shape.Format = Format;

output.Content.SetHtmlContent(await _displayHelper.ShapeExecuteAsync(shape));

// We don't want any encapsulating tag around the shape
output.TagName = null;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public TimeSpanTagHelper(IShapeFactory shapeFactory, IDisplayHelper displayHelpe

[HtmlAttributeName(OriginAttribute)]
public DateTime? Origin { set; get; }

public async override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var shapeType = "TimeSpan";
Expand All @@ -38,4 +38,4 @@ public async override Task ProcessAsync(TagHelperContext context, TagHelperOutpu
output.TagName = null;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Threading.Tasks;
using OrchardCore.DisplayManagement.Shapes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace OrchardCore.FileStorage.AmazonS3;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace OrchardCore.FileStorage.AmazonS3;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public CommandHelpAttribute(params string[] helpText)
return;
}

StringBuilder builder = new StringBuilder();
var builder = new StringBuilder();

foreach (var value in helpText)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static string Combine(string path, string other = null)
/// </summary>
public static string Combine(string path, params string[] others)
{
string result = path;
var result = path;

for (var i = 0; i < others.Length; i++)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Task BindModelAsync(ModelBindingContext bindingContext)
return Task.CompletedTask;
}

if (bool.TryParse(valueProviderResult.FirstValue, out bool result))
if (bool.TryParse(valueProviderResult.FirstValue, out var result))
{
bindingContext.Result = ModelBindingResult.Success(result);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.AspNetCore.Mvc.Razor.Extensions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static async Task PopulateMenuAsync(dynamic shapeFactory, dynamic parentS
/// <param name="viewContext">The current <see cref="ViewContext"/>.</param>
public static async Task PopulateMenuLevelAsync(dynamic shapeFactory, dynamic parentShape, dynamic menu, IEnumerable<MenuItem> menuItems, ViewContext viewContext)
{
foreach (MenuItem menuItem in menuItems)
foreach (var menuItem in menuItems)
{
dynamic menuItemShape = await BuildMenuItemShapeAsync(shapeFactory, parentShape, menu, menuItem, viewContext);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using OrchardCore.Search.AzureAI.Models;

namespace OrchardCore.Search.AzureAI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using OrchardCore.Search.AzureAI.Models;

namespace OrchardCore.Search.AzureAI;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace OrchardCore.Search.AzureAI;
namespace OrchardCore.Search.AzureAI;

public class AzureAISearchIndexRemoveContext(string indexName, string indexFullName)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure.Search.Documents.Models;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Query CreateQuery(ILuceneQueryService builder, LuceneQueryContext context
foreach (var property in query.Properties())
{
var occur = Occur.MUST;
bool isProps = false;
var isProps = false;

switch (property.Name.ToLowerInvariant())
{
Expand Down
Loading
Loading