Given several nullable boolean flags;
bool? l_flg_01 = true;
bool? l_flg_02 = false;
bool? l_flg_03 = true;
bool? l_result_flg = null;
I would have liked one of these syntax formats to work;
// if ( l_flg_01 && l_flg_02 && l_flg_03 ) // Line A
// if ( l_flg_01 & l_flg_02 & l_flg_03 ) // Line B
// if ( l_flg_01 &&? l_flg_02 &&? l_flg_03 ) // Line C
// if ( l_flg_01 &? l_flg_02 &? l_flg_03 ) // Line D
// if ( l_flg_01 AND l_flg_02 AND l_flg_03 ) // Line E
But I have to settle for casting (which looks messy) as below;
if ( (bool) l_flg_01 && (bool) l_flg_02 && (bool) l_flg_03 )
{
l_result_flg = true;
}
else
{
l_result_flg = false;
}
I thought 'lifted operators' would have worked for Line A or B.
My desired result, logically, is a null in any flag produces a false result.
My desired result, aesthetically, is a clean code line with no casting
baggage.
Do I have to write a custom operator for C# 2.0 nullable booleans,
(to get clean looking code) or am I missing something?
Thanks : shawnk
PS. I'm not worked about the logic, I would like to know about the aesthetics.