Call Graph

cs_Didier78 Messages postés 1 Date d'inscription lundi 25 octobre 2004 Statut Membre Dernière intervention 25 octobre 2004 - 25 oct. 2004 à 14:56
TheSaib Messages postés 2367 Date d'inscription mardi 17 avril 2001 Statut Membre Dernière intervention 26 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?

Thanks,

Didier

1 réponse

TheSaib Messages postés 2367 Date d'inscription mardi 17 avril 2001 Statut Membre Dernière intervention 26 décembre 2007 23
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;
}

PS : Si tu es francais tu peux ecrire en francais

::|The S@ib|::
MVP C#.NET
0
Rejoignez-nous