How can I check which class has called my method?
For example: If Class A uses the MethodB in the Class C than, the function should do something else than the function would do, if Class B calls the MethodB.
I can't add a boolean or something like that to the method.
There's no good way of doing this - and it's fundamentally a bad design, IMO. If ClassA and ClassB want different things to happen, they should call different methods.
The only time this is reasonable in my experience is when trying to work out a simple way of initializing loggers, where basically you want the calling class name to be part of the logger name. One horrible way of doing that is to throw and catch an exception, then look at its stack trace. But avoid if possible...
See more on this question at Stackoverflow