Skip to content

VB -> C#: Improve date literal conversion #213

Description

@GrahamTheCoder

In #159 I said

This will need to deal with inlining a const field as well as just constant literals.

I didn't actually implement this part so it will now leave you with a compile time error. Something like:

Input:

Public Class Test
    Const x As Date = #1990-1-1#
    Private Sub Y(ByVal opt As Date = x)
    End Sub
End Class

Erroneous output:

using System;

public class Test
{
    DateTime x = DateTime.Parse("1990-01-01");
    private void Y(DateTime opt = x)
    {
    }
}

Expected output:

using System;

public class Test
{
    private static DateTime x = DateTime.Parse("1990-01-01");
    private void Y([Optional, DateTimeConstant(123456789L/*1990-01-01*/)] DateTime opt)
    {
    }
}

Proposed work:

  • Inline the tick count when a const field is used as an optional parameter
  • Add a comment for what date it represents in the existing case and this case
  • Make const date fields into static fields

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    VB -> C#Specific to VB -> C# conversioncompilation errorA bug where the converted output won't compile

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions