Recently I have made a function for which all parameters are optional, but at the same time I need at least one parameter to be passed, otherwise the function doesn't do anything.
public async Task<discogsResult.DiscogsSearchResults?> Search(string? query = null, string? title = null, string? release_title = null, string credit? = null, string? artist = null, [...])
{
if (string.IsNullOrEmpty(query) &&
string.IsNullOrEmpty(title) &&
string.IsNullOrEmpty(release_title) &&
string.IsNullOrEmpty(credit) &&
string.IsNullOrEmpty(artist) &&
[...])
{
return null;
}
var discogsClient = new DiscogsClient.DiscogsClient(tokenInformation);
var discogsSearch = new DiscogsSearch()
{
query = query,
type = type,
title = title,
release_title = release_title,
credit = credit,
[...]
};
return await discogsClient.SearchAsync(discogsSearch);
}
I currently deal with it (check all parameters for null) and return empty if it is the case. But I would like to force the function caller to pass at least one because currently the function can be called with none.
Is there a way for the parameters to do that in c# ?