Skip to content

Instantly share code, notes, and snippets.

@jeppevammenkristensen
Created July 3, 2023 08:39
Show Gist options
  • Save jeppevammenkristensen/f526db13a1859a58c4eb4777ce3da9fe to your computer and use it in GitHub Desktop.
Save jeppevammenkristensen/f526db13a1859a58c4eb4777ce3da9fe to your computer and use it in GitHub Desktop.
[InterpolatedStringHandler]
public ref struct LogInterpolatedStringHandler
{
private int index = 0;
public readonly StringBuilder _builder = new StringBuilder();
public readonly (string name,object)[] Parameters;
public LogInterpolatedStringHandler(int literalLength, int formattedCount)
{
Parameters = new (string, object)[formattedCount];
}
public void AppendLiteral(string s)
{
_builder.Append(s);
}
public void AppendFormatted<T>(T t, [CallerArgumentExpression(nameof(t))] string name = null!)
{
_builder.Append($"{{{name}}}");
Parameters[index] = (name,t);
index++;
}
// public void AppendFormatted<T>(T t, string format, [CallerArgumentExpression(nameof(t))] string name = null!)
// {
// Console.WriteLine($"\tAppendFormatted called: {{{t}}} is of type {typeof(T)} name is {name}");
//
// int i = 0;
// Console.WriteLine($"\tAppended the formatted object");
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment