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

[6.0] Code cleanup for remaining product projects #26164

Merged
merged 2 commits into from
Sep 24, 2021
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions src/EFCore.Abstractions/DbFunctionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Utilities;
using CA = System.Diagnostics.CodeAnalysis;

namespace Microsoft.EntityFrameworkCore
{
Expand Down Expand Up @@ -48,7 +48,7 @@ public DbFunctionAttribute(string name, string? schema = null)
/// <summary>
/// The name of the function in the database.
/// </summary>
[CA.DisallowNull]
[DisallowNull]
public virtual string? Name
{
get => _name;
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Abstractions/Infrastructure/ILazyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void SetLoaded(
/// <param name="cancellationToken"> A <see cref="CancellationToken" /> to observe while waiting for the task to complete. </param>
/// <param name="navigationName"> The navigation property name. </param>
/// <returns> A task that represents the asynchronous operation. </returns>
/// <exception cref="OperationCanceledException"> If the <see cref="CancellationToken"/> is canceled. </exception>
/// <exception cref="OperationCanceledException"> If the <see cref="CancellationToken" /> is canceled. </exception>
#pragma warning disable CA1068 // CancellationToken parameters must come last
Task LoadAsync(
#pragma warning restore CA1068 // CancellationToken parameters must come last
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Abstractions/PrecisionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see> for more information.
/// </remarks>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class PrecisionAttribute : Attribute
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Abstractions/UnicodeAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.EntityFrameworkCore
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see> for more information.
/// </remarks>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public sealed class UnicodeAttribute : Attribute
{
/// <summary>
Expand Down
12 changes: 6 additions & 6 deletions src/EFCore.Analyzers/InternalUsageDiagnosticAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private static void AnalyzeNamedTypeSymbol(SymbolAnalysisContext context, INamed
var location = declaringSyntax.GetSyntax() switch
{
CSharpSyntax.ClassDeclarationSyntax s when s.BaseList?.Types.Count > 0
=> s.BaseList.Types[0].GetLocation(),
=> s.BaseList.Types[0].GetLocation(),
{ } otherSyntax => otherSyntax.GetLocation()
};

Expand Down Expand Up @@ -288,15 +288,15 @@ private static SyntaxNode NarrowDownSyntax(SyntaxNode syntax)
=> syntax switch
{
CSharpSyntax.InvocationExpressionSyntax s
when s.Expression is CSharpSyntax.MemberAccessExpressionSyntax memberAccessSyntax
=> memberAccessSyntax.Name,
when s.Expression is CSharpSyntax.MemberAccessExpressionSyntax memberAccessSyntax
=> memberAccessSyntax.Name,
CSharpSyntax.MemberAccessExpressionSyntax s => s.Name,
CSharpSyntax.ObjectCreationExpressionSyntax s => s.Type,
CSharpSyntax.PropertyDeclarationSyntax s => s.Type,
CSharpSyntax.VariableDeclaratorSyntax declarator
=> declarator.Parent is CSharpSyntax.VariableDeclarationSyntax declaration
? declaration.Type
: (SyntaxNode)declarator,
=> declarator.Parent is CSharpSyntax.VariableDeclarationSyntax declaration
? declaration.Type
: declarator,
CSharpSyntax.TypeOfExpressionSyntax s => s.Type,

// TODO: VB syntax narrowing (#22085)
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore.Cosmos/ChangeTracking/Internal/ListComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public ListComparer(ValueComparer elementComparer, bool readOnly)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override Type Type => typeof(TCollection);
public override Type Type
=> typeof(TCollection);

private static bool Compare(TCollection? a, TCollection? b, ValueComparer<TElement> elementComparer)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public NullableListComparer(ValueComparer elementComparer, bool readOnly)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override Type Type => typeof(TCollection);
public override Type Type
=> typeof(TCollection);

private static bool Compare(TCollection? a, TCollection? b, ValueComparer<TElement> elementComparer)
{
Expand Down Expand Up @@ -68,6 +69,7 @@ private static bool Compare(TCollection? a, TCollection? b, ValueComparer<TEleme

return false;
}

if (bElement is null || !elementComparer.Equals(aElement, bElement))
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ public sealed class NullableSingleDimensionalArrayComparer<TElement> : ValueComp
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public NullableSingleDimensionalArrayComparer(ValueComparer elementComparer) : base(
(a, b) => Compare(a, b, (ValueComparer<TElement>)elementComparer),
o => GetHashCode(o, (ValueComparer<TElement>)elementComparer),
source => Snapshot(source, (ValueComparer<TElement>)elementComparer))
public NullableSingleDimensionalArrayComparer(ValueComparer elementComparer)
: base(
(a, b) => Compare(a, b, (ValueComparer<TElement>)elementComparer),
o => GetHashCode(o, (ValueComparer<TElement>)elementComparer),
source => Snapshot(source, (ValueComparer<TElement>)elementComparer))
{
}

Expand All @@ -35,7 +36,8 @@ public NullableSingleDimensionalArrayComparer(ValueComparer elementComparer) : b
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override Type Type => typeof(TElement?[]);
public override Type Type
=> typeof(TElement?[]);

private static bool Compare(TElement?[]? a, TElement?[]? b, ValueComparer<TElement> elementComparer)
{
Expand Down Expand Up @@ -66,6 +68,7 @@ private static bool Compare(TElement?[]? a, TElement?[]? b, ValueComparer<TEleme

return false;
}

if (bElement is null || !elementComparer.Equals(aElement, bElement))
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public NullableStringDictionaryComparer(ValueComparer elementComparer, bool read
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override Type Type => typeof(TCollection);
public override Type Type
=> typeof(TCollection);

private static bool Compare(TCollection? a, TCollection? b, ValueComparer<TElement> elementComparer)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ public sealed class SingleDimensionalArrayComparer<TElement> : ValueComparer<TEl
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public SingleDimensionalArrayComparer(ValueComparer elementComparer) : base(
(a, b) => Compare(a, b, (ValueComparer<TElement>)elementComparer),
o => GetHashCode(o, (ValueComparer<TElement>)elementComparer),
source => Snapshot(source, (ValueComparer<TElement>)elementComparer))
public SingleDimensionalArrayComparer(ValueComparer elementComparer)
: base(
(a, b) => Compare(a, b, (ValueComparer<TElement>)elementComparer),
o => GetHashCode(o, (ValueComparer<TElement>)elementComparer),
source => Snapshot(source, (ValueComparer<TElement>)elementComparer))
{
}

Expand All @@ -34,7 +35,8 @@ public SingleDimensionalArrayComparer(ValueComparer elementComparer) : base(
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override Type Type => typeof(TElement[]);
public override Type Type
=> typeof(TElement[]);

private static bool Compare(TElement[]? a, TElement[]? b, ValueComparer<TElement> elementComparer)
{
Expand Down Expand Up @@ -84,6 +86,7 @@ private static TElement[] Snapshot(TElement[] source, ValueComparer<TElement> el
var element = source[i];
snapshot[i] = element is null ? default! : elementComparer.Snapshot(element);
}

return snapshot;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public StringDictionaryComparer(ValueComparer elementComparer, bool readOnly)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override Type Type => typeof(TCollection);
public override Type Type
=> typeof(TCollection);

private static bool Compare(TCollection? a, TCollection? b, ValueComparer<TElement> elementComparer)
{
Expand Down
12 changes: 6 additions & 6 deletions src/EFCore.Cosmos/Diagnostics/CosmosEventId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static readonly EventId ExecutingSqlQuery
/// </para>
/// </summary>
public static readonly EventId ExecutingReadItem
= new((int)Id.ExecutingReadItem, _commandPrefix + Id.ExecutingReadItem);
= new((int)Id.ExecutingReadItem, _commandPrefix + Id.ExecutingReadItem);

/// <summary>
/// <para>
Expand All @@ -81,7 +81,7 @@ public static readonly EventId ExecutingReadItem
/// </para>
/// </summary>
public static readonly EventId ExecutedReadNext
= new((int)Id.ExecutedReadNext, _commandPrefix + Id.ExecutedReadNext);
= new((int)Id.ExecutedReadNext, _commandPrefix + Id.ExecutedReadNext);

/// <summary>
/// <para>
Expand All @@ -95,7 +95,7 @@ public static readonly EventId ExecutedReadNext
/// </para>
/// </summary>
public static readonly EventId ExecutedReadItem
= new((int)Id.ExecutedReadItem, _commandPrefix + Id.ExecutedReadItem);
= new((int)Id.ExecutedReadItem, _commandPrefix + Id.ExecutedReadItem);

/// <summary>
/// <para>
Expand All @@ -109,7 +109,7 @@ public static readonly EventId ExecutedReadItem
/// </para>
/// </summary>
public static readonly EventId ExecutedCreateItem
= new((int)Id.ExecutedCreateItem, _commandPrefix + Id.ExecutedCreateItem);
= new((int)Id.ExecutedCreateItem, _commandPrefix + Id.ExecutedCreateItem);

/// <summary>
/// <para>
Expand All @@ -123,7 +123,7 @@ public static readonly EventId ExecutedCreateItem
/// </para>
/// </summary>
public static readonly EventId ExecutedReplaceItem
= new((int)Id.ExecutedReplaceItem, _commandPrefix + Id.ExecutedReplaceItem);
= new((int)Id.ExecutedReplaceItem, _commandPrefix + Id.ExecutedReplaceItem);

/// <summary>
/// <para>
Expand All @@ -137,6 +137,6 @@ public static readonly EventId ExecutedReplaceItem
/// </para>
/// </summary>
public static readonly EventId ExecutedDeleteItem
= new((int)Id.ExecutedDeleteItem, _commandPrefix + Id.ExecutedDeleteItem);
= new((int)Id.ExecutedDeleteItem, _commandPrefix + Id.ExecutedDeleteItem);
}
}
62 changes: 33 additions & 29 deletions src/EFCore.Cosmos/Diagnostics/Internal/CosmosLoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static void ExecutingReadItem(
diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled);
}
}

private static string ExecutingReadItem(EventDefinitionBase definition, EventData payload)
{
var d = (EventDefinition<string, string, string?>)definition;
Expand Down Expand Up @@ -213,7 +213,8 @@ public static void ExecutedReadItem(
if (diagnostics.ShouldLog(definition))
{
var logSensitiveData = diagnostics.ShouldLogSensitiveData();
definition.Log(diagnostics,
definition.Log(
diagnostics,
elapsed.TotalMilliseconds.ToString(),
requestCharge.ToString(),
activityId,
Expand Down Expand Up @@ -244,12 +245,12 @@ private static string ExecutedReadItem(EventDefinitionBase definition, EventData
var d = (EventDefinition<string, string, string, string, string, string?>)definition;
var p = (CosmosItemCommandExecutedEventData)payload;
return d.GenerateMessage(
p.Elapsed.Milliseconds.ToString(),
p.RequestCharge.ToString(),
p.ActivityId,
p.ContainerId,
p.LogSensitiveData ? p.ResourceId : "?",
p.LogSensitiveData ? p.PartitionKey : "?");
p.Elapsed.Milliseconds.ToString(),
p.RequestCharge.ToString(),
p.ActivityId,
p.ContainerId,
p.LogSensitiveData ? p.ResourceId : "?",
p.LogSensitiveData ? p.PartitionKey : "?");
}

/// <summary>
Expand All @@ -272,7 +273,8 @@ public static void ExecutedCreateItem(
if (diagnostics.ShouldLog(definition))
{
var logSensitiveData = diagnostics.ShouldLogSensitiveData();
definition.Log(diagnostics,
definition.Log(
diagnostics,
elapsed.TotalMilliseconds.ToString(),
requestCharge.ToString(),
activityId,
Expand Down Expand Up @@ -303,12 +305,12 @@ private static string ExecutedCreateItem(EventDefinitionBase definition, EventDa
var d = (EventDefinition<string, string, string, string, string, string?>)definition;
var p = (CosmosItemCommandExecutedEventData)payload;
return d.GenerateMessage(
p.Elapsed.Milliseconds.ToString(),
p.RequestCharge.ToString(),
p.ActivityId,
p.ContainerId,
p.LogSensitiveData ? p.ResourceId : "?",
p.LogSensitiveData ? p.PartitionKey : "?");
p.Elapsed.Milliseconds.ToString(),
p.RequestCharge.ToString(),
p.ActivityId,
p.ContainerId,
p.LogSensitiveData ? p.ResourceId : "?",
p.LogSensitiveData ? p.PartitionKey : "?");
}

/// <summary>
Expand All @@ -331,7 +333,8 @@ public static void ExecutedDeleteItem(
if (diagnostics.ShouldLog(definition))
{
var logSensitiveData = diagnostics.ShouldLogSensitiveData();
definition.Log(diagnostics,
definition.Log(
diagnostics,
elapsed.TotalMilliseconds.ToString(),
requestCharge.ToString(),
activityId,
Expand Down Expand Up @@ -362,12 +365,12 @@ private static string ExecutedDeleteItem(EventDefinitionBase definition, EventDa
var d = (EventDefinition<string, string, string, string, string, string?>)definition;
var p = (CosmosItemCommandExecutedEventData)payload;
return d.GenerateMessage(
p.Elapsed.Milliseconds.ToString(),
p.RequestCharge.ToString(),
p.ActivityId,
p.ContainerId,
p.LogSensitiveData ? p.ResourceId : "?",
p.LogSensitiveData ? p.PartitionKey : "?");
p.Elapsed.Milliseconds.ToString(),
p.RequestCharge.ToString(),
p.ActivityId,
p.ContainerId,
p.LogSensitiveData ? p.ResourceId : "?",
p.LogSensitiveData ? p.PartitionKey : "?");
}

/// <summary>
Expand All @@ -390,7 +393,8 @@ public static void ExecutedReplaceItem(
if (diagnostics.ShouldLog(definition))
{
var logSensitiveData = diagnostics.ShouldLogSensitiveData();
definition.Log(diagnostics,
definition.Log(
diagnostics,
elapsed.TotalMilliseconds.ToString(),
requestCharge.ToString(),
activityId,
Expand Down Expand Up @@ -421,12 +425,12 @@ private static string ExecutedReplaceItem(EventDefinitionBase definition, EventD
var d = (EventDefinition<string, string, string, string, string, string?>)definition;
var p = (CosmosItemCommandExecutedEventData)payload;
return d.GenerateMessage(
p.Elapsed.Milliseconds.ToString(),
p.RequestCharge.ToString(),
p.ActivityId,
p.ContainerId,
p.LogSensitiveData ? p.ResourceId : "?",
p.LogSensitiveData ? p.PartitionKey : "?");
p.Elapsed.Milliseconds.ToString(),
p.RequestCharge.ToString(),
p.ActivityId,
p.ContainerId,
p.LogSensitiveData ? p.ResourceId : "?",
p.LogSensitiveData ? p.PartitionKey : "?");
}

private static string FormatParameters(IReadOnlyList<(string Name, object? Value)> parameters, bool shouldLogParameterValues)
Expand Down
Loading