我非常喜歡簡化代碼以實現可擴展性。我試圖簡化這段代碼,但我一直在卡住。有誰知道我可以簡化這個代碼,因爲它包含了很多醜陋的,如果如果。過度併發症的原因是傳遞給方法的變量數量。這些都是必需的。C#:簡化代碼
感謝
private void SetVisibility(int AuctionID, int BidStatus, int LoginErrorCode, int IsHome, bool IsGetMoreTokens)
{
this._dealBidPlacedControl.Visible = false;
this._dealBidControl.Visible = false;
this._loginReg.Visible = false;
this._deals.Visible = false;
if (AuctionID > 0)
{
if (LoginErrorCode == 0)
{
if (BidStatus > 0)
{
this._dealBidPlacedControl.Visible = true;
}
else
{
this._dealBidControl.Visible = true;
}
}
else
{
this._loginReg.LoginErrorType = LoginErrorCode;
this._loginReg.Visible = true;
this._deals.Visible = true;
}
}
else
{
this._loginReg.Visible = true;
this._deals.Visible = true;
}
if (IsGetMoreTokens)
{
this._getMoreTokens.Visible = true;
this._loginReg.Visible = false;
this._deals.Visible = false;
}
// set the hidden field which can be used to set visibility if included in a tab control or anything
// by the parent site
if (this.AuctionID > 0 || BidStatus > 0 || IsHome > 0 || LoginErrorCode > 0 || IsGetMoreTokens)
this._visibilityStatus.Value = "1";
}
聽起來像你會對http://codereview.stackexchange.com/感興趣http://codereview.stackexchange.com/ – 2012-01-11 10:00:16