我有以下代码根据用户在 Web 表单中选择的内容设置某些对象(CarsCourse)值。
该代码有效,但我的一位同事表示这是最糟糕的做法。但是,他无法提出任何建议。
那么有没有更好的方法来实现这一点?
谢谢
If Not String.IsNullOrEmpty(tbDisplayName.Text) Then CarsCourse.DisplayName = tbDisplayName.Text
If Not String.IsNullOrEmpty(tbDescription.Text) Then CarsCourse.Description = tbDescription.Text
If Not String.IsNullOrEmpty(tbOfficialStartDate.Text) Then CarsCourse.OfficialStartDate = DateTime.Parse(tbOfficialStartDate.Text)
If Not String.IsNullOrEmpty(tbOfficialEndDate.Text) Then CarsCourse.OfficialEndDate = DateTime.Parse(tbOfficialEndDate.Text)
If Not String.IsNullOrEmpty(tbBtmDatepicker1.Text) Then CarsCourse.VisibleStartDate = DateTime.Parse(tbBtmDatepicker1.Text)
If Not String.IsNullOrEmpty(tbBtmDatepicker2.Text) Then CarsCourse.VisibleEndDate = DateTime.Parse(tbBtmDatepicker2.Text)
If Not String.IsNullOrEmpty(ddlDepartment.SelectedValue) Then CarsCourse.SecondarySpecialtyName = ddlDepartment.SelectedValue
If Not String.IsNullOrEmpty(ddlOptionType.SelectedValue) Then CarsCourse.OptionType = ddlOptionType.SelectedValue
If Not String.IsNullOrEmpty(ddlOfficialName.SelectedValue) Then CarsCourse.OfficialCourseID = Guid.Parse((ddlOfficialName.SelectedValue))