backport method generification of Alexey Kudravtsev commit cd454f2 to fix compilation problem