Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi everyone!

My question is if there is any property or something else that returns from where the method was called.

For example:
void method2(..){..}
void method1(...)
{ method2(); }

I would like to know if method2(){} was called from method1(){} or from another method.

Thanks beforehead.
Posted
Comments
Richard MacCutchan 27-Sep-13 3:52am    
Idon't think there is any way to get that information, and a method should not need to know stand corrected (must learn more about reflection).

Carlo has provided the answer.
CPallini 27-Sep-13 4:08am    
You forgot they live in a managed world. :-)
Richard MacCutchan 27-Sep-13 4:36am    
You are right, as always. :)
CPallini 27-Sep-13 4:58am    
No, that's The Wife! :-)

1 solution

See, for instance, here: Get Calling Method using Reflection [C#][^].
 
Share this answer
 
Comments
Maciej Los 27-Sep-13 4:49am    
+5
CPallini 27-Sep-13 4:57am    
Thank you.
BillW33 27-Sep-13 15:55pm    
@Acusu: If this solution answered your question you should mark it as the solution and upvote it. :)
Maciej Los 28-Sep-13 17:02pm    
Who? Me?
I'm not a questioner.
BillW33 28-Sep-13 21:02pm    
Sorry, I meant to direct it to Acusu, I have fixed that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900