danikf / tik4net

Manage mikrotik routers with .NET C# code via ADO.NET like API or enjoy O/R mapper like highlevel api.
Apache License 2.0
177 stars 94 forks source link

[Suggestion] ExecuteSingleRowOrDefault #58

Closed Deantwo closed 5 years ago

Deantwo commented 5 years ago

We currently have cmd.ExecuteSingleRow() which is very useful. At least if you are expecting there to be a result, or don't mind adding a try-catch just to be sure there isn't no results.

I suggest a simple cmd.ExecuteSingleRowOrDefault(). Simply return null if no results were found.

Deantwo commented 5 years ago

Made a simple extension method in my project:

internal static ITikSentence ExecuteSingleRowOrDefault(this ITikCommand command)
{
    IEnumerable<ITikSentence> sentences = command.ExecuteList();
    return sentences.SingleOrDefault();
}

Seem like it it would be a no brainer to implement in the tik4net. But can likely be written better than this.

Deantwo commented 5 years ago

On the topic of cmd.ExecuteSingleRow(), it would be nice if the error message from it was made a little simpler.

tik4net.TikConnectionException: 'Command expected 2 sentences as response, but got 1 response sentences.'

The average user won't know that !done is part of those, so saying it expected 2 sentences is confusing.