Replies: 1 comment
-
No. We suggest declaring multiple methods in a scenario like this. If we introduced an attribute like this, the compiler would still only have a limited ability to track what possible values does a boolean expression have, and we would need to do significant work to improve that beyond simple scenarios like public DataRow? ExecuteToDataRow(SqlCommand command) {
DataTable dataTable = ExecuteToDataTable(command);
DataRowCollection rows = dataTable.Rows;
switch (rows.Count) {
case 1:
return rows[0];
case < 1:
return null;
}
throw new ArgumentException($"The command returned multiple rows!");
}
public DataRow ExecuteToRequiredDataRow(SqlCommand command) {
return ExecuteToDataRow(command) ?? throw new ArgumentException($"The command did not return any rows!");
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In C#, is it possible to express that a result may be null/may not be null depending on a Boolean parameter, something like the following (not compiling) code?
Beta Was this translation helpful? Give feedback.
All reactions