CodeConverter icon indicating copy to clipboard operation
CodeConverter copied to clipboard

VB -> C#: Simple boolean eval function breaks on dynamic storage object

Open docfresh opened this issue 4 years ago • 1 comments

VB.Net input code

    Public Function IsHybridApp() As Boolean
        Return Application.Session("hybrid") IsNot Nothing AndAlso Application.Session("hybrid") = 1
    End Function

Erroneous output

public static bool IsHybridApp()
        {
            return Conversions.ToBoolean((object)(Application.Session.hybrid is object) && Operators.ConditionalCompareObjectEqual(Application.Session.hybrid, 1, false));
        }

Expected output

        public static bool IsHybridApp()
        {
              return Application.Session.hybrid != null && Application.Session.hybrid == 1;
        }

Details

CC 8.41

Application.Session definition is

    //
    // Summary:
    //     Provides a generic storage for session-based objects.
    public static dynamic Session { get; }

docfresh avatar Nov 04 '21 00:11 docfresh

Lots of dynamic related stuff will likely be solved with the same change, feel free to add more examples of you find them, but this one is definitely good for its simplicity

GrahamTheCoder avatar Nov 04 '21 08:11 GrahamTheCoder

I think this is slightly improved in the recent release. It's still ugly but I think now runnable. I've added a test case for it

GrahamTheCoder avatar Feb 12 '24 21:02 GrahamTheCoder