Files
RobustToolbox/Robust.Roslyn.Shared/IndentWriter.cs
T
b4eb85ad3c [Dependency] source generator (#6549)
* [Dependency] source generator

No more reflection, no more codegen at runtime

Also various changes to Roslyn helpers to make this easier to write.

Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback.

No fallback is available for [field: Dependency] properties, due to a Roslyn bug.

Code Fixes exist. We love Roslyn

* Release notes

* Handle nullable dependencies

These are bad but gotta deal with it.

* Apply suggestions from code review

Co-authored-by: Moony <moony@hellomouse.net>

* Fine, let's not use collection expressions

---------

Co-authored-by: Moony <moony@hellomouse.net>
2026-05-08 12:38:02 +02:00

66 lines
1.1 KiB
C#

using System.Text;
namespace Robust.Roslyn.Shared;
public struct IndentWriter(StringBuilder builder, int depth = 0)
{
public readonly StringBuilder Builder = builder;
public int Depth = depth;
public readonly void AppendLine()
{
Builder.AppendLine();
}
public readonly void AppendLine(string str)
{
Builder.AppendLine(str);
}
public void AppendLineIndented(string str)
{
AppendIndents();
Builder.AppendLine(str);
}
public void AppendOpeningBrace()
{
AppendLineIndented("{");
PushDepth();
}
public void AppendClosingBrace()
{
PopDepth();
AppendLineIndented("}");
}
public readonly void AppendIndents()
{
Builder.Append(' ', 4 * Depth);
}
public readonly void Append(string str)
{
Builder.Append(str);
}
public void PushDepth()
{
Depth += 1;
}
public void PopDepth()
{
if (Depth == 0)
return;
Depth -= 1;
}
public override string ToString()
{
return Builder.ToString();
}
}