c# - passing StackFrame Stack trace from derived class -
i have base class accepts stackframe parameter.
public excpm(string msg, stackframe parcallstack = null, bool show = true) { stackframe lcallstack; if (parcallstack == null) lcallstack= new stackframe(1, true); else lcallstack= parcallstack; //do stuff info in lcallstack .. } originally have started without said parameter, have added because when using common extension method or method calls above constructor, without added parameter callstack.getmethod() give extension method data rather intended caller 1 after.
now called solution, there comes new problem stuck without proper solution for, starts me thinking using incorrectly.
the problem when created derived class above excpm main class gives wrong guy data (the derived own ctor..)
derived (added false return value boolean methods usage)
public class excpflsv:excpm { bool rtrn { { return false; } } public excpflsv(string bsmsg, stackframe bscallstack = null) : base(bsmsg, bscallstack) { } } usage
public bool somemethodreturnsbool() { //unless adding local callstack field every method passes ctor of excpflsv calling method stackframe lcallstack = new system.diagnostics.stackframe(1, true); if(some condition no met) return new excpflsv("some error message...", lcallstack).rtrn; } what proper way pass caller method data ?
public bool secondlevel(string caller, int callerlvl = 2) { return teststacktrace(" called secondlevel " + caller, callerlvl); } public bool teststacktracefirstlvl(string caller, int callerlvl = 1) { new excpm("teststacktrace " + caller, callerlvl); return false; } public excpm(string msg,int callerlevel=1, bool show = true) { stackframe callstack = new stackframe(callerlevel, true); this.lnnum = callstack.getfilelinenumber(); this.fl = callstack.getfilename(); this.mthod = callstack.getmethod().name; this.lmsg = msg; } or derived (false version) , skipping stack frame
public class excpflsv:excpm { bool rtrn { { return false; } } public excpflsv(string bsmsg, int callerlevel=2) : base(bsmsg, callerlevel) { } } public bool secondlevel(string caller, int callerlvl = 3) { return teststacktrace(" called secondlevel " + caller, callerlvl); } public bool teststacktracefirstlvl(string caller, int callerlvl = 2) { return new excflsblv("teststacktrace " + caller, callvl).rtrn; }
Comments
Post a Comment