Dont know what object type will be passed in, if it is type of FishDTO it has a different route to generate the uri, if it is not fish than it is mammal and should follow standard route. Is there a cleaner way to do this? Instead of using type is there a better way using as? This works but it just looks ugly:
public Uri GetAnimalImageUrl(object animalResult)
{
if (animalResult.GetType() == typeof(FishDTO))
{
return new Uri(GetFishImageUrl((FishDTO)animalResult));
}
var mammal = (MammalDTO)animalResult;
var mammalUrl = GetMammalImageUrl(mammal);
if (!string.IsNullOrEmpty(mammalUrl))
{
return new Uri(mammalUrl);
}
_logger.Error("Image not found for animal");
return null;
}
FishDTO
. Make a different method that accepts aMammalDTO
. Do those classes have an inheritance relationship? If so you only need one method...