mirror of
https://github.com/fergalmoran/EFCore.NamingConventions.git
synced 2025-12-22 09:38:21 +00:00
File-scoped namespaces
This commit is contained in:
@@ -14,10 +14,10 @@ using Microsoft.EntityFrameworkCore.TestUtilities;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit;
|
||||
|
||||
namespace EFCore.NamingConventions.Test
|
||||
namespace EFCore.NamingConventions.Test;
|
||||
|
||||
public class NameRewritingConventionTest
|
||||
{
|
||||
public class NameRewritingConventionTest
|
||||
{
|
||||
[Fact]
|
||||
public void Table()
|
||||
{
|
||||
@@ -561,5 +561,4 @@ namespace EFCore.NamingConventions.Test
|
||||
{
|
||||
public int OwnedProperty { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@ using System.Globalization;
|
||||
using EFCore.NamingConventions.Internal;
|
||||
using Xunit;
|
||||
|
||||
namespace EFCore.NamingConventions.Test
|
||||
namespace EFCore.NamingConventions.Test;
|
||||
|
||||
public class RewriterTest
|
||||
{
|
||||
public class RewriterTest
|
||||
{
|
||||
[Fact]
|
||||
public void SnakeCase()
|
||||
=> Assert.Equal("full_name",
|
||||
@@ -30,5 +30,4 @@ namespace EFCore.NamingConventions.Test
|
||||
public void UpperCase()
|
||||
=> Assert.Equal("FULLNAME",
|
||||
new UpperCaseNameRewriter(CultureInfo.InvariantCulture).RewriteName("FullName"));
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,10 @@ using Microsoft.EntityFrameworkCore.Sqlite.Diagnostics.Internal;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace Microsoft.EntityFrameworkCore.TestUtilities
|
||||
namespace Microsoft.EntityFrameworkCore.TestUtilities;
|
||||
|
||||
public class SqliteTestHelpers : TestHelpers
|
||||
{
|
||||
public class SqliteTestHelpers : TestHelpers
|
||||
{
|
||||
protected SqliteTestHelpers()
|
||||
{
|
||||
}
|
||||
@@ -26,5 +26,4 @@ namespace Microsoft.EntityFrameworkCore.TestUtilities
|
||||
#pragma warning disable EF1001
|
||||
public override LoggingDefinitions LoggingDefinitions { get; } = new SqliteLoggingDefinitions();
|
||||
#pragma warning restore EF1001
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@ using JetBrains.Annotations;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace Microsoft.EntityFrameworkCore
|
||||
namespace Microsoft.EntityFrameworkCore;
|
||||
|
||||
[DebuggerStepThrough]
|
||||
internal static class Check
|
||||
{
|
||||
[DebuggerStepThrough]
|
||||
internal static class Check
|
||||
{
|
||||
[ContractAnnotation("value:null => halt")]
|
||||
public static T NotNull<T>([NoEnumeration] T value, [InvokerParameterName] [NotNull] string parameterName)
|
||||
{
|
||||
@@ -106,5 +106,4 @@ namespace Microsoft.EntityFrameworkCore
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,37 @@
|
||||
using System;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace JetBrains.Annotations
|
||||
namespace JetBrains.Annotations;
|
||||
|
||||
[AttributeUsage(
|
||||
AttributeTargets.Method | AttributeTargets.Parameter |
|
||||
AttributeTargets.Property | AttributeTargets.Delegate |
|
||||
AttributeTargets.Field)]
|
||||
internal sealed class NotNullAttribute : Attribute
|
||||
{
|
||||
[AttributeUsage(
|
||||
}
|
||||
|
||||
[AttributeUsage(
|
||||
AttributeTargets.Method | AttributeTargets.Parameter |
|
||||
AttributeTargets.Property | AttributeTargets.Delegate |
|
||||
AttributeTargets.Field)]
|
||||
internal sealed class NotNullAttribute : Attribute
|
||||
{
|
||||
}
|
||||
internal sealed class CanBeNullAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
[AttributeUsage(
|
||||
AttributeTargets.Method | AttributeTargets.Parameter |
|
||||
AttributeTargets.Property | AttributeTargets.Delegate |
|
||||
AttributeTargets.Field)]
|
||||
internal sealed class CanBeNullAttribute : Attribute
|
||||
{
|
||||
}
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
internal sealed class InvokerParameterNameAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
internal sealed class InvokerParameterNameAttribute : Attribute
|
||||
{
|
||||
}
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
internal sealed class NoEnumerationAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
internal sealed class NoEnumerationAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
|
||||
internal sealed class ContractAnnotationAttribute : Attribute
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
|
||||
internal sealed class ContractAnnotationAttribute : Attribute
|
||||
{
|
||||
public string Contract { get; }
|
||||
|
||||
public bool ForceFullStates { get; }
|
||||
@@ -46,11 +46,11 @@ namespace JetBrains.Annotations
|
||||
Contract = contract;
|
||||
ForceFullStates = forceFullStates;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.All)]
|
||||
internal sealed class UsedImplicitlyAttribute : Attribute
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.All)]
|
||||
internal sealed class UsedImplicitlyAttribute : Attribute
|
||||
{
|
||||
public UsedImplicitlyAttribute()
|
||||
: this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default)
|
||||
{
|
||||
@@ -75,34 +75,33 @@ namespace JetBrains.Annotations
|
||||
|
||||
public ImplicitUseKindFlags UseKindFlags { get; }
|
||||
public ImplicitUseTargetFlags TargetFlags { get; }
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Delegate)]
|
||||
internal sealed class StringFormatMethodAttribute : Attribute
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Delegate)]
|
||||
internal sealed class StringFormatMethodAttribute : Attribute
|
||||
{
|
||||
public StringFormatMethodAttribute([NotNull] string formatParameterName)
|
||||
=> FormatParameterName = formatParameterName;
|
||||
|
||||
[NotNull]
|
||||
public string FormatParameterName { get; }
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
internal enum ImplicitUseKindFlags
|
||||
{
|
||||
[Flags]
|
||||
internal enum ImplicitUseKindFlags
|
||||
{
|
||||
Default = Access | Assign | InstantiatedWithFixedConstructorSignature,
|
||||
Access = 1,
|
||||
Assign = 2,
|
||||
InstantiatedWithFixedConstructorSignature = 4,
|
||||
InstantiatedNoFixedConstructorSignature = 8
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
internal enum ImplicitUseTargetFlags
|
||||
{
|
||||
[Flags]
|
||||
internal enum ImplicitUseTargetFlags
|
||||
{
|
||||
Default = Itself,
|
||||
Itself = 1,
|
||||
Members = 2,
|
||||
WithMembers = Itself | Members
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace EFCore.NamingConventions.Internal
|
||||
namespace EFCore.NamingConventions.Internal;
|
||||
|
||||
public class CamelCaseNameRewriter : INameRewriter
|
||||
{
|
||||
public class CamelCaseNameRewriter : INameRewriter
|
||||
{
|
||||
private readonly CultureInfo _culture;
|
||||
|
||||
public CamelCaseNameRewriter(CultureInfo culture) => _culture = culture;
|
||||
|
||||
public string RewriteName(string name) =>
|
||||
string.IsNullOrEmpty(name) ? name: char.ToLower(name[0], _culture) + name.Substring(1);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
namespace EFCore.NamingConventions.Internal
|
||||
namespace EFCore.NamingConventions.Internal;
|
||||
|
||||
public interface INameRewriter
|
||||
{
|
||||
public interface INameRewriter
|
||||
{
|
||||
string RewriteName(string name);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace EFCore.NamingConventions.Internal
|
||||
namespace EFCore.NamingConventions.Internal;
|
||||
|
||||
public class LowerCaseNameRewriter : INameRewriter
|
||||
{
|
||||
public class LowerCaseNameRewriter : INameRewriter
|
||||
{
|
||||
private readonly CultureInfo _culture;
|
||||
|
||||
public LowerCaseNameRewriter(CultureInfo culture) => _culture = culture;
|
||||
public string RewriteName(string name) => name.ToLower(_culture);
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,9 @@ using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
|
||||
|
||||
namespace EFCore.NamingConventions.Internal
|
||||
{
|
||||
public class NameRewritingConvention :
|
||||
namespace EFCore.NamingConventions.Internal;
|
||||
|
||||
public class NameRewritingConvention :
|
||||
IEntityTypeAddedConvention,
|
||||
IEntityTypeAnnotationChangedConvention,
|
||||
IPropertyAddedConvention,
|
||||
@@ -17,7 +17,7 @@ namespace EFCore.NamingConventions.Internal
|
||||
IIndexAddedConvention,
|
||||
IEntityTypeBaseTypeChangedConvention,
|
||||
IModelFinalizingConvention
|
||||
{
|
||||
{
|
||||
private static readonly StoreObjectType[] _storeObjectTypes
|
||||
= { StoreObjectType.Table, StoreObjectType.View, StoreObjectType.Function, StoreObjectType.SqlQuery };
|
||||
|
||||
@@ -278,5 +278,4 @@ namespace EFCore.NamingConventions.Internal
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
namespace EFCore.NamingConventions.Internal
|
||||
namespace EFCore.NamingConventions.Internal;
|
||||
|
||||
public enum NamingConvention
|
||||
{
|
||||
public enum NamingConvention
|
||||
{
|
||||
None,
|
||||
SnakeCase,
|
||||
LowerCase,
|
||||
CamelCase,
|
||||
UpperCase,
|
||||
UpperSnakeCase
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace EFCore.NamingConventions.Internal
|
||||
namespace EFCore.NamingConventions.Internal;
|
||||
|
||||
public class NamingConventionSetPlugin : IConventionSetPlugin
|
||||
{
|
||||
public class NamingConventionSetPlugin : IConventionSetPlugin
|
||||
{
|
||||
private readonly IDbContextOptions _options;
|
||||
public NamingConventionSetPlugin([NotNull] IDbContextOptions options) => _options = options;
|
||||
|
||||
@@ -44,5 +44,4 @@ namespace EFCore.NamingConventions.Internal
|
||||
|
||||
return conventionSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,10 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace EFCore.NamingConventions.Internal
|
||||
namespace EFCore.NamingConventions.Internal;
|
||||
|
||||
public class NamingConventionsOptionsExtension : IDbContextOptionsExtension
|
||||
{
|
||||
public class NamingConventionsOptionsExtension : IDbContextOptionsExtension
|
||||
{
|
||||
private DbContextOptionsExtensionInfo _info;
|
||||
private NamingConvention _namingConvention;
|
||||
private CultureInfo _culture;
|
||||
@@ -145,5 +145,4 @@ namespace EFCore.NamingConventions.Internal
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@ using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace EFCore.NamingConventions.Internal
|
||||
namespace EFCore.NamingConventions.Internal;
|
||||
|
||||
public class SnakeCaseNameRewriter : INameRewriter
|
||||
{
|
||||
public class SnakeCaseNameRewriter : INameRewriter
|
||||
{
|
||||
private readonly CultureInfo _culture;
|
||||
|
||||
public SnakeCaseNameRewriter(CultureInfo culture) => _culture = culture;
|
||||
@@ -71,5 +71,4 @@ namespace EFCore.NamingConventions.Internal
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace EFCore.NamingConventions.Internal
|
||||
namespace EFCore.NamingConventions.Internal;
|
||||
|
||||
public class UpperCaseNameRewriter : INameRewriter
|
||||
{
|
||||
public class UpperCaseNameRewriter : INameRewriter
|
||||
{
|
||||
private readonly CultureInfo _culture;
|
||||
|
||||
public UpperCaseNameRewriter(CultureInfo culture) => _culture = culture;
|
||||
public string RewriteName(string name) => name.ToUpper(_culture);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace EFCore.NamingConventions.Internal
|
||||
namespace EFCore.NamingConventions.Internal;
|
||||
|
||||
public class UpperSnakeCaseNameRewriter : SnakeCaseNameRewriter
|
||||
{
|
||||
public class UpperSnakeCaseNameRewriter : SnakeCaseNameRewriter
|
||||
{
|
||||
private readonly CultureInfo _culture;
|
||||
|
||||
public UpperSnakeCaseNameRewriter(CultureInfo culture) : base(culture) => _culture = culture;
|
||||
|
||||
public override string RewriteName(string name) => base.RewriteName(name).ToUpper(_culture);
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,10 @@ using JetBrains.Annotations;
|
||||
using EFCore.NamingConventions.Internal;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace Microsoft.EntityFrameworkCore
|
||||
namespace Microsoft.EntityFrameworkCore;
|
||||
|
||||
public static class NamingConventionsExtensions
|
||||
{
|
||||
public static class NamingConventionsExtensions
|
||||
{
|
||||
public static DbContextOptionsBuilder UseSnakeCaseNamingConvention(
|
||||
[NotNull] this DbContextOptionsBuilder optionsBuilder , CultureInfo culture = null)
|
||||
{
|
||||
@@ -102,5 +102,4 @@ namespace Microsoft.EntityFrameworkCore
|
||||
[NotNull] this DbContextOptionsBuilder<TContext> optionsBuilder, CultureInfo culture = null)
|
||||
where TContext : DbContext
|
||||
=> (DbContextOptionsBuilder<TContext>)UseCamelCaseNamingConvention((DbContextOptionsBuilder)optionsBuilder, culture);
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,13 @@ using EFCore.NamingConventions.Internal;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
namespace Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="Microsoft.Extensions.DependencyInjection.IServiceCollection" />.
|
||||
/// </summary>
|
||||
public static class NamingConventionsServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="Microsoft.Extensions.DependencyInjection.IServiceCollection" />.
|
||||
/// </summary>
|
||||
public static class NamingConventionsServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// Adds the services required for applying naming conventions in Entity Framework Core.
|
||||
@@ -38,5 +38,4 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||
|
||||
return serviceCollection;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user