Proposal: Add CallerType to Caller Information attributes #8032
Unanswered
timothyBoye
asked this question in
Language Ideas
Replies: 1 comment 1 reply
-
Information about compiled result (Type) is more complex than information about source code (filename, line). A method can belong to compiler synthesized type like closure of lambda. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
Caller Information attributes include CallerFilePath, CallerLineNumber, CallerMethodName, and CallerArgumentExpression. It is requested that CallerType representing the value typeof(Caller) be added to the caller information attributes.
Previous discussions have occurred at #87 and LDM. These appear to have been overly ambitious, however the core proposal warrants further consideration.
Details and Motivation
Caller information attributes are used for debugging, logging, and various other tasks. While the current set of properties is very useful for these, it is not possible to reliably infer the type of the caller from the current set.
As an example, it would be beneficial to be able to log not just the name of a caller but the type where subclassing is involved. This would make it clear which sub class the logging is related to where the inherited property or method would always have the same CallerMethodName e.g.,
Doing some googling on ‘csharp custom attributes type’ and similar queries it is clear there is a sizeable contingent of developers looking for ways to get the type of the caller in custom attributes (myself included). Typically it appears this is related to switching on type for custom logic, both as in the inheritance example above as well as in more generic cases e.g.
Based on previous discussions including the LDM notes, it appears the main concern is bloating of the Caller Information as previous proposals have taken a laundry list approach hoping something will stick. Most previously requested Caller Information can however be achieved through Type alone, limiting the expansion of the Caller Information to one additional attribute (e.g., type name, full type name etc).
There was some suggestion that providing the caller object itself would provide all the information one could need including a way to get the type easily and thus would be the superior all encompassing Caller information. However, this comes with a lot of baggage and would likely lead to the same concerns listed in the LDM notes. While I can see many ways this could be useful, I suggest that Type covers the vast majority of requests discussed while in comparison significantly limiting potential concerns and therefore is a reasonable middle ground.
Beta Was this translation helpful? Give feedback.
All reactions