下面的方法怎么改写,使得更加简洁容易理解

caicoko caicoko 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
下面是web控件的部分重写代码,有些乱,用了很多if语句,如何改写使得代码更加简洁,更加容易理解。


protected override void OnPreRender(EventArgs e)
{
if (this._controlType == "DateTime" && (BB.Get("action") == "insert" || BB.Get("action") == "copy"))
{
this.Text = DateTime.Now.ToString();
}
if (this._controlType == "UpdateDate" && BB.Get("action") == "update")
{
this.Text = DateTime.Now.ToString();
}
if (this._controlType == "InputUser" && BB.Get("action") == "insert")
{
this.Text = BB.LoginKey("Name") != null ? BB.LoginKey("Name") : String.Empty;
}
if (this._controlType == "InputUserName" && BB.Get("action") == "insert")
{
this.Text = BB.LoginKey("Name") != null ? BB.LoginKey("Name") : String.Empty;
}
if (this._controlType == "InputUserID" && (BB.Get("action") == "insert" || BB.Get("action") == "copy"))
{
this.Text = BB.LoginKey("UserID") != null ? BB.LoginKey("UserID") : String.Empty;
}
if (this._controlType == "Password")
{
this.TextMode = TextBoxMode.Password;
}
if (this._controlType == "MultiLine")
{
this.TextMode = TextBoxMode.MultiLine;
}
base.OnPreRender(e);
}
...全文
评论 13
收藏 已收藏
分享
返回顶部
caicoko
.NET社区 62,272 成员 668,968 内容