cs_Didier78
Messages postés1Date d'inscriptionlundi 25 octobre 2004StatutMembreDernière intervention25 octobre 2004
-
25 oct. 2004 à 14:56
TheSaib
Messages postés2367Date d'inscriptionmardi 17 avril 2001StatutMembreDernière intervention26 décembre 2007
-
26 oct. 2004 à 01:45
Hello,
I'm implementing an exception management application block in C# and I'm facing a problem. I would like to get a reference to the caller object of another object method I'm currently in, if it is possible. Let me precise that I don't want this reference to be a parameter of my method. Could anyone help me?
TheSaib
Messages postés2367Date d'inscriptionmardi 17 avril 2001StatutMembreDernière intervention26 décembre 200723 26 oct. 2004 à 01:45
Impossible, without use parameters. Maybe you could find "this object" reference in stack but i don't know how to do and if is possible. Maybe using Debugger API ... Not a good solution to my mind.
you could also use a proxy class or a static var in your class.
Her an C++.NET sample found on MS newsgroup :
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
public __value class Reference {
public:
static Object* ref;
};
public __gc class Callee
{
public:
Callee(){}
void Call() {
Object* refToParent = Reference::ref;
Console::WriteLine(refToParent->ToString());
}
};
public __gc class Caller
{
public:
Caller(){}
void DoCall() {
Reference::ref = this;
Callee* callee = new Callee();
callee->Call();
}
};
int _tmain()
{
Caller* caller = new Caller();
caller->DoCall();
return 0;
}