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 const when possible #16635

Merged
merged 2 commits into from
Aug 30, 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 @@ -9,8 +9,10 @@ namespace OrchardCore.Apis.GraphQL.ValidationRules;

public class RequiresPermissionValidationRule : IValidationRule
{
public static readonly string ErrorCode = "Unauthorized";
public const string ErrorCode = "Unauthorized";

private readonly IAuthorizationService _authorizationService;

protected readonly IStringLocalizer S;

public RequiresPermissionValidationRule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class DynamicCacheTagHelper : TagHelper
/// <summary>
/// Prefix used by <see cref="DynamicCacheTagHelper"/> instances when creating entries in <see cref="IDynamicCacheService"/>.
/// </summary>
public static readonly string CacheKeyPrefix = nameof(DynamicCacheTagHelper);
public const string CacheKeyPrefix = nameof(DynamicCacheTagHelper);

private readonly IDynamicCacheService _dynamicCacheService;
private readonly ICacheScopeManager _cacheScopeManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ namespace OrchardCore.GitHub.Configuration;
public static class GitHubDefaults
{
public const string AuthenticationScheme = "GitHub";
public static readonly string DisplayName = "GitHub";
public static readonly string AuthorizationEndpoint = "https://github.com/login/oauth/authorize";
public static readonly string TokenEndpoint = "https://github.com/login/oauth/access_token";
public static readonly string UserInformationEndpoint = "https://api.github.com/user";

public const string DisplayName = "GitHub";

public const string AuthorizationEndpoint = "https://github.com/login/oauth/authorize";

public const string TokenEndpoint = "https://github.com/login/oauth/access_token";

public const string UserInformationEndpoint = "https://api.github.com/user";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ namespace OrchardCore.Security;

public static class SecurityHeaderDefaults
{
internal static readonly char PoliciesSeparator = ',';
internal const char PoliciesSeparator = ',';

internal static readonly string[] ContentSecurityPolicyNames =
[
ContentSecurityPolicyValue.BaseUri,
Expand All @@ -23,6 +24,7 @@ public static class SecurityHeaderDefaults
ContentSecurityPolicyValue.StyleSource,
ContentSecurityPolicyValue.Sandbox
];

internal static readonly string[] PermissionsPolicyNames =
[
PermissionsPolicyValue.Accelerometer,
Expand Down Expand Up @@ -58,9 +60,9 @@ public static class SecurityHeaderDefaults

public static readonly string[] ContentSecurityPolicy = [];

public static readonly string ContentTypeOptions = ContentTypeOptionsValue.NoSniff;
public const string ContentTypeOptions = ContentTypeOptionsValue.NoSniff;
hishamco marked this conversation as resolved.
Show resolved Hide resolved

public static readonly string[] PermissionsPolicy = [];

public static readonly string ReferrerPolicy = ReferrerPolicyValue.NoReferrer;
public const string ReferrerPolicy = ReferrerPolicyValue.NoReferrer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace OrchardCore.DisplayManagement.Liquid.TagHelpers;
public class LiquidTagHelperMatching
{
private const string AspPrefix = "asp-";
public readonly static LiquidTagHelperMatching None = new();
public static readonly LiquidTagHelperMatching None = new();
public readonly TagMatchingRuleDescriptor[] _rules = [];

public LiquidTagHelperMatching()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace OrchardCore.Notifications;

public static class NotificationPermissions
{
public readonly static Permission ManageNotifications = new("ManageNotifications", "Manage notifications");
public static readonly Permission ManageNotifications = new("ManageNotifications", "Manage notifications");
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class AzureAISearchDefaultOptions
{
public const string DefaultAnalyzer = LexicalAnalyzerName.Values.StandardLucene;

public readonly static string[] DefaultAnalyzers =
public static readonly string[] DefaultAnalyzers =
[
LexicalAnalyzerName.Values.ArMicrosoft,
LexicalAnalyzerName.Values.ArLucene,
Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore/OrchardCore.Sms.Abstractions/SmsResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class SmsResult
/// <summary>
/// Returns an <see cref="SmsResult"/> indicating a successful SMS operation.
/// </summary>
public readonly static SmsResult Success = new()
public static readonly SmsResult Success = new()
{
Succeeded = true
};
Expand Down
16 changes: 8 additions & 8 deletions src/OrchardCore/OrchardCore/Localization/BclCalendars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ namespace OrchardCore.Localization;

internal static class BclCalendars
{
public readonly static Calendar Hebrew = new HebrewCalendar();
public readonly static Calendar Hijri = new HijriCalendar();
public readonly static Calendar Gregorian = new GregorianCalendar();
public readonly static Calendar Julian = new JulianCalendar();
public readonly static Calendar Persian = new PersianCalendar();
public readonly static Calendar UmAlQura = new UmAlQuraCalendar();
public static readonly Calendar Hebrew = new HebrewCalendar();
public static readonly Calendar Hijri = new HijriCalendar();
public static readonly Calendar Gregorian = new GregorianCalendar();
public static readonly Calendar Julian = new JulianCalendar();
public static readonly Calendar Persian = new PersianCalendar();
public static readonly Calendar UmAlQura = new UmAlQuraCalendar();

public static CalendarSystem GetCalendarByName(CalendarName calendarName) =>
calendarName switch
Expand All @@ -20,8 +20,8 @@ public static CalendarSystem GetCalendarByName(CalendarName calendarName) =>
CalendarName.Gregorian => CalendarSystem.Iso,
CalendarName.Julian => CalendarSystem.Julian,
CalendarName.Persian => CultureInfo.CurrentUICulture.Calendar.IsLeapYear(1)
? CalendarSystem.PersianSimple
: CalendarSystem.PersianAstronomical,
? CalendarSystem.PersianSimple
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved
: CalendarSystem.PersianAstronomical,
CalendarName.UmAlQura => CalendarSystem.UmAlQura,
_ => throw new NotSupportedException($"The calendar is not supported."),
};
Expand Down