danikf/tik4net

ExecuteScalarOrDefault Throws Exceptions

Deantwo opened this issue · 4 comments

I think you might have misunderstood the normal behavior of "OrDefault" methods in C#.

Normally a "OrDefult" method returns null when the non-"OrDefault" version of the method would through an exception. Well it would throw the default(T) of whatever the return type is, which for a string is null.

I am not completely sure what your version of "OrDefault" methods are supposed to do.

public string ExecuteScalarOrDefault()

public string ExecuteScalarOrDefault(string defaultValue)

public string ExecuteScalarOrDefault(string defaultValue, string target)

I will confess that I had you implement these "OrDefault" methods, but I hadn't had the chance to test them myself before recently.

Hi Deantwo,

could you please close this issue or explain the problem. I agree with your description, but I believe that the behavior is as described :-)

Thx,
D

Main issue is, as the title says, the methods throw an exception.

throw new TikCommandUnexpectedResponseException("Single !done response or exactly one !re sentences expected. (1x!done or 1x!re + 1x!done )", this, response.Cast<ITikSentence>());

And also that the string defaultValue parameter seems pointless and a little confusing. It would be simpler to just always return null if the command resulted in more than one or no values. Like a normal SingleOrDefault method.

I think I might have misunderstood something here when I made this bug report. So I am just gonna close this.
But I have found an issue though, I will make a new bug report for that.