If a marriage is declared invalid, an agreement that would otherwise have been a premarital agreement is enforceable only to the extent necessary to avoid an inequitable result.