[API Proposal]: InterpolatedStringHandler allow method overload that has the "name" of the interpolated values. #7537
-
Background and motivationIn some casese it may be of relevance to know from where the value was recived. E.g.: A structual logger may want to know the variable to use when logging. API Proposalpublic void AppendFormatted<T> (T value, int alignment, string? format, string name); name will contain the text wiritten in source code. API Usagesubject = "Mail";
logger.LogInformation($"Create entity {subject}"); will call Alternative Designspublic void AppendFormatted<T> (T value, int alignment, string? format, System.Linq.Expression name); An alternateive, or additon could be to use Expressions to get more information. RisksBesides an increased complexexty I currently see no risk. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can use CallerArgumentExpressionAttribute to achieve this with a custom interpolated string handler: public void AppendFormatted<T> (
T value,
int alignment,
string? format,
[CallerArgumentExpression("value")] string? name = null) { ... } |
Beta Was this translation helpful? Give feedback.
You can use CallerArgumentExpressionAttribute to achieve this with a custom interpolated string handler: