'How to find the class from which the method was called in C#

I have a class MainClass with method MainMethod. I created more classes which iherit from this class. I would like to add a line to MainMethod which will print the name of class of object from which this method was called. Is it possible?



Solution 1:[1]

Have you investigated CallerMemberNameAttribute and the other goodies discussed here: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/attributes/caller-information

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Edmund Schweppe