dotnet/roslyn

VB disregards CultureInfo on DateTime evaluation

開放

#42,906 建立於 2020年3月30日

 (0 則留言) (0 個反應) (0 位負責人)C# (4,257 個分叉)batch import
Area-InteractiveBugInteractive-DebuggingLanguage-VBhelp wanted

倉庫指標

星標
 (20,414 顆星)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 256 個 PR)

描述

Steps to Reproduce:

Sub Main(args As String())
    Thread.CurrentThread.CurrentCulture = New CultureInfo("pt-BR")

    Dim dateTime = System.DateTime.Now
    Console.WriteLine(dateTime) // breakpoint here
End Sub
  1. Start debugging and stop at breakpoint;
  2. Open Watch Window and evaluate the following expressions:
dateTime
dateTime.ToString()

Expected Behavior: Both expressions have the same formatting.

Actual Behavior: DateTime object evaluation ignores formatting and uses "en-US" by default.

Remarks

  • Not a regression;
  • The issue only reproduces on VB since it follows the codepath for DateTime as a primitive value;
  • Regarding this code path on Formatter.FormatPrimitive(...):
if (value.Type.GetLmrType().IsDateTime())
{
    var dateDataValue = value.GetPropertyValue("Ticks", inspectionContext);
    obj = new DateTime((long)dateDataValue.HostObjectValue);
}

It is no longer necessary - the debugger now returns the DateTime object at value.HostObjectValue.

貢獻者指南