Skip to content

Commit

Permalink
Updated to make private read-only static fields match the naming conv…
Browse files Browse the repository at this point in the history
…ention for const fields.
  • Loading branch information
ajcvickers committed Dec 11, 2021
1 parent 50ea89e commit 329663f
Show file tree
Hide file tree
Showing 159 changed files with 1,027 additions and 1,035 deletions.
8 changes: 0 additions & 8 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,6 @@ dotnet_naming_rule.const_field_naming.symbols = const_field_symbol
dotnet_naming_rule.const_field_naming.style = pascal_case_style
dotnet_naming_rule.const_field_naming.severity = suggestion

# Private Fields
dotnet_naming_symbols.private_field_symbol.applicable_kinds = field
dotnet_naming_symbols.private_field_symbol.applicable_accessibilities = private

dotnet_naming_rule.private_field_naming.symbols = private_field_symbol
dotnet_naming_rule.private_field_naming.style = _camelCase
dotnet_naming_rule.private_field_naming.severity = suggestion

# Parameters
dotnet_naming_symbols.parameter_symbol.applicable_kinds = parameter
dotnet_naming_symbols.parameter_symbol.applicable_accessibilities = *
Expand Down
2 changes: 1 addition & 1 deletion All.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FK/@EntryIndexedValue">FK</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MARS/@EntryIndexedValue">MARS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/EventHandlerPatternLong/@EntryValue">$object$_On$event$</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=042e7460_002D3ec6_002D4f1c_002D87c3_002Dfc91240d4c90/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static, Instance" AccessRightKinds="Public" Description="Test Methods"&gt;&lt;ElementKinds&gt;&lt;Kind Name="TEST_MEMBER" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="Aa_bb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=EF/@EntryIndexedValue">EF</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FBLOCK_005FSCOPE_005FCONSTANT/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
Expand Down
26 changes: 13 additions & 13 deletions src/EFCore.Analyzers/InternalUsageDiagnosticAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ namespace Microsoft.EntityFrameworkCore;
public sealed class InternalUsageDiagnosticAnalyzer : DiagnosticAnalyzer
{
public const string Id = "EF1001";
private static readonly int _efLen = "EntityFrameworkCore".Length;
private static readonly int EFLen = "EntityFrameworkCore".Length;

private static readonly DiagnosticDescriptor _descriptor
private static readonly DiagnosticDescriptor Descriptor
= new(
Id,
title: AnalyzerStrings.InternalUsageTitle,
Expand All @@ -25,7 +25,7 @@ private static readonly DiagnosticDescriptor _descriptor
isEnabledByDefault: true);

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
=> ImmutableArray.Create(_descriptor);
=> ImmutableArray.Create(Descriptor);

public override void Initialize(AnalysisContext context)
{
Expand Down Expand Up @@ -115,7 +115,7 @@ private static void AnalyzeInvocation(OperationAnalysisContext context, IInvocat
{
if (IsInternal(context, a))
{
context.ReportDiagnostic(Diagnostic.Create(_descriptor, context.Operation.Syntax.GetLocation(), a));
context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Operation.Syntax.GetLocation(), a));
}
}

Expand All @@ -134,7 +134,7 @@ private static void AnalyzeVariableDeclaration(OperationAnalysisContext context,
CSharpSyntax.VariableDeclarationSyntax s => s.Type,
_ => context.Operation.Syntax
};
context.ReportDiagnostic(Diagnostic.Create(_descriptor, syntax.GetLocation(), declarator.Symbol.Type));
context.ReportDiagnostic(Diagnostic.Create(Descriptor, syntax.GetLocation(), declarator.Symbol.Type));
return;
}
}
Expand Down Expand Up @@ -191,7 +191,7 @@ CSharpSyntax.ClassDeclarationSyntax s when s.BaseList?.Types.Count > 0
{ } otherSyntax => otherSyntax.GetLocation()
};

context.ReportDiagnostic(Diagnostic.Create(_descriptor, location, baseSymbol));
context.ReportDiagnostic(Diagnostic.Create(Descriptor, location, baseSymbol));
}
}

Expand All @@ -205,7 +205,7 @@ CSharpSyntax.ClassDeclarationSyntax s when s.BaseList?.Types.Count > 0
{ } otherSyntax => otherSyntax.GetLocation()
};

context.ReportDiagnostic(Diagnostic.Create(_descriptor, location, @interface));
context.ReportDiagnostic(Diagnostic.Create(Descriptor, location, @interface));
}
}
}
Expand All @@ -229,7 +229,7 @@ private static void AnalyzeMethodTypeSymbol(SymbolAnalysisContext context, IMeth
{ } otherSyntax => otherSyntax.GetLocation()
};

context.ReportDiagnostic(Diagnostic.Create(_descriptor, location, symbol.ReturnType));
context.ReportDiagnostic(Diagnostic.Create(Descriptor, location, symbol.ReturnType));
}
}

Expand All @@ -243,7 +243,7 @@ private static void AnalyzeMethodTypeSymbol(SymbolAnalysisContext context, IMeth
{ } otherSyntax => otherSyntax.GetLocation()
};

context.ReportDiagnostic(Diagnostic.Create(_descriptor, location, paramSymbol.Type));
context.ReportDiagnostic(Diagnostic.Create(Descriptor, location, paramSymbol.Type));
}
}
}
Expand All @@ -264,10 +264,10 @@ private static void AnalyzeMemberDeclarationTypeSymbol(

private static void ReportDiagnostic(OperationAnalysisContext context, object messageArg)
=> context.ReportDiagnostic(
Diagnostic.Create(_descriptor, NarrowDownSyntax(context.Operation.Syntax).GetLocation(), messageArg));
Diagnostic.Create(Descriptor, NarrowDownSyntax(context.Operation.Syntax).GetLocation(), messageArg));

private static void ReportDiagnostic(SymbolAnalysisContext context, SyntaxNode syntax, object messageArg)
=> context.ReportDiagnostic(Diagnostic.Create(_descriptor, NarrowDownSyntax(syntax).GetLocation(), messageArg));
=> context.ReportDiagnostic(Diagnostic.Create(Descriptor, NarrowDownSyntax(syntax).GetLocation(), messageArg));

/// <summary>
/// Given a syntax node, pattern matches some known types and returns a narrowed-down node for the type syntax which
Expand Down Expand Up @@ -318,8 +318,8 @@ private static bool IsInInternalNamespace(ISymbol symbol)
return
i != -1
&& (i == 0 || ns[i - 1] == '.')
&& i + _efLen < ns.Length
&& ns[i + _efLen] == '.'
&& i + EFLen < ns.Length
&& ns[i + EFLen] == '.'
&& ns.EndsWith(".Internal", StringComparison.Ordinal);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ namespace Microsoft.EntityFrameworkCore;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class UninitializedDbSetDiagnosticSuppressor : DiagnosticSuppressor
{
private static readonly SuppressionDescriptor _suppressUninitializedDbSetRule = new(
private static readonly SuppressionDescriptor SuppressUninitializedDbSetRule = new(
id: "SPR1001",
suppressedDiagnosticId: "CS8618",
justification: AnalyzerStrings.UninitializedDbSetWarningSuppressionJustification);

/// <inheritdoc />
public override ImmutableArray<SuppressionDescriptor> SupportedSuppressions { get; }
= ImmutableArray.Create(_suppressUninitializedDbSetRule);
= ImmutableArray.Create(SuppressUninitializedDbSetRule);

/// <inheritdoc />
public override void ReportSuppressions(SuppressionAnalysisContext context)
Expand Down
16 changes: 8 additions & 8 deletions src/EFCore.Cosmos/Diagnostics/CosmosEventId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private enum Id
ExecutedDeleteItem
}

private static readonly string _commandPrefix = DbLoggerCategory.Database.Command.Name + ".";
private static readonly string CommandPrefix = DbLoggerCategory.Database.Command.Name + ".";

/// <summary>
/// A SQL query is going to be executed.
Expand All @@ -50,7 +50,7 @@ private enum Id
/// </para>
/// </remarks>
public static readonly EventId ExecutingSqlQuery
= new((int)Id.ExecutingSqlQuery, _commandPrefix + Id.ExecutingSqlQuery);
= new((int)Id.ExecutingSqlQuery, CommandPrefix + Id.ExecutingSqlQuery);

/// <summary>
/// ReadItem is going to be executed.
Expand All @@ -64,7 +64,7 @@ public static readonly EventId ExecutingSqlQuery
/// </para>
/// </remarks>
public static readonly EventId ExecutingReadItem
= new((int)Id.ExecutingReadItem, _commandPrefix + Id.ExecutingReadItem);
= new((int)Id.ExecutingReadItem, CommandPrefix + Id.ExecutingReadItem);

/// <summary>
/// ReadNext was executed.
Expand All @@ -78,7 +78,7 @@ public static readonly EventId ExecutingReadItem
/// </para>
/// </remarks>
public static readonly EventId ExecutedReadNext
= new((int)Id.ExecutedReadNext, _commandPrefix + Id.ExecutedReadNext);
= new((int)Id.ExecutedReadNext, CommandPrefix + Id.ExecutedReadNext);

/// <summary>
/// ReadItem was executed.
Expand All @@ -92,7 +92,7 @@ public static readonly EventId ExecutedReadNext
/// </para>
/// </remarks>
public static readonly EventId ExecutedReadItem
= new((int)Id.ExecutedReadItem, _commandPrefix + Id.ExecutedReadItem);
= new((int)Id.ExecutedReadItem, CommandPrefix + Id.ExecutedReadItem);

/// <summary>
/// CreateItem was executed.
Expand All @@ -106,7 +106,7 @@ public static readonly EventId ExecutedReadItem
/// </para>
/// </remarks>
public static readonly EventId ExecutedCreateItem
= new((int)Id.ExecutedCreateItem, _commandPrefix + Id.ExecutedCreateItem);
= new((int)Id.ExecutedCreateItem, CommandPrefix + Id.ExecutedCreateItem);

/// <summary>
/// ReplaceItem was executed.
Expand All @@ -120,7 +120,7 @@ public static readonly EventId ExecutedCreateItem
/// </para>
/// </remarks>
public static readonly EventId ExecutedReplaceItem
= new((int)Id.ExecutedReplaceItem, _commandPrefix + Id.ExecutedReplaceItem);
= new((int)Id.ExecutedReplaceItem, CommandPrefix + Id.ExecutedReplaceItem);

/// <summary>
/// DeleteItem was executed.
Expand All @@ -134,5 +134,5 @@ public static readonly EventId ExecutedReplaceItem
/// </para>
/// </remarks>
public static readonly EventId ExecutedDeleteItem
= new((int)Id.ExecutedDeleteItem, _commandPrefix + Id.ExecutedDeleteItem);
= new((int)Id.ExecutedDeleteItem, CommandPrefix + Id.ExecutedDeleteItem);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal;
/// </summary>
public class CosmosProjectionBindingExpressionVisitor : ExpressionVisitor
{
private static readonly MethodInfo _getParameterValueMethodInfo
private static readonly MethodInfo GetParameterValueMethodInfo
= typeof(CosmosProjectionBindingExpressionVisitor)
.GetTypeInfo().GetDeclaredMethod(nameof(GetParameterValue));

Expand Down Expand Up @@ -124,7 +124,7 @@ public override Expression Visit(Expression expression)
== true)
{
return Expression.Call(
_getParameterValueMethodInfo.MakeGenericMethod(parameterExpression.Type),
GetParameterValueMethodInfo.MakeGenericMethod(parameterExpression.Type),
QueryCompilationContext.QueryContextParameter,
Expression.Constant(parameterExpression.Name));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ public partial class CosmosShapedQueryCompilingExpressionVisitor
{
private abstract class CosmosProjectionBindingRemovingExpressionVisitorBase : ExpressionVisitor
{
private static readonly MethodInfo _getItemMethodInfo
private static readonly MethodInfo GetItemMethodInfo
= typeof(JObject).GetRuntimeProperties()
.Single(pi => pi.Name == "Item" && pi.GetIndexParameters()[0].ParameterType == typeof(string))
.GetMethod;

private static readonly PropertyInfo _jTokenTypePropertyInfo
private static readonly PropertyInfo JTokenTypePropertyInfo
= typeof(JToken).GetRuntimeProperties()
.Single(mi => mi.Name == nameof(JToken.Type));

private static readonly MethodInfo _jTokenToObjectWithSerializerMethodInfo
private static readonly MethodInfo JTokenToObjectWithSerializerMethodInfo
= typeof(JToken).GetRuntimeMethods()
.Single(mi => mi.Name == nameof(JToken.ToObject) && mi.GetParameters().Length == 1 && mi.IsGenericMethodDefinition);

private static readonly MethodInfo _collectionAccessorAddMethodInfo
private static readonly MethodInfo CollectionAccessorAddMethodInfo
= typeof(IClrCollectionAccessor).GetTypeInfo()
.GetDeclaredMethod(nameof(IClrCollectionAccessor.Add));

private static readonly MethodInfo _collectionAccessorGetOrCreateMethodInfo
private static readonly MethodInfo CollectionAccessorGetOrCreateMethodInfo
= typeof(IClrCollectionAccessor).GetTypeInfo()
.GetDeclaredMethod(nameof(IClrCollectionAccessor.GetOrCreate));

Expand All @@ -55,7 +55,7 @@ private readonly IDictionary<Expression, Expression> _ordinalParameterBindings
private List<IncludeExpression> _pendingIncludes
= new();

private static readonly MethodInfo _toObjectWithSerializerMethodInfo
private static readonly MethodInfo ToObjectWithSerializerMethodInfo
= typeof(CosmosProjectionBindingRemovingExpressionVisitorBase)
.GetRuntimeMethods().Single(mi => mi.Name == nameof(SafeToObjectWithSerializer));

Expand Down Expand Up @@ -272,7 +272,7 @@ protected override Expression VisitExtension(Expression extensionExpression)

var navigation = collectionShaperExpression.Navigation;
return Expression.Call(
_populateCollectionMethodInfo.MakeGenericMethod(navigation.TargetEntityType.ClrType, navigation.ClrType),
PopulateCollectionMethodInfo.MakeGenericMethod(navigation.TargetEntityType.ClrType, navigation.ClrType),
Expression.Constant(navigation.GetCollectionAccessor()),
entities);
}
Expand Down Expand Up @@ -350,7 +350,7 @@ private void AddInclude(
{
// Cosmos does not support Includes for ISkipNavigation
var navigation = (INavigation)includeExpression.Navigation;
var includeMethod = navigation.IsCollection ? _includeCollectionMethodInfo : _includeReferenceMethodInfo;
var includeMethod = navigation.IsCollection ? IncludeCollectionMethodInfo : IncludeReferenceMethodInfo;
var includingClrType = navigation.DeclaringEntityType.ClrType;
var relatedEntityClrType = navigation.TargetEntityType.ClrType;
#pragma warning disable EF1001 // Internal EF Core API usage.
Expand Down Expand Up @@ -383,7 +383,7 @@ private void AddInclude(
#pragma warning restore EF1001 // Internal EF Core API usage.
}

private static readonly MethodInfo _includeReferenceMethodInfo
private static readonly MethodInfo IncludeReferenceMethodInfo
= typeof(CosmosProjectionBindingRemovingExpressionVisitorBase).GetTypeInfo()
.GetDeclaredMethod(nameof(IncludeReference));

Expand Down Expand Up @@ -429,7 +429,7 @@ private static void IncludeReference<TIncludingEntity, TIncludedEntity>(
}
}

private static readonly MethodInfo _includeCollectionMethodInfo
private static readonly MethodInfo IncludeCollectionMethodInfo
= typeof(CosmosProjectionBindingRemovingExpressionVisitorBase).GetTypeInfo()
.GetDeclaredMethod(nameof(IncludeCollection));

Expand Down Expand Up @@ -533,7 +533,7 @@ private static Delegate GenerateInitialize(

var getOrCreateExpression = Expression.Call(
Expression.Constant(navigation.GetCollectionAccessor()),
_collectionAccessorGetOrCreateMethodInfo,
CollectionAccessorGetOrCreateMethodInfo,
entityParameter,
Expression.Constant(true));

Expand All @@ -553,12 +553,12 @@ private static Expression AddToCollectionNavigation(
INavigation navigation)
=> Expression.Call(
Expression.Constant(navigation.GetCollectionAccessor()),
_collectionAccessorAddMethodInfo,
CollectionAccessorAddMethodInfo,
entity,
relatedEntity,
Expression.Constant(true));

private static readonly MethodInfo _populateCollectionMethodInfo
private static readonly MethodInfo PopulateCollectionMethodInfo
= typeof(CosmosProjectionBindingRemovingExpressionVisitorBase).GetTypeInfo()
.GetDeclaredMethod(nameof(PopulateCollection));

Expand All @@ -579,7 +579,7 @@ private static TCollection PopulateCollection<TEntity, TCollection>(
protected abstract ProjectionExpression GetProjection(ProjectionBindingExpression projectionBindingExpression);

private static Expression CreateReadJTokenExpression(Expression jObjectExpression, string propertyName)
=> Expression.Call(jObjectExpression, _getItemMethodInfo, Expression.Constant(propertyName));
=> Expression.Call(jObjectExpression, GetItemMethodInfo, Expression.Constant(propertyName));

private Expression CreateGetValueExpression(
Expression jObjectExpression,
Expand Down Expand Up @@ -685,7 +685,7 @@ var body
converter.ConvertFromProviderExpression.Parameters.Single(),
Expression.Call(
jTokenParameter,
_jTokenToObjectWithSerializerMethodInfo.MakeGenericMethod(converter.ProviderClrType),
JTokenToObjectWithSerializerMethodInfo.MakeGenericMethod(converter.ProviderClrType),
Expression.Constant(CosmosClientWrapper.Serializer)),
converter.ConvertFromProviderExpression.Body);

Expand Down Expand Up @@ -716,7 +716,7 @@ var body
Expression.OrElse(
Expression.Equal(jTokenParameter, Expression.Default(typeof(JToken))),
Expression.Equal(
Expression.MakeMemberAccess(jTokenParameter, _jTokenTypePropertyInfo),
Expression.MakeMemberAccess(jTokenParameter, JTokenTypePropertyInfo),
Expression.Constant(JTokenType.Null))),
replaceExpression,
body);
Expand All @@ -740,7 +740,7 @@ private static Expression ConvertJTokenToType(Expression jTokenExpression, Type
=> type == typeof(JToken)
? jTokenExpression
: Expression.Call(
_toObjectWithSerializerMethodInfo.MakeGenericMethod(type),
ToObjectWithSerializerMethodInfo.MakeGenericMethod(type),
jTokenExpression);

private static T SafeToObject<T>(JToken token)
Expand Down
Loading

0 comments on commit 329663f

Please sign in to comment.