Skip to content

C# and ASP.NET Core to Ruby

Recorder: the polyglot C# adapter (dotnet + a generated driver). Static methods are recordable. ASP.NET Core minimal API (app.MapGet) and attribute-routed controllers are found by analyze.

ASP.NET to Rails

ASP.NET Core Rails
app.MapGet("/x/{id}", ...) / [HttpGet("{id}")] route + controller action
Results.Ok(x) / return Ok(x) render json: x
Results.NotFound() / NotFound() head :not_found (match the recorded body)
CreatedAtAction(...) render json: x, status: :created, location: ...
Razor pages / views (.cshtml) ERB views (frontend.md)
Entity Framework DbContext, LINQ ActiveRecord; Where/Select/OrderBy/Include -> where/select/order/includes
Data annotations ([Required], [StringLength]) validates
Identity Rails authentication generator (password hashes differ: plan a re-hash)
IOptions<T> / appsettings.json config/*.yml + credentials
BackgroundService / Hangfire Active Job + Solid Queue
System.Text.Json camelCase output keep camelCase keys

Constructs

  • Errors: ArgumentException/ArgumentNullException/ArgumentOutOfRangeException -> ArgumentError; InvalidOperationException -> RuntimeError; KeyNotFoundException -> KeyError; FormatException (int.Parse) -> ArgumentError.
  • Nullable int? -> nil; ?? -> .nil? ? d : x; ?. -> &..
  • LINQ on collections -> Enumerable (Aggregate -> reduce, GroupBy -> group_by, ToDictionary -> to_h/index_by, First() raises when empty -> fetch(0) / raise).
  • Records / properties -> Data.define / attr_reader.
  • decimal -> BigDecimal, never Float.

Traps

  • Rounding: Math.Round(2.5) == 2 (banker's rounding by default!) -> round(half: :even); MidpointRounding.AwayFromZero -> round. ToString("F2") and string interpolation formats use the current culture: the decimal separator can be ,.
  • Integer overflow wraps unless checked; / truncates toward zero; % takes the dividend's sign.
  • string.Length counts UTF-16 units. string.Split(' ') keeps empty entries (split(" ", -1) with a regex in Ruby).
  • Dictionary<K,V> enumeration order is insertion order in practice but not guaranteed: sort when a recorded case shows an order.
  • DateTime without a kind is local time; serialize the way the recording shows.
Edit this page on GitHub →