I do not know how to do that in git alone, but there is at least one commercial tool (i.e. it costs money) which deals with that kind of problems, called SemanticMerge.
It can handle quite a lot of cool cases, and supports C#, Java, and partially C. You can configure git to use it as merge tool.
(I’m not affiliated.)