New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for FormattableString #24
Comments
The problem about We could perhaps support it without allocating by rewriting the code with a Fody addin (this would rewrite the |
@ltrzesniewski ah, thanks for the comment. So in essence, the compiler is re-writing the code to allocate the FormattableString object at the call site? |
Yes, it allocates the See here: public void M()
{
Log($"Hello {42}, world! {true}");
}
public static void Log(FormattableString value)
{
} Gets compiled to: public void M()
{
object[] obj = new object[2];
obj[0] = 42;
obj[1] = true;
Log(FormattableStringFactory.Create("Hello {0}, world! {1}", obj));
}
public static void Log(FormattableString value)
{
} |
OK, I should have realized it would probably be awful... |
Ok, it's maybe a tiny bit late, but interpolated string support is now available in v2, and does not allocate thanks to interpolated string handlers in C# 10. 🙂 |
I think it would be a nice addition to the arsenal of ZeroLog to support the somewhat unknown c# interpolated string feature called
ForamttableString
.This would basically allow users to call ZeroLog with interpolated strings:
The theory behind this is that ZeroLog would get a FormattableString instance fed into the
*Interpolated
variants of the logging functions that would have to be added to ZeroLog and to the StringFormatter project.The reason behind adding yet another overload for this purpose is that apprently the c# compiler has a feature/issue where having two functions that only differ by having a string/FormattableString parameter leads to the string variant being always selected by the compiler:
dotnet/roslyn#46
http://blog.engdahls.dk/2016/08/how-to-overload-string-and.html
Any thoughts about this?
The text was updated successfully, but these errors were encountered: