Skip to content

Commit

Permalink
Code cleanup for miscellaneous packages (#22184)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Aug 23, 2020
1 parent 31e2302 commit cd38a21
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,35 @@ protected override void RemoveSortCore()
/// 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>
protected override bool IsSortedCore => _isSorted;
protected override bool IsSortedCore
=> _isSorted;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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>
protected override ListSortDirection SortDirectionCore => _sortDirection;
protected override ListSortDirection SortDirectionCore
=> _sortDirection;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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>
protected override PropertyDescriptor SortPropertyCore => _sortProperty;
protected override PropertyDescriptor SortPropertyCore
=> _sortProperty;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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>
protected override bool SupportsSortingCore => true;
protected override bool SupportsSortingCore
=> true;

private sealed class PropertyComparer : Comparer<T>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public ObservableCollectionListSource([NotNull] List<T> list)
/// <summary>
/// Always false because there is never a contained collection.
/// </summary>
bool IListSource.ContainsListCollection => false;
bool IListSource.ContainsListCollection
=> false;

/// <summary>
/// Returns an <see cref="IBindingList" /> implementation that stays in sync with
Expand All @@ -68,6 +69,7 @@ public ObservableCollectionListSource([NotNull] List<T> list)
/// <returns>
/// An <see cref="IBindingList" /> in sync with the ObservableCollection.
/// </returns>
IList IListSource.GetList() => _bindingList ?? (_bindingList = this.ToBindingList());
IList IListSource.GetList()
=> _bindingList ?? (_bindingList = this.ToBindingList());
}
}
3 changes: 2 additions & 1 deletion src/EFCore.Abstractions/DbFunctionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public virtual bool IsNullable
/// <summary>
/// Checks whether <see cref="IsNullable" /> has been explicitly set to a value.
/// </summary>
public bool IsNullableHasValue => _nullable.HasValue;
public bool IsNullableHasValue
=> _nullable.HasValue;
}
}
3 changes: 2 additions & 1 deletion src/EFCore.Abstractions/IndexAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public bool IsUnique
/// <summary>
/// Checks whether <see cref="IsUnique" /> has been explicitly set to a value.
/// </summary>
public bool IsUniqueHasValue => _isUnique.HasValue;
public bool IsUniqueHasValue
=> _isUnique.HasValue;
}
}
49 changes: 29 additions & 20 deletions src/EFCore.Analyzers/InternalUsageDiagnosticAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Operations;

using CSharpSyntax = Microsoft.CodeAnalysis.CSharp.Syntax;
using VBSyntax = Microsoft.CodeAnalysis.VisualBasic.Syntax;

Expand Down Expand Up @@ -37,14 +36,16 @@ private static readonly DiagnosticDescriptor _descriptor
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true);

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

public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);

context.RegisterOperationAction(AnalyzeNode,
context.RegisterOperationAction(
AnalyzeNode,
OperationKind.FieldReference,
OperationKind.PropertyReference,
OperationKind.MethodReference,
Expand All @@ -54,7 +55,8 @@ public override void Initialize(AnalysisContext context)
OperationKind.VariableDeclaration,
OperationKind.TypeOf);

context.RegisterSymbolAction(AnalyzeSymbol,
context.RegisterSymbolAction(
AnalyzeSymbol,
SymbolKind.NamedType,
SymbolKind.Method,
SymbolKind.Property,
Expand Down Expand Up @@ -93,11 +95,11 @@ private static void AnalyzeNode(OperationAnalysisContext context)
default:
throw new ArgumentException($"Unexpected {nameof(OperationKind)}: {context.Operation.Kind}");
}

}

private static void AnalyzeMember(OperationAnalysisContext context, ISymbol symbol)
{
// ReSharper disable once RedundantCast
if ((object)symbol.ContainingAssembly == context.Compilation.Assembly)
{
// Skip all methods inside the same assembly - internal access is fine
Expand Down Expand Up @@ -197,7 +199,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 @@ -228,6 +230,7 @@ private static void AnalyzeMethodTypeSymbol(SymbolAnalysisContext context, IMeth
// Property getters/setters are handled via IPropertySymbol
return;
}

if (IsInternal(context, symbol.ReturnType))
{
foreach (var declaringSyntax in symbol.DeclaringSyntaxReferences)
Expand Down Expand Up @@ -272,7 +275,8 @@ private static void AnalyzeMemberDeclarationTypeSymbol(
}

private static void ReportDiagnostic(OperationAnalysisContext context, object messageArg)
=> context.ReportDiagnostic(Diagnostic.Create(_descriptor, NarrowDownSyntax(context.Operation.Syntax).GetLocation(), messageArg));
=> context.ReportDiagnostic(
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));
Expand All @@ -285,20 +289,20 @@ 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
: (SyntaxNode)declarator,
CSharpSyntax.TypeOfExpressionSyntax s => s.Type,

VBSyntax.InvocationExpressionSyntax s
when s.Expression is VBSyntax.MemberAccessExpressionSyntax memberAccessSyntax
=> memberAccessSyntax.Name,
when s.Expression is VBSyntax.MemberAccessExpressionSyntax memberAccessSyntax
=> memberAccessSyntax.Name,
VBSyntax.MemberAccessExpressionSyntax s => s.Name,
VBSyntax.ObjectCreationExpressionSyntax s => s.Type,
VBSyntax.TypeOfExpressionSyntax s => s.Type,
Expand All @@ -307,17 +311,21 @@ when s.Expression is VBSyntax.MemberAccessExpressionSyntax memberAccessSyntax
};

private static bool IsInternal(SymbolAnalysisContext context, ITypeSymbol symbol)
// ReSharper disable once RedundantCast
=> (object)symbol.ContainingAssembly != context.Compilation.Assembly
&& (IsInInternalNamespace(symbol) || HasInternalAttribute(symbol));

private static bool IsInternal(OperationAnalysisContext context, ITypeSymbol symbol)
// ReSharper disable once RedundantCast
=> (object)symbol.ContainingAssembly != context.Compilation.Assembly
&& (IsInInternalNamespace(symbol) || HasInternalAttribute(symbol));

private static bool HasInternalAttribute(ISymbol symbol)
=> symbol != null
&& symbol.GetAttributes().Any(a =>
a.AttributeClass.ToDisplayString() == "Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkInternalAttribute");
&& symbol.GetAttributes().Any(
a =>
a.AttributeClass.ToDisplayString()
== "Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkInternalAttribute");

private static bool IsInInternalNamespace(ISymbol symbol)
{
Expand All @@ -326,10 +334,11 @@ private static bool IsInInternalNamespace(ISymbol symbol)
var i = ns.IndexOf("EntityFrameworkCore");

return
i != -1 &&
(i == 0 || ns[i - 1] == '.') &&
i + EFLen < ns.Length && ns[i + EFLen] == '.' &&
ns.EndsWith(".Internal", StringComparison.Ordinal);
i != -1
&& (i == 0 || ns[i - 1] == '.')
&& i + EFLen < ns.Length
&& ns[i + EFLen] == '.'
&& ns.EndsWith(".Internal", StringComparison.Ordinal);
}

return false;
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Proxies/Proxies/Internal/LazyLoadingInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public virtual void Intercept(IInvocation invocation)
?? (INavigationBase)_entityType.FindSkipNavigation(navigationName);

if (navigationBase != null
&& (!(navigationBase is INavigation navigation
&& navigation.ForeignKey.IsOwnership)))
&& (!(navigationBase is INavigation navigation
&& navigation.ForeignKey.IsOwnership)))
{
_loader.Load(invocation.Proxy, navigationName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public virtual void Intercept(IInvocation invocation)
{
var comparer = property.IsKey()
|| property.IsForeignKey()
? property.GetKeyValueComparer()
: property.GetValueComparer();
? property.GetKeyValueComparer()
: property.GetValueComparer();

HandleChanged(invocation, property, comparer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public virtual void Intercept(IInvocation invocation)
{
var comparer = property.IsKey()
|| property.IsForeignKey()
? property.GetKeyValueComparer()
: property.GetValueComparer();
? property.GetKeyValueComparer()
: property.GetValueComparer();

HandleChanging(invocation, property, comparer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public virtual ConventionSet ModifyConventions(ConventionSet conventionSet)
new ProxyChangeTrackingConvention(extension),
typeof(DbSetFindingConvention));

conventionSet.ModelFinalizingConventions.Add(new ProxyBindingRewriter(
conventionSet.ModelFinalizingConventions.Add(
new ProxyBindingRewriter(
_proxyFactory,
extension,
_lazyLoaderParameterBindingFactoryDependencies,
Expand Down
29 changes: 18 additions & 11 deletions src/EFCore.Proxies/Proxies/Internal/ProxiesOptionsExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,39 +64,44 @@ public virtual DbContextOptionsExtensionInfo Info
/// 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>
protected virtual ProxiesOptionsExtension Clone() => new ProxiesOptionsExtension(this);
protected virtual ProxiesOptionsExtension Clone()
=> new ProxiesOptionsExtension(this);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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 virtual bool UseLazyLoadingProxies => _useLazyLoadingProxies;
public virtual bool UseLazyLoadingProxies
=> _useLazyLoadingProxies;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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 virtual bool UseChangeTrackingProxies => _useChangeTrackingProxies;
public virtual bool UseChangeTrackingProxies
=> _useChangeTrackingProxies;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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 virtual bool CheckEquality => _checkEquality;
public virtual bool CheckEquality
=> _checkEquality;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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 virtual bool UseProxies => UseLazyLoadingProxies || UseChangeTrackingProxies;
public virtual bool UseProxies
=> UseLazyLoadingProxies || UseChangeTrackingProxies;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down Expand Up @@ -173,18 +178,20 @@ public ExtensionInfo(IDbContextOptionsExtension extension)
private new ProxiesOptionsExtension Extension
=> (ProxiesOptionsExtension)base.Extension;

public override bool IsDatabaseProvider => false;
public override bool IsDatabaseProvider
=> false;

public override string LogFragment
=> _logFragment ??= Extension.UseLazyLoadingProxies && Extension.UseChangeTrackingProxies
? "using lazy-loading and change tracking proxies "
: Extension.UseLazyLoadingProxies
? "using lazy-loading proxies "
: Extension.UseChangeTrackingProxies
? "using change tracking proxies "
: "";
? "using lazy-loading proxies "
: Extension.UseChangeTrackingProxies
? "using change tracking proxies "
: "";

public override long GetServiceProviderHashCode() => Extension.UseProxies ? 541 : 0;
public override long GetServiceProviderHashCode()
=> Extension.UseProxies ? 541 : 0;

public override void PopulateDebugInfo(IDictionary<string, string> debugInfo)
{
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore.Proxies/Proxies/Internal/ProxyBindingRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public ProxyBindingRewriter(

/// <inheritdoc />
public virtual void ProcessModelFinalizing(
IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
IConventionModelBuilder modelBuilder,
IConventionContext<IConventionModelBuilder> context)
{
if (_options?.UseProxies == true)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ProxyChangeTrackingConvention : IModelInitializedConvention
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public ProxyChangeTrackingConvention(
[CanBeNull] ProxiesOptionsExtension options)
[CanBeNull] ProxiesOptionsExtension options)
{
_options = options;
}
Expand All @@ -35,7 +35,9 @@ public ProxyChangeTrackingConvention(
/// </summary>
/// <param name="modelBuilder"> The builder for the model. </param>
/// <param name="context"> Additional information associated with convention execution. </param>
public virtual void ProcessModelInitialized(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
public virtual void ProcessModelInitialized(
IConventionModelBuilder modelBuilder,
IConventionContext<IConventionModelBuilder> context)
{
if (_options?.UseChangeTrackingProxies == true)
{
Expand Down
Loading

0 comments on commit cd38a21

Please sign in to comment.