Optimize conditional operators branching in C#
- by abatishchev
Hello. I have next code:
return this.AllowChooseAny.Value ?
radioSpecific.Checked ?
UserManager.CurrentUser.IsClient ? txtSubject.Text : subjectDropDownList.SelectedItem.Text :
String.Empty :
UserManager.CurrentUser.IsClient ? txtSubject.Text : subjectDropDownList.SelectedItem.Text;
or in less complex form:
return any ?
specified ?
isClient ? textbox : dropdown :
empty :
isClient ? textbox : dropdown;
or in schematic form:
|
any
/ \
specified isClient
/ \ / \
isClient empty textbox dropdown
/ \
textbox dropdown
Evidently I have a duplicated block on two different levels. Is it possible to optimize this code to probably split them to one? Or something like that..