From 9b51266ec98bb631fe18489a4bfa8ed64be740e5 Mon Sep 17 00:00:00 2001 From: lindexi Date: Wed, 18 Sep 2024 19:19:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BB=93=E6=9E=84=E4=BD=93?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E6=AF=8F=E6=AC=A1=E8=8E=B7=E5=8F=96=E9=83=BD?= =?UTF-8?q?=E8=A2=AB=E5=A4=8D=E5=88=B6=E4=B8=80=E4=BB=BD=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=86=99=E5=85=A5=E6=97=A5=E5=BF=97=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LoggerInterpolatedStringHandler.g.cs | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/dotnetCampus.Logger/LoggerInterpolatedStringHandler.g.cs b/src/dotnetCampus.Logger/LoggerInterpolatedStringHandler.g.cs index 92b1dd5..d7bd06e 100644 --- a/src/dotnetCampus.Logger/LoggerInterpolatedStringHandler.g.cs +++ b/src/dotnetCampus.Logger/LoggerInterpolatedStringHandler.g.cs @@ -11,17 +11,37 @@ public LoggerInterpolatedStringHandler(int literalLength, int formattedCount) _handler = new DefaultInterpolatedStringHandler(literalLength, formattedCount); } - private readonly DefaultInterpolatedStringHandler _handler; + private DefaultInterpolatedStringHandler _handler; - public void AppendLiteral(string s) => _handler.AppendLiteral(s); + public void AppendLiteral(string s) + { + ref var handle = ref _handler; + handle.AppendLiteral(s); + } - public void AppendFormatted(T value) => _handler.AppendFormatted(value); + public void AppendFormatted(T value) + { + ref var handle = ref _handler; + handle.AppendFormatted(value); + } - public void AppendFormatted(T value, string format) => _handler.AppendFormatted(value, format); + public void AppendFormatted(T value, string format) + { + ref var handle = ref _handler; + handle.AppendFormatted(value, format); + } - public string ToStringAndClear() => _handler.ToStringAndClear(); + public string ToStringAndClear() + { + ref var handle = ref _handler; + return handle.ToStringAndClear(); + } - public override string ToString() => _handler.ToString(); + public override string ToString() + { + ref var handle = ref _handler; + return handle.ToString(); + } /// /// 废弃掉此字符串 @@ -30,7 +50,8 @@ public void Discard() { // 这里的 ToStringAndClear 其实只是取其 Clear 的功能 // 暂时先使用 DefaultInterpolatedStringHandler 提供的能力,后续再考虑是否需要优化 - _handler.ToStringAndClear(); + ref var handle = ref _handler; + handle.ToStringAndClear(); } }