好的,吸引我注意的是: public override bool AdjustAccountBalance
。
我建议这public override
意味着这段代码可以从任何地方调用。
在这种情况下,我通常遵循肮脏但可靠的方法:
- 添加属性设置器和方法的所有调用(带有时间戳和堆栈跟踪)的日志记录(到本地文件
C:\log.txt
,我警告这是肮脏的方式:)); Global.AccountBalance
AdjustAccountBalance
- 重现问题;
- 挖掘日志并调查对上述方法的所有调用;找到“aha-there-it-is”-代码;
- ???
- 利润
因此,您的代码将类似于:
Helper 类:
internal static class LogHelper
{
public void LogCall(string method, string details, StackFrame[] stackTrace)
{
var sb = new StringBuilder();
sb.Append(DateTie.Now.ToShortTimeString() + ": " method + "{" + details + "}");
foreach (StackFrame stackFrame in stackTrace)
{
sb.AppendLine(stackFrame.GetMethod().Name);
}
File.AppendText("C:\\log.txt", sb.ToString());
}
}
AdjustAccountBalance 方法(修改片段):
public override bool AdjustAccountBalance(Account acct, decimal amount, string transType)
{
.. lots of your code posted in question..
case "D":
LogHelper.LogCall("AdjustAccountBalance","D-case",new StackTrace().GetFrames())
acct.AccountBalace += amount;
Global.AccountBalance = acct.AccountBalace;
break;
case "W":
if (acct.AccountBalace >= amount)
{
LogHelper.LogCall("AdjustAccountBalance","W-case",new StackTrace().GetFrames())
acct.AccountBalace -= amount;
Global.AccountBalance = acct.AccountBalace;
}
break;
.. lots of your code posted in question..
}
AccountBalance
类属性Global
:
public static decimal AccountBalance
{
get { return _AccountBalance; }
set {
LogHelper.LogCall("set_AccountBalance","value is " + value,new StackTrace().GetFrames())
_AccountBalance = value;
}
}
希望这可以帮助 ...