I want to remove the code duplication, I have a base abstract class A
defined in a separate assembly and derived classes B
, C
(each in a separate assembly), which are different only by calling a sync or async versions of methods. I want to move all the logic to the base class to remove code duplication. I’ve tried adding virtual methods to the base class for sync and async versions (Evaluate
and EvaluateAsync
), but it is not the best choice as they will be publically visible and will confuse the customers when to call any of them.
My attempts:
public virtual Task<object?> EvaluateAsync()
{
return Task.FromResult<object?>(null);
}
public virtual object? Evaluate()
{
return null;
}
With this both methods will be available in sync and async assemblies. Is any way to solve it?
the_it_guy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.