That logic only applies to custom object sharing, and only if the object isn't public read/write. Standard sharing uses various specialized tables, such as AccountShare or CaseShare (to name a couple). A full solution would involve some heavy lifting, and probably wouldn't be worth it. However, let's say you wanted to approach it, your algorithm would be something like:
- Describe the object (apiName), and see if isCustom() is true or not.
- If not custom, consult a mapping table to determine which share table to use.
- If custom, append __Share to the apiName to determine which share table to use.
- Try to describe the share table resolved above.
- If not custom, and table exists, use some specialized handler to determine which fields to set.
- If custom, able table exists, use generic algorithm to create shares (they all work the same).
You may also need/want a "share reason" parameter. Standard shares can only be "manual", but custom shares might include custom sharing reasons.