each dwelling unit in the housing will remain affordable, according to binding commitments satisfactory to the Secretary, for
(B) such other period as the Secretary determines is the longest feasible period of time consistent with sound economics and the purposes of this subchapter, except upon a foreclosure by a lender (or upon other transfer in lieu of foreclosure) if that action
(i) recognizes any contractual or legal rights of any public agency,
nonprofit">
nonprofit sponsor, or other person or entity to take an action that would
(I) avoid termination of low-income affordability, in the case of foreclosure; or
(II) transfer ownership in lieu of foreclosure; and
(ii) is not for the purpose of avoiding low-income affordability restrictions, as determined by the Secretary.