G
Guest
Hi i want to obtain a reference to the object which invoked the class
constructor. I'm doing the following in the class constructor:
public Constructor()
{
StackTrace st = new StackTrace();
bool firstMethodOutsideOfCtor = false;
for (int i = 0; i < st.FrameCount && !firstMethodOutsideOfCtor;
i++)
{
StackFrame frame = st.GetFrame(i);
MethodBase mBase = frame.GetMethod();
if ((firstMethodOutsideOfCtor = !mBase.IsConstructor))
{
Type handle = mBase.DeclaringType;
}
}
So as you see, i can get the type of the invoking class, but i need a
reference. Is there a solution to this problem?
constructor. I'm doing the following in the class constructor:
public Constructor()
{
StackTrace st = new StackTrace();
bool firstMethodOutsideOfCtor = false;
for (int i = 0; i < st.FrameCount && !firstMethodOutsideOfCtor;
i++)
{
StackFrame frame = st.GetFrame(i);
MethodBase mBase = frame.GetMethod();
if ((firstMethodOutsideOfCtor = !mBase.IsConstructor))
{
Type handle = mBase.DeclaringType;
}
}
So as you see, i can get the type of the invoking class, but i need a
reference. Is there a solution to this problem?