diff --git a/src/dotnetCampus.Logger/LoggerInterpolatedStringHandler.g.cs b/src/dotnetCampus.Logger/LoggerInterpolatedStringHandler.g.cs index 92b1dd5..125cce5 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 handler = ref _handler; + handler.AppendLiteral(s); + } - public void AppendFormatted(T value) => _handler.AppendFormatted(value); + public void AppendFormatted(T value) + { + ref var handler = ref _handler; + handler.AppendFormatted(value); + } - public void AppendFormatted(T value, string format) => _handler.AppendFormatted(value, format); + public void AppendFormatted(T value, string format) + { + ref var handler = ref _handler; + handler.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 handler = ref _handler; + return handler.ToString(); + } /// /// 废弃掉此字符串 @@ -30,7 +50,8 @@ public void Discard() { // 这里的 ToStringAndClear 其实只是取其 Clear 的功能 // 暂时先使用 DefaultInterpolatedStringHandler 提供的能力,后续再考虑是否需要优化 - _handler.ToStringAndClear(); + ref var handler = ref _handler; + handler.ToStringAndClear(); } }