Skip to content

C# और ASP.NET Core से Ruby

Recorder: polyglot C# adapter (dotnet + एक generated driver)। Static methods record किए जा सकते हैं। ASP.NET Core minimal API (app.MapGet) और attribute-routed controllers को analyze ढूँढ लेता है।

ASP.NET से 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 (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 अलग होते हैं: re-hash का plan बनाएँ)
IOptions<T> / appsettings.json config/*.yml + credentials
BackgroundService / Hangfire Active Job + Solid Queue
System.Text.Json का camelCase output camelCase keys बनाए रखें

Constructs

  • Errors: ArgumentException/ArgumentNullException/ArgumentOutOfRangeException -> ArgumentError; InvalidOperationException -> RuntimeError; KeyNotFoundException -> KeyError; FormatException (int.Parse) -> ArgumentError।
  • Nullable int? -> nil; ?? -> .nil? ? d : x; ?. -> &.।
  • Collections पर LINQ -> Enumerable (Aggregate -> reduce, GroupBy -> group_by, ToDictionary -> to_h/index_by, First() खाली होने पर raise करता है -> fetch(0) / raise)।
  • Records / properties -> Data.define / attr_reader।
  • decimal -> BigDecimal, कभी Float नहीं।

Traps

  • Rounding: Math.Round(2.5) == 2 (default रूप से banker's rounding!) -> round(half: :even); MidpointRounding.AwayFromZero -> round। ToString("F2") और string interpolation formats current culture इस्तेमाल करते हैं: decimal separator , हो सकता है।
  • Integer overflow wrap होता है जब तक checked न हो; / zero की ओर truncate करता है; % dividend का sign लेता है।
  • string.Length UTF-16 units गिनता है। string.Split(' ') खाली entries रखता है (Ruby में regex के साथ split(" ", -1))।
  • Dictionary<K,V> का enumeration order व्यवहार में insertion order होता है, पर इसकी guarantee नहीं: जब कोई recorded case कोई order दिखाए तो sort करें।
  • बिना kind वाला DateTime local time होता है; उसे वैसे ही serialize करें जैसा recording में दिखता है।
इस page को GitHub पर edit करें →