C#/.NET port of Petrovich ruby gem