From 2788003d92fb1d024721cfe534b24a5d1ac0171e Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Fri, 31 Jul 2020 19:51:52 +0300 Subject: [PATCH] Un-expose some methods on CSharpSnapshotGenerator (#21875) Part of #20409 (July 22) --- .../Design/CSharpSnapshotGenerator.cs | 194 ++++++++---------- 1 file changed, 87 insertions(+), 107 deletions(-) diff --git a/src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs b/src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs index c8a8ae5c8ab..ae5435a603c 100644 --- a/src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs +++ b/src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs @@ -1206,113 +1206,6 @@ protected virtual void GenerateAnnotations( } } - /// - /// Generates a Fluent API call for the max length configuration. - /// - /// The property. - /// The builder code is added to. - protected virtual void GenerateFluentApiForMaxLength( - [NotNull] IProperty property, - [NotNull] IndentedStringBuilder stringBuilder) - { - if (property.GetMaxLength() is int maxLength) - { - stringBuilder - .AppendLine() - .Append(".") - .Append(nameof(PropertyBuilder.HasMaxLength)) - .Append("(") - .Append(Code.Literal(maxLength)) - .Append(")"); - } - } - - /// - /// Generates a Fluent API call for the Precision and Scale configuration. - /// - /// The property. - /// The builder code is added to. - protected virtual void GenerateFluentApiForPrecisionAndScale( - [NotNull] IProperty property, - [NotNull] IndentedStringBuilder stringBuilder) - { - if (property.GetPrecision() is int precision) - { - stringBuilder - .AppendLine() - .Append(".") - .Append(nameof(PropertyBuilder.HasPrecision)) - .Append("(") - .Append(Code.UnknownLiteral(precision)); - - if (property.GetScale() is int scale) - { - if (scale != 0) - { - stringBuilder - .Append(", ") - .Append(Code.UnknownLiteral(scale)); - } - } - - stringBuilder.Append(")"); - } - } - - /// - /// Generates a Fluent API call for the unicode configuration. - /// - /// The property. - /// The builder code is added to. - protected virtual void GenerateFluentApiForIsUnicode( - [NotNull] IProperty property, - [NotNull] IndentedStringBuilder stringBuilder) - { - if (property.IsUnicode() is bool unicode) - { - stringBuilder - .AppendLine() - .Append(".") - .Append(nameof(PropertyBuilder.IsUnicode)) - .Append("(") - .Append(Code.Literal(unicode)) - .Append(")"); - } - } - - /// - /// Generates a Fluent API call for the default value annotations. - /// - /// The property. - /// The builder code is added to. - protected virtual void GenerateFluentApiForDefaultValue( - [NotNull] IProperty property, - [NotNull] IndentedStringBuilder stringBuilder) - { - var defaultValue = property.GetDefaultValue(); - if (defaultValue == null) - { - return; - } - - stringBuilder - .AppendLine() - .Append(".") - .Append(nameof(RelationalPropertyBuilderExtensions.HasDefaultValue)) - .Append("("); - - if (defaultValue != DBNull.Value) - { - stringBuilder - .Append(Code.UnknownLiteral(FindValueConverter(property) is ValueConverter valueConverter - ? valueConverter.ConvertToProvider(defaultValue) - : defaultValue)); - } - - stringBuilder - .Append(")"); - } - /// /// Generates code for an annotation which does not have a fluent API call. /// @@ -1416,5 +1309,92 @@ protected virtual void GenerateData( stringBuilder .AppendLine(");"); } + + private void GenerateFluentApiForMaxLength( + [NotNull] IProperty property, + [NotNull] IndentedStringBuilder stringBuilder) + { + if (property.GetMaxLength() is int maxLength) + { + stringBuilder + .AppendLine() + .Append(".") + .Append(nameof(PropertyBuilder.HasMaxLength)) + .Append("(") + .Append(Code.Literal(maxLength)) + .Append(")"); + } + } + + private void GenerateFluentApiForPrecisionAndScale( + [NotNull] IProperty property, + [NotNull] IndentedStringBuilder stringBuilder) + { + if (property.GetPrecision() is int precision) + { + stringBuilder + .AppendLine() + .Append(".") + .Append(nameof(PropertyBuilder.HasPrecision)) + .Append("(") + .Append(Code.UnknownLiteral(precision)); + + if (property.GetScale() is int scale) + { + if (scale != 0) + { + stringBuilder + .Append(", ") + .Append(Code.UnknownLiteral(scale)); + } + } + + stringBuilder.Append(")"); + } + } + + private void GenerateFluentApiForIsUnicode( + [NotNull] IProperty property, + [NotNull] IndentedStringBuilder stringBuilder) + { + if (property.IsUnicode() is bool unicode) + { + stringBuilder + .AppendLine() + .Append(".") + .Append(nameof(PropertyBuilder.IsUnicode)) + .Append("(") + .Append(Code.Literal(unicode)) + .Append(")"); + } + } + + private void GenerateFluentApiForDefaultValue( + [NotNull] IProperty property, + [NotNull] IndentedStringBuilder stringBuilder) + { + var defaultValue = property.GetDefaultValue(); + if (defaultValue == null) + { + return; + } + + stringBuilder + .AppendLine() + .Append(".") + .Append(nameof(RelationalPropertyBuilderExtensions.HasDefaultValue)) + .Append("("); + + if (defaultValue != DBNull.Value) + { + stringBuilder + .Append(Code.UnknownLiteral(FindValueConverter(property) is ValueConverter valueConverter + ? valueConverter.ConvertToProvider(defaultValue) + : defaultValue)); + } + + stringBuilder + .Append(")"); + } } }