Skip to content

Commit

Permalink
Make ToDebugString methods public and DebugViews easily obtainable (#…
Browse files Browse the repository at this point in the history
…20681)

Part of #20409
  • Loading branch information
ajcvickers authored Apr 21, 2020
1 parent e6cf5e7 commit 786a989
Show file tree
Hide file tree
Showing 45 changed files with 1,408 additions and 1,182 deletions.
45 changes: 44 additions & 1 deletion src/EFCore.Relational/Extensions/RelationalModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
Expand All @@ -14,10 +16,51 @@
namespace Microsoft.EntityFrameworkCore
{
/// <summary>
/// Extension methods for <see cref="IModel" /> for relational database metadata.
/// Relational-specific extension methods for <see cref="IModel" /> and extension methods for <see cref="IRelationalModel"/>.
/// </summary>
public static class RelationalModelExtensions
{
/// <summary>
/// <para>
/// Creates a human-readable representation of the given metadata.
/// </para>
/// <para>
/// Warning: Do not rely on the format of the returned string.
/// It is designed for debugging only and may change arbitrarily between releases.
/// </para>
/// </summary>
/// <param name="model"> The metadata item. </param>
/// <param name="options"> Options for generating the string. </param>
/// <param name="indent"> The number of indent spaces to use before each new line. </param>
/// <returns> A human-readable representation. </returns>
public static string ToDebugString(
[NotNull] this IRelationalModel model,
MetadataDebugStringOptions options,
int indent = 0)
{
var builder = new StringBuilder();
var indentString = new string(' ', indent);

builder.Append(indentString).Append("DatabaseModel: ");

foreach (var table in model.Tables)
{
builder.AppendLine().Append(table.ToDebugString(options, indent + 2));
}

foreach (var view in model.Views)
{
builder.AppendLine().Append(view.ToDebugString(options, indent + 2));
}

if ((options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
{
builder.Append(model.AnnotationsToDebugString(indent));
}

return builder.ToString();
}

/// <summary>
/// Returns the default schema to use for the model, or <c>null</c> if none has been set.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,36 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <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.
/// Extension methods for <see cref="ICheckConstraint" />.
/// </summary>
public static class CheckConstraintExtensions
{
/// <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.
/// <para>
/// Creates a human-readable representation of the given metadata.
/// </para>
/// <para>
/// Warning: Do not rely on the format of the returned string.
/// It is designed for debugging only and may change arbitrarily between releases.
/// </para>
/// </summary>
/// <param name="constraint"> The metadata item. </param>
/// <param name="options"> Options for generating the string. </param>
/// <param name="indent"> The number of indent spaces to use before each new line. </param>
/// <returns> A human-readable representation. </returns>
public static string ToDebugString(
[NotNull] this ICheckConstraint constraint,
MetadataDebugStringOptions options,
[NotNull] string indent = "")
int indent = 0)
{
var builder = new StringBuilder();
var indentString = new string(' ', indent);

builder
.Append(indent)
.Append(indentString)
.Append("Check: ");

builder.Append(constraint.Name)
Expand All @@ -41,7 +46,7 @@ public static string ToDebugString(
{
if ((options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
{
builder.Append(constraint.AnnotationsToDebugString(indent: indent + " "));
builder.Append(constraint.AnnotationsToDebugString(indent: indent + 2));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,35 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <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.
/// Extension methods for <see cref="IColumn" />.
/// </summary>
public static class ColumnExtensions
{
/// <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.
/// <para>
/// Creates a human-readable representation of the given metadata.
/// </para>
/// <para>
/// Warning: Do not rely on the format of the returned string.
/// It is designed for debugging only and may change arbitrarily between releases.
/// </para>
/// </summary>
/// <param name="column"> The metadata item. </param>
/// <param name="options"> Options for generating the string. </param>
/// <param name="indent"> The number of indent spaces to use before each new line. </param>
/// <returns> A human-readable representation. </returns>
public static string ToDebugString(
[NotNull] this IColumn column,
MetadataDebugStringOptions options,
[NotNull] string indent = "")
int indent = 0)
{
var builder = new StringBuilder();
var indentString = new string(' ', indent);

builder.Append(indent);
builder.Append(indentString);

var singleLine = (options & MetadataDebugStringOptions.SingleLine) != 0;
if (singleLine)
Expand All @@ -54,7 +59,7 @@ public static string ToDebugString(
if (!singleLine &&
(options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
{
builder.Append(column.AnnotationsToDebugString(indent + " "));
builder.Append(column.AnnotationsToDebugString(indent + 2));
}

return builder.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,35 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <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.
/// Extension methods for <see cref="IColumnMapping" />.
/// </summary>
public static class ColumnMappingExtensions
{
/// <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.
/// <para>
/// Creates a human-readable representation of the given metadata.
/// </para>
/// <para>
/// Warning: Do not rely on the format of the returned string.
/// It is designed for debugging only and may change arbitrarily between releases.
/// </para>
/// </summary>
/// <param name="columnMapping"> The metadata item. </param>
/// <param name="options"> Options for generating the string. </param>
/// <param name="indent"> The number of indent spaces to use before each new line. </param>
/// <returns> A human-readable representation. </returns>
public static string ToDebugString(
[NotNull] this IColumnMapping columnMapping,
MetadataDebugStringOptions options,
[NotNull] string indent = "")
int indent = 0)
{
var builder = new StringBuilder();
var indentString = new string(' ', indent);

builder.Append(indent);
builder.Append(indentString);

var singleLine = (options & MetadataDebugStringOptions.SingleLine) != 0;
if (singleLine)
Expand All @@ -50,7 +55,7 @@ public static string ToDebugString(
if (!singleLine &&
(options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
{
builder.Append(columnMapping.AnnotationsToDebugString(indent + " "));
builder.Append(columnMapping.AnnotationsToDebugString(indent + 2));
}

return builder.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,36 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <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.
/// Extension methods for <see cref="IDbFunction" />.
/// </summary>
public static class DbFunctionExtensions
{
/// <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.
/// <para>
/// Creates a human-readable representation of the given metadata.
/// </para>
/// <para>
/// Warning: Do not rely on the format of the returned string.
/// It is designed for debugging only and may change arbitrarily between releases.
/// </para>
/// </summary>
/// <param name="function"> The metadata item. </param>
/// <param name="options"> Options for generating the string. </param>
/// <param name="indent"> The number of indent spaces to use before each new line. </param>
/// <returns> A human-readable representation. </returns>
public static string ToDebugString(
[NotNull] this IDbFunction function,
MetadataDebugStringOptions options,
[NotNull] string indent = "")
int indent = 0)
{
var builder = new StringBuilder();
var indentString = new string(' ', indent);

builder
.Append(indent)
.Append(indentString)
.Append("DbFunction: ");

builder.Append(function.ReturnType.ShortDisplayName())
Expand All @@ -50,16 +55,16 @@ public static string ToDebugString(
var parameters = function.Parameters.ToList();
if (parameters.Count != 0)
{
builder.AppendLine().Append(indent).Append(" Parameters: ");
builder.AppendLine().Append(indentString).Append(" Parameters: ");
foreach (var parameter in parameters)
{
builder.AppendLine().Append(parameter.ToDebugString(options, indent + " "));
builder.AppendLine().Append(parameter.ToDebugString(options, indent + 4));
}
}

if ((options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
{
builder.Append(function.AnnotationsToDebugString(indent: indent + " "));
builder.Append(function.AnnotationsToDebugString(indent: indent + 2));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,36 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Metadata.Internal
namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <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.
/// Extension methods for <see cref="IDbFunctionParameter" />.
/// </summary>
public static class DbFunctionParameterExtensions
{
/// <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.
/// <para>
/// Creates a human-readable representation of the given metadata.
/// </para>
/// <para>
/// Warning: Do not rely on the format of the returned string.
/// It is designed for debugging only and may change arbitrarily between releases.
/// </para>
/// </summary>
/// <param name="parameter"> The metadata item. </param>
/// <param name="options"> Options for generating the string. </param>
/// <param name="indent"> The number of indent spaces to use before each new line. </param>
/// <returns> A human-readable representation. </returns>
public static string ToDebugString(
[NotNull] this IDbFunctionParameter parameter,
MetadataDebugStringOptions options,
[NotNull] string indent = "")
int indent = 0)
{
var builder = new StringBuilder();
var indentString = new string(' ', indent);

builder
.Append(indent)
.Append(indentString)
.Append("DbFunctionParameter: ");

builder.Append(parameter.Name)
Expand All @@ -40,7 +45,7 @@ public static string ToDebugString(
{
if ((options & MetadataDebugStringOptions.IncludeAnnotations) != 0)
{
builder.Append(parameter.AnnotationsToDebugString(indent: indent + " "));
builder.Append(parameter.AnnotationsToDebugString(indent + 2));
}
}

Expand Down
Loading

0 comments on commit 786a989

Please sign in to comment.