mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-07 16:36:52 +02:00
* [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>
66 lines
1.1 KiB
C#
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();
|
|
}
|
|
}
|