|
-
Feb 4th, 2003, 10:30 AM
#1
Thread Starter
Lively Member
Reference to caller object
Is it possible to get a reference to the object that is calling a function inside that function? (Without passing it has a parameter)
Example:
Code:
Interface I
{
void CallerMethod();
void CalledBackMethod();
}
public class A : I
{
public void CallerMethod()
{
B b = new B();
b.CalledMethod();
}
public void CalledBackMethod()
{
//Do something
}
}
public class B
{
public void CalledMethod()
{
I i = GetCallingObject(); //This is what I want!!
i.CalledBackMethod()
}
}
Or is there other ways of doing this?
Thanks!
-
Feb 4th, 2003, 09:38 PM
#2
PowerPoster
I don't think you can. For a example, look at all the build in methods that handle events, the signatures all have a sender object passed in as an argument. It would seem to me that MS would avoided it if they could do it another way... But I have no proof one way or the other.
-
Feb 5th, 2003, 05:57 AM
#3
Thread Starter
Lively Member
Thanks hellswraith. I had myself noticed that adopted behaviour by Microsoft. It seems, like you say, I have to do the same...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|