我非常喜欢简化代码以实现可扩展性。我试图简化这段代码,但我一直在卡住。有谁知道我可以简化这个代码,因为它包含了很多丑陋的,如果如果。过度并发症的原因是传递给方法的变量数量。这些都是必需的。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