Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ indent_size = 2
end_of_line = crlf
indent_size = 2

# Scaffolding templates and their pre-processed output: line breaks here end up in scaffolded code, which is always LF
[src/EFCore.Design/Scaffolding/Internal/CSharp{DbContext,EntityType}Generator.{tt,cs}]
end_of_line = lf

## Language conventions
# Dotnet code style settings:
[*.{cs,vb}]
Expand Down
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@
*.sln eol=crlf
*.sql diff

# The scaffolding templates and their pre-processed output must use LF so that scaffolded code always has LF line endings
# (line breaks inside the templates become string literals in the generated code).
src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.tt eol=lf
src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs eol=lf
src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.tt eol=lf
src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs eol=lf

.github/workflows/*.lock.yml linguist-generated=true
55 changes: 31 additions & 24 deletions src/EFCore.Design/Design/Internal/CSharpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace Microsoft.EntityFrameworkCore.Design.Internal;
/// </summary>
public class CSharpHelper : ICSharpHelper
{
private const int IndentSize = 4;

private readonly ITypeMappingSource _typeMappingSource;
private readonly Project _project;
private readonly RuntimeModelLinqToCSharpSyntaxTranslator _translator;
Expand All @@ -46,6 +48,17 @@ public CSharpHelper(ITypeMappingSource typeMappingSource)
_translator = new RuntimeModelLinqToCSharpSyntaxTranslator(syntaxGenerator);
}

/// <summary>
/// The line terminator used by <see cref="Fragment(IMethodCallCodeFragment?, int)" />,
/// <see cref="Fragment(NestedClosureCodeFragment, int)" /> and <see cref="XmlComment" />.
/// Defaults to <see cref="Environment.NewLine" />.
/// </summary>
/// <remarks>
/// This does not affect the vertical collection literals, which are built with <see cref="IndentedStringBuilder" />.
/// </remarks>
protected virtual string NewLine
=> Environment.NewLine;

private static readonly IReadOnlyCollection<string> Keywords =
[
"__arglist",
Expand Down Expand Up @@ -1368,23 +1381,20 @@ public virtual string Fragment(IMethodCallCodeFragment? fragment, int indent = 0
return string.Empty;
}

var builder = new IndentedStringBuilder();
var builder = new StringBuilder();

if (fragment.ChainedCall is null)
{
AppendMethodCall(fragment);
}
else
{
for (var i = 0; i < indent; i++)
{
builder.IncrementIndent();
}
var indentString = new string(' ', indent * IndentSize);

var current = fragment;
do
{
builder.AppendLine();
builder.Append(NewLine).Append(indentString);
AppendMethodCall(current);

current = current.ChainedCall;
Expand Down Expand Up @@ -1450,26 +1460,23 @@ public virtual string Fragment(NestedClosureCodeFragment fragment, int indent =
return fragment.Parameter + " => " + fragment.Parameter + Fragment(fragment.MethodCalls[0], indent);
}

var builder = new IndentedStringBuilder();
builder.AppendLine(fragment.Parameter + " =>");
for (var i = 0; i < indent - 1; i++)
{
builder.IncrementIndent();
}
var outerIndent = new string(' ', Math.Max(indent - 1, 0) * IndentSize);
var innerIndent = outerIndent + new string(' ', IndentSize);

builder.AppendLine("{");
using (builder.Indent())
var builder = new StringBuilder();
builder.Append(fragment.Parameter).Append(" =>").Append(NewLine);
builder.Append(outerIndent).Append('{').Append(NewLine);
foreach (var methodCall in fragment.MethodCalls)
{
foreach (var methodCall in fragment.MethodCalls)
{
builder
.Append(fragment.Parameter)
.Append(Fragment(methodCall, indent + 1));
builder.AppendLine(";");
}
builder
.Append(innerIndent)
.Append(fragment.Parameter)
.Append(Fragment(methodCall, indent + 1))
.Append(';')
.Append(NewLine);
}

builder.Append("}");
builder.Append(outerIndent).Append('}');

return builder.ToString();
}
Expand Down Expand Up @@ -1564,8 +1571,8 @@ public virtual string XmlComment(string comment, int indent = 0)
if (!first)
{
builder
.AppendLine()
.Append(' ', indent * 4)
.Append(NewLine)
.Append(' ', indent * IndentSize)
.Append("/// ");
}
else
Expand Down
Loading
Loading