I'm going to pass the current class name as a parameter to some of the functions inside my codes.
I have many calls like this inside my code:
return Ok(new WebServiceResult(ErrorCodes.ERROR_CODE_MINUS_002_INVALID_REQUEST_DATE,
MethodBase.GetCurrentMethod().DeclaringType.Name));
The part MethodBase.GetCurrentMethod().DeclaringType.Name
is intended to return name of the current class.
How can I shorten this MethodBase.GetCurrentMethod().DeclaringType.Name
using C# syntaxes?
I was looking for a thing like macros in C/C++, something such as:
#define CLASSNAME MethodBase.GetCurrentMethod().DeclaringType.Name
but it seems Macros are not supported in C# and it is not a good practice in C# if I understood correctly. However, for making my code clearer and more readable I'm looking for something to replace this snippet and make it shorter.
P.S. I don't want to fetch name of calling class inside the called method itself but I'm looking for a way to shorten my code and make it more clear.