79163053

Date: 2024-11-06 14:37:20
Score: 0.5
Natty:
Report link

The better approach here is to test the type in the method.

AddOrUpdate<TorC>( TorC entryOrEntries)
{
    if (typeof(ToC).IsAssignableTo(typeof(IEnumerable)) {
        AddOrUpdateEnumerable( entryOrEntries);
    } else {
        AddOrUpdateSingle( entryOrEntries);
    }
}

This reduces unintentional errors because the caller doesn't have to remember to specify the type when passing a value. In the other approach, if the caller forgets to specify the type then the compiler will not complain and the wrong method will be called.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: sjb