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

Updated naming pattern used the s_ prefix for private static fields #56647

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions eng/tools/BaselineGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static void Main(string[] args)
private readonly CommandOption _output;
private readonly CommandOption _update;

private static readonly string[] _defaultSources = new string[] { "https://api.nuget.org/v3/index.json" };
private static readonly string[] s_defaultSources = new string[] { "https://api.nuget.org/v3/index.json" };

public Program()
{
Expand All @@ -59,7 +59,7 @@ private async Task<int> Run()

var inputPath = Path.Combine(Directory.GetCurrentDirectory(), "Baseline.xml");
var input = XDocument.Load(inputPath);
var sources = _sources.HasValue() ? _sources.Values.Select(s => s.TrimEnd('/')) : _defaultSources;
var sources = _sources.HasValue() ? _sources.Values.Select(s => s.TrimEnd('/')) : s_defaultSources;
var packageSources = sources.Select(s => new PackageSource(s));
var providers = Repository.Provider.GetCoreV3(); // Get v2 and v3 API support
var sourceRepositories = packageSources.Select(ps => new SourceRepository(ps, providers));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public class DiagnosticProject
/// </summary>
public static string TestProjectName = "TestProject";

private static readonly ICompilationAssemblyResolver _assemblyResolver = new AppBaseCompilationAssemblyResolver();
private static readonly Dictionary<Assembly, Solution> _solutionCache = new Dictionary<Assembly, Solution>();
private static readonly ICompilationAssemblyResolver s_assemblyResolver = new AppBaseCompilationAssemblyResolver();
private static readonly Dictionary<Assembly, Solution> s_solutionCache = new Dictionary<Assembly, Solution>();

public static Project Create(Assembly testAssembly, string[] sources, Func<Workspace> workspaceFactory = null, Type analyzerReference = null)
{
Solution solution;
lock (_solutionCache)
lock (s_solutionCache)
{
if (!_solutionCache.TryGetValue(testAssembly, out solution))
if (!s_solutionCache.TryGetValue(testAssembly, out solution))
{
workspaceFactory ??= CreateWorkspace;

Expand All @@ -44,7 +44,7 @@ public static Project Create(Assembly testAssembly, string[] sources, Func<Works

foreach (var defaultCompileLibrary in DependencyContext.Load(testAssembly).CompileLibraries)
{
foreach (var resolveReferencePath in defaultCompileLibrary.ResolveReferencePaths(_assemblyResolver))
foreach (var resolveReferencePath in defaultCompileLibrary.ResolveReferencePaths(s_assemblyResolver))
{
solution = solution.AddMetadataReference(projectId, MetadataReference.CreateFromFile(resolveReferencePath));
}
Expand All @@ -57,7 +57,7 @@ public static Project Create(Assembly testAssembly, string[] sources, Func<Works
new AnalyzerFileReference(analyzerReference.Assembly.Location, AssemblyLoader.Instance));
}

_solutionCache.Add(testAssembly, solution);
s_solutionCache.Add(testAssembly, solution);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Components/Components/src/Routing/RouteTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Components.Routing;
internal sealed class RouteTable(TreeRouter treeRouter)
{
private readonly TreeRouter _router = treeRouter;
private static readonly ConcurrentDictionary<(Type, string), InboundRouteEntry> _routeEntryCache = new();
private static readonly ConcurrentDictionary<(Type, string), InboundRouteEntry> s_routeEntryCache = new();

public TreeRouter? TreeRouter => _router;

Expand All @@ -23,7 +23,7 @@ internal static RouteData ProcessParameters(RouteData endpointRouteData)
{
if (endpointRouteData.Template != null)
{
var entry = _routeEntryCache.GetOrAdd(
var entry = s_routeEntryCache.GetOrAdd(
(endpointRouteData.PageType, endpointRouteData.Template),
((Type page, string template) key) => RouteTableFactory.CreateEntry(key.page, key.template));

Expand Down
4 changes: 2 additions & 2 deletions src/Components/Server/src/Circuits/RemoteRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal partial class RemoteRenderer : WebRenderer
#pragma warning restore CA1852 // Seal internal types
{
private static readonly Task CanceledTask = Task.FromCanceled(new CancellationToken(canceled: true));
private static readonly ComponentPlatform _componentPlatform = new("Server", isInteractive: true);
private static readonly ComponentPlatform s_componentPlatform = new("Server", isInteractive: true);

private readonly CircuitClientProxy _client;
private readonly CircuitOptions _options;
Expand Down Expand Up @@ -57,7 +57,7 @@ public RemoteRenderer(

public override Dispatcher Dispatcher { get; } = Dispatcher.CreateDefault();

protected override ComponentPlatform ComponentPlatform => _componentPlatform;
protected override ComponentPlatform ComponentPlatform => s_componentPlatform;

protected override IComponentRenderMode? GetComponentRenderMode(IComponent component) => RenderMode.InteractiveServer;

Expand Down
6 changes: 3 additions & 3 deletions src/Components/Shared/src/ElementReferenceJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Components;

internal sealed class ElementReferenceJsonConverter : JsonConverter<ElementReference>
{
private static readonly JsonEncodedText IdProperty = JsonEncodedText.Encode("__internalId");
private static readonly JsonEncodedText s_IdProperty = JsonEncodedText.Encode("__internalId");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be s_idProperty. The character after the first underscore should be lower case.

Applies to all fields.


private readonly ElementReferenceContext _elementReferenceContext;

Expand All @@ -24,7 +24,7 @@ public override ElementReference Read(ref Utf8JsonReader reader, Type typeToConv
{
if (reader.TokenType == JsonTokenType.PropertyName)
{
if (reader.ValueTextEquals(IdProperty.EncodedUtf8Bytes))
if (reader.ValueTextEquals(s_IdProperty.EncodedUtf8Bytes))
{
reader.Read();
id = reader.GetString();
Expand All @@ -51,7 +51,7 @@ public override ElementReference Read(ref Utf8JsonReader reader, Type typeToConv
public override void Write(Utf8JsonWriter writer, ElementReference value, JsonSerializerOptions options)
{
writer.WriteStartObject();
writer.WriteString(IdProperty, value.Id);
writer.WriteString(s_IdProperty, value.Id);
writer.WriteEndObject();
}
}
4 changes: 2 additions & 2 deletions src/Components/Web/src/Forms/InputNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Components.Forms;
/// </summary>
public class InputNumber<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TValue> : InputBase<TValue>
{
private static readonly string _stepAttributeValue = GetStepAttributeValue();
private static readonly string s_stepAttributeValue = GetStepAttributeValue();

private static string GetStepAttributeValue()
{
Expand Down Expand Up @@ -52,7 +52,7 @@ private static string GetStepAttributeValue()
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(0, "input");
builder.AddAttribute(1, "step", _stepAttributeValue);
builder.AddAttribute(1, "step", s_stepAttributeValue);
builder.AddMultipleAttributes(2, AdditionalAttributes);
builder.AddAttribute(3, "type", "number");
builder.AddAttributeIfNotNullOrEmpty(4, "name", NameAttributeValue);
Expand Down
32 changes: 16 additions & 16 deletions src/Components/Web/src/WebEventData/DragEventArgsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ namespace Microsoft.AspNetCore.Components.Web;

internal static class DragEventArgsReader
{
private static readonly JsonEncodedText DataTransfer = JsonEncodedText.Encode("dataTransfer");
private static readonly JsonEncodedText DropEffect = JsonEncodedText.Encode("dropEffect");
private static readonly JsonEncodedText EffectAllowed = JsonEncodedText.Encode("effectAllowed");
private static readonly JsonEncodedText Files = JsonEncodedText.Encode("files");
private static readonly JsonEncodedText Items = JsonEncodedText.Encode("items");
private static readonly JsonEncodedText Types = JsonEncodedText.Encode("types");
private static readonly JsonEncodedText Kind = JsonEncodedText.Encode("kind");
private static readonly JsonEncodedText Type = JsonEncodedText.Encode("type");
private static readonly JsonEncodedText s_DataTransfer = JsonEncodedText.Encode("dataTransfer");
private static readonly JsonEncodedText s_DropEffect = JsonEncodedText.Encode("dropEffect");
private static readonly JsonEncodedText s_EffectAllowed = JsonEncodedText.Encode("effectAllowed");
private static readonly JsonEncodedText s_Files = JsonEncodedText.Encode("files");
private static readonly JsonEncodedText s_Items = JsonEncodedText.Encode("items");
private static readonly JsonEncodedText s_Types = JsonEncodedText.Encode("types");
private static readonly JsonEncodedText s_Kind = JsonEncodedText.Encode("kind");
private static readonly JsonEncodedText s_Type = JsonEncodedText.Encode("type");

internal static DragEventArgs Read(JsonElement jsonElement)
{
var eventArgs = new DragEventArgs();
foreach (var property in jsonElement.EnumerateObject())
{
if (property.NameEquals(DataTransfer.EncodedUtf8Bytes))
if (property.NameEquals(s_DataTransfer.EncodedUtf8Bytes))
{
eventArgs.DataTransfer = ReadDataTransfer(property.Value);
}
Expand All @@ -41,19 +41,19 @@ private static DataTransfer ReadDataTransfer(JsonElement jsonElement)
var dataTransfer = new DataTransfer();
foreach (var property in jsonElement.EnumerateObject())
{
if (property.NameEquals(DropEffect.EncodedUtf8Bytes))
if (property.NameEquals(s_DropEffect.EncodedUtf8Bytes))
{
dataTransfer.DropEffect = property.Value.GetString()!;
}
else if (property.NameEquals(EffectAllowed.EncodedUtf8Bytes))
else if (property.NameEquals(s_EffectAllowed.EncodedUtf8Bytes))
{
dataTransfer.EffectAllowed = property.Value.GetString();
}
else if (property.NameEquals(Files.EncodedUtf8Bytes))
else if (property.NameEquals(s_Files.EncodedUtf8Bytes))
{
dataTransfer.Files = ReadStringArray(property.Value);
}
else if (property.NameEquals(Items.EncodedUtf8Bytes))
else if (property.NameEquals(s_Items.EncodedUtf8Bytes))
{
var value = property.Value;
var items = new DataTransferItem[value.GetArrayLength()];
Expand All @@ -64,7 +64,7 @@ private static DataTransfer ReadDataTransfer(JsonElement jsonElement)
}
dataTransfer.Items = items;
}
else if (property.NameEquals(Types.EncodedUtf8Bytes))
else if (property.NameEquals(s_Types.EncodedUtf8Bytes))
{
dataTransfer.Types = ReadStringArray(property.Value);
}
Expand All @@ -82,11 +82,11 @@ private static DataTransferItem ReadDataTransferItem(JsonElement jsonElement)
var item = new DataTransferItem();
foreach (var property in jsonElement.EnumerateObject())
{
if (property.NameEquals(Kind.EncodedUtf8Bytes))
if (property.NameEquals(s_Kind.EncodedUtf8Bytes))
{
item.Kind = property.Value.GetString()!;
}
else if (property.NameEquals(Type.EncodedUtf8Bytes))
else if (property.NameEquals(s_Type.EncodedUtf8Bytes))
{
item.Type = property.Value.GetString()!;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Server;
internal sealed class ContentEncodingNegotiator
{
// List of encodings by preference order with their associated extension so that we can easily handle "*".
private static readonly StringSegment[] _preferredEncodings =
private static readonly StringSegment[] s_preferredEncodings =
new StringSegment[] { "br", "gzip" };

private static readonly Dictionary<StringSegment, string> _encodingExtensionMap = new Dictionary<StringSegment, string>(StringSegmentComparer.OrdinalIgnoreCase)
private static readonly Dictionary<StringSegment, string> s_encodingExtensionMap = new Dictionary<StringSegment, string>(StringSegmentComparer.OrdinalIgnoreCase)
{
["br"] = ".br",
["gzip"] = ".gz"
Expand Down Expand Up @@ -64,7 +64,7 @@ private void NegotiateEncoding(HttpContext context)
{
selectedEncoding = PickPreferredEncoding(context, selectedEncoding, encoding);
}
else if (_encodingExtensionMap.TryGetValue(encodingName, out var encodingExtension) && ResourceExists(context, encodingExtension))
else if (s_encodingExtensionMap.TryGetValue(encodingName, out var encodingExtension) && ResourceExists(context, encodingExtension))
{
selectedEncoding = encodingName;
selectedEncodingQuality = quality;
Expand All @@ -85,7 +85,7 @@ private void NegotiateEncoding(HttpContext context)
}
}

if (_encodingExtensionMap.TryGetValue(selectedEncoding, out var extension))
if (s_encodingExtensionMap.TryGetValue(selectedEncoding, out var extension))
{
context.Request.Path = context.Request.Path + extension;
context.Response.Headers.ContentEncoding = selectedEncoding.Value;
Expand All @@ -96,14 +96,14 @@ private void NegotiateEncoding(HttpContext context)

StringSegment PickPreferredEncoding(HttpContext context, StringSegment selectedEncoding, StringWithQualityHeaderValue encoding)
{
foreach (var preferredEncoding in _preferredEncodings)
foreach (var preferredEncoding in s_preferredEncodings)
{
if (preferredEncoding == selectedEncoding)
{
return selectedEncoding;
}

if ((preferredEncoding == encoding.Value || encoding.Value == "*") && ResourceExists(context, _encodingExtensionMap[preferredEncoding]))
if ((preferredEncoding == encoding.Value || encoding.Value == "*") && ResourceExists(context, s_encodingExtensionMap[preferredEncoding]))
{
return preferredEncoding;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ namespace Microsoft.AspNetCore.DataProtection.Internal;

internal static class ContainerUtils
{
private static readonly Lazy<bool> _isContainer = new Lazy<bool>(IsProcessRunningInContainer);
private static readonly Lazy<bool> s_isContainer = new Lazy<bool>(IsProcessRunningInContainer);
private const string RunningInContainerVariableName = "DOTNET_RUNNING_IN_CONTAINER";
private const string DeprecatedRunningInContainerVariableName = "DOTNET_RUNNING_IN_CONTAINERS";

public static bool IsContainer => _isContainer.Value;
public static bool IsContainer => s_isContainer.Value;

public static bool IsVolumeMountedFolder(DirectoryInfo directory)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ namespace Microsoft.AspNetCore.DataProtection.KeyManagement;
/// </summary>
public class KeyManagementOptions
{
private static readonly TimeSpan _keyPropagationWindow = TimeSpan.FromDays(2);
private static readonly TimeSpan _keyRingRefreshPeriod = TimeSpan.FromHours(24);
private static readonly TimeSpan _maxServerClockSkew = TimeSpan.FromMinutes(5);
private static readonly TimeSpan s_keyPropagationWindow = TimeSpan.FromDays(2);
private static readonly TimeSpan s_keyRingRefreshPeriod = TimeSpan.FromHours(24);
private static readonly TimeSpan s_maxServerClockSkew = TimeSpan.FromMinutes(5);
private TimeSpan _newKeyLifetime = TimeSpan.FromDays(90);

/// <summary>
Expand Down Expand Up @@ -54,7 +54,7 @@ internal static TimeSpan KeyPropagationWindow
{
// This value is not settable since there's a complex interaction between
// it and the key ring refresh period.
return _keyPropagationWindow;
return s_keyPropagationWindow;
}
}

Expand All @@ -72,7 +72,7 @@ internal static TimeSpan KeyRingRefreshPeriod
{
// This value is not settable since there's a complex interaction between
// it and the key expiration safety period.
return _keyRingRefreshPeriod;
return s_keyRingRefreshPeriod;
}
}

Expand All @@ -90,7 +90,7 @@ internal static TimeSpan MaxServerClockSkew
{
get
{
return _maxServerClockSkew;
return s_maxServerClockSkew;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/HealthChecks/Abstractions/src/HealthCheckResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.Extensions.Diagnostics.HealthChecks;
/// </summary>
public struct HealthCheckResult
{
private static readonly IReadOnlyDictionary<string, object> _emptyReadOnlyDictionary = new Dictionary<string, object>();
private static readonly IReadOnlyDictionary<string, object> s_emptyReadOnlyDictionary = new Dictionary<string, object>();

/// <summary>
/// Creates a new <see cref="HealthCheckResult"/> with the specified values for <paramref name="status"/>,
Expand All @@ -26,7 +26,7 @@ public HealthCheckResult(HealthStatus status, string? description = null, Except
Status = status;
Description = description;
Exception = exception;
Data = data ?? _emptyReadOnlyDictionary;
Data = data ?? s_emptyReadOnlyDictionary;
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/HealthChecks/Abstractions/src/HealthReportEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.Extensions.Diagnostics.HealthChecks;
/// </summary>
public struct HealthReportEntry
{
private static readonly IReadOnlyDictionary<string, object> _emptyReadOnlyDictionary = new Dictionary<string, object>();
private static readonly IReadOnlyDictionary<string, object> s_emptyReadOnlyDictionary = new Dictionary<string, object>();

/// <summary>
/// Creates a new <see cref="HealthReportEntry"/> with the specified values for <paramref name="status"/>, <paramref name="exception"/>,
Expand Down Expand Up @@ -44,7 +44,7 @@ public HealthReportEntry(HealthStatus status, string? description, TimeSpan dura
Description = description;
Duration = duration;
Exception = exception;
Data = data ?? _emptyReadOnlyDictionary;
Data = data ?? s_emptyReadOnlyDictionary;
Tags = tags ?? Enumerable.Empty<string>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Authentication;
/// </summary>
public class AuthenticateResult
{
private static readonly AuthenticateResult _noResult = new() { None = true };
private static readonly AuthenticateResult s_noResult = new() { None = true };

/// <summary>
/// Creates a new <see cref="AuthenticateResult"/> instance.
Expand Down Expand Up @@ -88,7 +88,7 @@ public static AuthenticateResult Success(AuthenticationTicket ticket)
/// <returns>The result.</returns>
public static AuthenticateResult NoResult()
{
return _noResult;
return s_noResult;
}

/// <summary>
Expand Down
Loading