[API Proposal]: Add CallerType attribute to tell the method the current type that is invoking the current member. #102725
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Runtime
Background and motivation
As the title says, the introduction of the attribute
CallerTypeAttribute
which will provide the method with the the type that is invoking the current member, as well asCallerMemberNameName
.I had this problem while writing a micro logger to handle tasks with more logging details. And when I realized that I was either creating a gigantic work-around or creating scoped loggers that store the methodbase instance or method name + type name.
And as .NET does not support expansive macros syntax like C++, it is not possible to simply write a macro that calls all the necessary functions by passing
MethodBase.GetCurrentMethod()
in each of them. (it would be something like#define INVOKE_LOG(LogInst, Msg) LogInst.WriteLine(Msg, MethodBase.GetCurrentMethod())
)API Proposal
API Usage
The value of
currentType
will be filled withtypeof(MyType)
(ortypeof(Utilities)
in API usage example).Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: