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

Code cleanup #17410

Merged
merged 1 commit into from
Aug 26, 2019
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
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion All.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_EMBEDDED_STATEMENT_ON_SAME_LINE/@EntryValue">NEVER</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_INITIALIZER_ON_SINGLE_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_INITIALIZER_ON_SINGLE_LINE/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_LINQ_ON_SINGLE_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_WHILE_ON_NEW_LINE/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SIMPLE_EMBEDDED_STATEMENT_STYLE/@EntryValue">LINE_BREAK</s:String>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Abstractions/DbFunctionAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Abstractions/OwnedAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand Down
33 changes: 19 additions & 14 deletions src/EFCore.Analyzers/InternalUsageDiagnosticAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand All @@ -24,7 +24,7 @@ public const string MessageFormat
protected const string DefaultTitle = "Internal EF Core API usage.";
protected const string Category = "Usage";

static readonly int EFLen = "EntityFrameworkCore".Length;
private static readonly int EFLen = "EntityFrameworkCore".Length;

private static readonly DiagnosticDescriptor _descriptor
= new DiagnosticDescriptor(
Expand All @@ -40,7 +40,8 @@ private static readonly DiagnosticDescriptor _descriptor
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.RegisterSyntaxNodeAction(AnalyzeNode,
context.RegisterSyntaxNodeAction(
AnalyzeNode,
SyntaxKind.SimpleMemberAccessExpression,
SyntaxKind.ObjectCreationExpression,
SyntaxKind.ClassDeclaration);
Expand All @@ -52,30 +53,33 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
{
case MemberAccessExpressionSyntax memberAccessSyntax:
{
if (context.SemanticModel.GetSymbolInfo(context.Node, context.CancellationToken).Symbol is ISymbol symbol &&
symbol.ContainingAssembly != context.Compilation.Assembly)
if (context.SemanticModel.GetSymbolInfo(context.Node, context.CancellationToken).Symbol is ISymbol symbol
&& symbol.ContainingAssembly != context.Compilation.Assembly)
{
var containingType = symbol.ContainingType;

if (HasInternalAttribute(symbol))
{
context.ReportDiagnostic(Diagnostic.Create(_descriptor, memberAccessSyntax.Name.GetLocation(), $"{containingType}.{symbol.Name}"));
context.ReportDiagnostic(
Diagnostic.Create(_descriptor, memberAccessSyntax.Name.GetLocation(), $"{containingType}.{symbol.Name}"));
return;
}

if (IsInInternalNamespace(containingType) || HasInternalAttribute(containingType))
if (IsInInternalNamespace(containingType)
|| HasInternalAttribute(containingType))
{
context.ReportDiagnostic(Diagnostic.Create(_descriptor, memberAccessSyntax.Name.GetLocation(), containingType));
return;
}
}

return;
}

case ObjectCreationExpressionSyntax creationSyntax:
{
if (context.SemanticModel.GetSymbolInfo(context.Node, context.CancellationToken).Symbol is ISymbol symbol &&
symbol.ContainingAssembly != context.Compilation.Assembly)
if (context.SemanticModel.GetSymbolInfo(context.Node, context.CancellationToken).Symbol is ISymbol symbol
&& symbol.ContainingAssembly != context.Compilation.Assembly)
{
var containingType = symbol.ContainingType;

Expand All @@ -85,7 +89,8 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
return;
}

if (IsInInternalNamespace(containingType) || HasInternalAttribute(containingType))
if (IsInInternalNamespace(containingType)
|| HasInternalAttribute(containingType))
{
context.ReportDiagnostic(Diagnostic.Create(_descriptor, creationSyntax.Type.GetLocation(), containingType));
return;
Expand All @@ -97,10 +102,10 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)

case ClassDeclarationSyntax declarationSyntax:
{
if (context.SemanticModel.GetDeclaredSymbol(declarationSyntax)?.BaseType is ISymbol symbol &&
symbol.ContainingAssembly != context.Compilation.Assembly &&
(IsInInternalNamespace(symbol) || HasInternalAttribute(symbol)) &&
declarationSyntax.BaseList?.Types.Count > 0)
if (context.SemanticModel.GetDeclaredSymbol(declarationSyntax)?.BaseType is ISymbol symbol
&& symbol.ContainingAssembly != context.Compilation.Assembly
&& (IsInInternalNamespace(symbol) || HasInternalAttribute(symbol))
&& declarationSyntax.BaseList?.Types.Count > 0)
{
context.ReportDiagnostic(Diagnostic.Create(_descriptor, declarationSyntax.BaseList.Types[0].GetLocation(), symbol));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Cosmos.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Utilities;

// ReSharper disable once CheckNamespace
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand Down
8 changes: 5 additions & 3 deletions src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using JetBrains.Annotations;
Expand Down Expand Up @@ -101,7 +101,8 @@ public static void SetCosmosContainingPropertyName(
/// </summary>
/// <param name="entityType"> The entity type to find configuration source for. </param>
/// <returns> The <see cref="ConfigurationSource" /> for the parent property to which the entity type is mapped. </returns>
public static ConfigurationSource? GetCosmosContainingPropertyNameConfigurationSource([NotNull] this IConventionEntityType entityType)
public static ConfigurationSource? GetCosmosContainingPropertyNameConfigurationSource(
[NotNull] this IConventionEntityType entityType)
=> entityType.FindAnnotation(CosmosAnnotationNames.PropertyName)
?.GetConfigurationSource();

Expand Down Expand Up @@ -141,7 +142,8 @@ public static void SetCosmosPartitionKeyPropertyName(
/// </summary>
/// <param name="entityType"> The entity type to find configuration source for. </param>
/// <returns> The <see cref="ConfigurationSource" /> for the partition key property. </returns>
public static ConfigurationSource? GetCosmosPartitionKeyPropertyNameConfigurationSource([NotNull] this IConventionEntityType entityType)
public static ConfigurationSource? GetCosmosPartitionKeyPropertyNameConfigurationSource(
[NotNull] this IConventionEntityType entityType)
=> entityType.FindAnnotation(CosmosAnnotationNames.PartitionKeyName)
?.GetConfigurationSource();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using JetBrains.Annotations;
Expand Down
5 changes: 3 additions & 2 deletions src/EFCore.Cosmos/Extensions/CosmosModelExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using JetBrains.Annotations;
Expand Down Expand Up @@ -38,7 +38,8 @@ public static void SetCosmosDefaultContainer([NotNull] this IMutableModel model,
/// <param name="model"> The model. </param>
/// <param name="name"> The name to set. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetCosmosDefaultContainer([NotNull] this IConventionModel model, [CanBeNull] string name, bool fromDataAnnotation = false)
public static void SetCosmosDefaultContainer(
[NotNull] this IConventionModel model, [CanBeNull] string name, bool fromDataAnnotation = false)
=> model.SetOrRemoveAnnotation(
CosmosAnnotationNames.ContainerName,
Check.NullButNotEmpty(name, nameof(name)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using JetBrains.Annotations;
Expand Down
5 changes: 3 additions & 2 deletions src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Linq;
Expand Down Expand Up @@ -59,7 +59,8 @@ public static void SetCosmosPropertyName([NotNull] this IMutableProperty propert
/// <param name="property"> The property. </param>
/// <param name="name"> The name to set. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
public static void SetCosmosPropertyName([NotNull] this IConventionProperty property, [CanBeNull] string name, bool fromDataAnnotation = false)
public static void SetCosmosPropertyName(
[NotNull] this IConventionProperty property, [CanBeNull] string name, bool fromDataAnnotation = false)
=> property.SetOrRemoveAnnotation(
CosmosAnnotationNames.PropertyName,
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static class CosmosServiceCollectionExtensions
/// Calling this method is no longer necessary when building most applications, including those that
/// use dependency injection in ASP.NET or elsewhere.
/// It is only needed when building the internal service provider for use with
/// the <see cref="DbContextOptionsBuilder.UseInternalServiceProvider"/> method.
/// the <see cref="DbContextOptionsBuilder.UseInternalServiceProvider" /> method.
/// This is not recommend other than for some advanced scenarios.
/// </para>
/// </summary>
Expand Down Expand Up @@ -63,7 +63,6 @@ public static IServiceCollection AddEntityFrameworkCosmos([NotNull] this IServic
// New Query pipeline
.TryAdd<IQueryableMethodTranslatingExpressionVisitorFactory, CosmosQueryableMethodTranslatingExpressionVisitorFactory>()
.TryAdd<IShapedQueryCompilingExpressionVisitorFactory, CosmosShapedQueryCompilingExpressionVisitorFactory>()

.TryAdd<ISingletonOptions, ICosmosSingletonOptions>(p => p.GetService<ICosmosSingletonOptions>())
.TryAddProviderSpecificServices(
b => b
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public virtual CosmosDbContextOptionsBuilder ExecutionStrategy(
=> WithOption(e => e.WithExecutionStrategyFactory(Check.NotNull(getExecutionStrategy, nameof(getExecutionStrategy))));

/// <summary>
/// Configures the context to use the provided Region.
/// Configures the context to use the provided Region.
/// </summary>
/// <param name="region">CosmosDB region name</param>
public virtual CosmosDbContextOptionsBuilder Region([NotNull] string region)
=> WithOption(e => e.WithRegion(Check.NotNull(region, nameof(region))));

/// <summary>
/// Configures the context to use the provided connection mode.
/// Configures the context to use the provided connection mode.
/// </summary>
/// <param name="connectionMode">CosmosDB connection mode</param>
public virtual CosmosDbContextOptionsBuilder ConnectionMode(ConnectionMode connectionMode)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand Down Expand Up @@ -262,9 +262,11 @@ public override void PopulateDebugInfo(IDictionary<string, string> debugInfo)
{
Check.NotNull(debugInfo, nameof(debugInfo));

debugInfo["Cosmos:" + nameof(AccountEndpoint)] = Extension._accountEndpoint.GetHashCode().ToString(CultureInfo.InvariantCulture);
debugInfo["Cosmos:" + nameof(AccountEndpoint)] =
Extension._accountEndpoint.GetHashCode().ToString(CultureInfo.InvariantCulture);
debugInfo["Cosmos:" + nameof(AccountKey)] = Extension._accountKey.GetHashCode().ToString(CultureInfo.InvariantCulture);
debugInfo["Cosmos:" + nameof(CosmosDbContextOptionsBuilder.Region)] = (Extension._region?.GetHashCode() ?? 0).ToString(CultureInfo.InvariantCulture);
debugInfo["Cosmos:" + nameof(CosmosDbContextOptionsBuilder.Region)] =
(Extension._region?.GetHashCode() ?? 0).ToString(CultureInfo.InvariantCulture);
}

public override string LogFragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Infrastructure.Internal
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </para>
/// <para>
/// The service lifetime is <see cref="ServiceLifetime.Singleton"/>. This means a single instance
/// is used by many <see cref="DbContext"/> instances. The implementation must be thread-safe.
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped"/>.
/// The service lifetime is <see cref="ServiceLifetime.Singleton" />. This means a single instance
/// is used by many <see cref="DbContext" /> instances. The implementation must be thread-safe.
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped" />.
/// </para>
/// </summary>
public class CosmosSingletonOptions : ICosmosSingletonOptions
Expand Down Expand Up @@ -56,7 +56,6 @@ public class CosmosSingletonOptions : ICosmosSingletonOptions
/// </summary>
public virtual ConnectionMode? ConnectionMode { get; private set; }


/// <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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Infrastructure.Internal
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </para>
/// <para>
/// The service lifetime is <see cref="ServiceLifetime.Singleton"/> and multiple registrations
/// are allowed. This means a single instance of each service is used by many <see cref="DbContext"/>
/// The service lifetime is <see cref="ServiceLifetime.Singleton" /> and multiple registrations
/// are allowed. This means a single instance of each service is used by many <see cref="DbContext" />
/// instances. The implementation must be thread-safe.
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped"/>.
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped" />.
/// </para>
/// </summary>
public interface ICosmosSingletonOptions : ISingletonOptions
Expand Down
8 changes: 5 additions & 3 deletions src/EFCore.Cosmos/Internal/CosmosModelValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ protected virtual void ValidateSharedContainerCompatibility(
}

var keyType = nextPartitionKeyProperty.GetTypeMapping().Converter?.ProviderClrType
?? nextPartitionKeyProperty.ClrType;
?? nextPartitionKeyProperty.ClrType;
if (keyType != typeof(string))
{
throw new InvalidOperationException(CosmosStrings.PartitionKeyNonStringStoreType(
partitionKeyPropertyName, entityType.DisplayName(), keyType.ShortDisplayName()));
throw new InvalidOperationException(
CosmosStrings.PartitionKeyNonStringStoreType(
partitionKeyPropertyName, entityType.DisplayName(), keyType.ShortDisplayName()));
}

if (partitionKey == null)
Expand All @@ -115,6 +116,7 @@ protected virtual void ValidateSharedContainerCompatibility(
{
throw new InvalidOperationException(CosmosStrings.NoPartitionKey(firstEntityType.DisplayName(), container));
}

partitionKey = nextPartitionKeyProperty;
}
else if (partitionKey.GetCosmosPropertyName() != nextPartitionKeyProperty.GetCosmosPropertyName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ private static bool Any([NotNull] IEnumerable source)
return false;
}


/// <summary>
/// Called after the base type of an entity type changes.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using JetBrains.Annotations;
Expand Down
Loading