HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMinor

Finding arin whois information

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
informationarinwhoisfinding

Problem

I have created one method that get whois information from arin server is this any changes in this code for good code structure.

public ArinResponse GetWhoisInfo(string domainName)
{
    if (string.IsNullOrEmpty(domainName))
    {
        throw new ArgumentException("You have to supply a domainName.", nameof(domainName));
    }
    using (var clientService = new HttpClientService(arinBaseUrl))
    {
        string query = string.Format("pocs;domain={0}", domainName);
        var arinResponse = clientService.GetAPI(query);
        if (arinResponse != null)
        {
            return arinResponse;
        }
    }
    return new ArinResponse();
}


it should be very helpful to me. thanks.

HttpClientService is generic common class for calling rest api.

Solution

There is not much to comment on. In general the code looks fine.

I can only suggest making the return shorter by using the ?? (coalesce) operator

return clientService.GetAPI(query) ?? new ArinResponse();


and perhaps you should also consider using dependency injection for the HttpClientService.

Code Snippets

return clientService.GetAPI(query) ?? new ArinResponse();

Context

StackExchange Code Review Q#160314, answer score: 4

Revisions (0)

No revisions yet.