Created
July 3, 2023 08:39
-
-
Save jeppevammenkristensen/f526db13a1859a58c4eb4777ce3da9fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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