I have 2 methods, one of which works with generic param and other one with regular string. It looks like this :
public static async Task PostAlertAsync(this IQueueService queueService,
AlertTypes alertType,
string orgId,
AlertDetailsBase details = null)
{
Guard.ArgumentNotNull(queueService, nameof(queueService));
Guard.ArgumentNotNullOrEmptyString(orgId, nameof(orgId));
var alertMessage = BuildAlertQueueMessage(alertType, orgId, details);
await queueService.SendMessageAsync(alertMessage);
}
public static async Task PostAlertAsync<T>(this IQueueService queueService,
AlertTypes alertType,
T source,
AlertDetailsBase details = null,
string customSubject = null)
where T: IAlertSource
{
Guard.ArgumentNotNull(queueService, nameof(queueService));
Guard.ArgumentNotNull(source, nameof(source));
var alertMessage = BuildAlertQueueMessage<T>(alertType, source, details, customSubject);
await queueService.SendMessageAsync(alertMessage);
}
I wonder, why calling compiling next call result with ambiguity error? String
in this case is obviously doesn't implement IAlertSource
QueueServiceCollection.Alerts.PostAlertAsync(AlertTypes.AzureAdDsProvisionCompleted, orgId);
Any ideas? Thanks.
Simply put: where
restrictions are not used while determining which method overload is to be used. So when you ignore that information it becomes not obvious which overload to use. You might argue that exact mach is better but it is not. Both methods can be called using string as parameter if you disregard this information.