VB -> C#: Lambda function should use dynamic type

Ouverte
#781 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
45/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
csharp
Domaine
devtools

Piste de recherche

Commencez par la signature du callback Application.Eval et reproduisez l’entrée VB fournie dans la conversion VB-to-C#. Comparez le paramètre du callback généré et l’accès au membre Application.Session avec la sortie C# attendue. C’est terminé lorsque la conversion produit la forme C# prévue et qu’un cas de régression couvre cette entrée.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

compilation error VB -> C#

I believe I have the correct C# code at the end, although I am not 100% certain.
In VB I was able to have the lambda function have a boolean, but in C# it appears it needs dynamic.

Also, note the different syntax for accessing members of Application.Session. In VB it is this

        Public Shared ReadOnly Property Session As <Dynamic> Object

but in C# it is this.

        public static dynamic Session { get; }`
VB.Net input code
    Public Sub DetectIOSWebAppStandalone()
        'does a one-time check of window.navigator.standalone and writes a session flag 
        'so we know if we have been launched in iOS webview 

        Application.Eval("window.navigator.standalone", Sub(a As Boolean)
                                                            If a = True Then
                                                                Application.Session("isIOSstandalone") = True 'its standalone mode
                                                            Else
                                                                Application.Session("isIOSstandalone") = False 'its not standalone mode
                                                            End If
                                                        End Sub)


    End Sub
Erroneous output
        public void DetectIOSWebAppStandalone()
        {
            // does a one-time check of window.navigator.standalone and writes a session flag 
            // so we know if we have been launched in iOS webview (or at least "Add To Homescreen App"
            // need to combine this with hybrid flag... not sure if returns true in hybrid app!

            Application.Eval("window.navigator.standalone", (bool a) => { if (a == true) { Application.Session("isIOSstandalone") = (object)true; } else { Application.Session("isIOSstandalone") = (object)false; } }); // its standalone mode
                                                                                                                                                                                                                         // its not standalone mode
        }
Expected output
        public void DetectIOSWebAppStandalone()
        {
            // does a one-time check of window.navigator.standalone and writes a session flag 
            // so we know if we have been launched in iOS webview (or at least "Add To Homescreen App"
            // need to combine this with hybrid flag... not sure if returns true in hybrid app!

            Application.Eval("window.navigator.standalone", (dynamic a) =>
            {
                if (a == true)
                {
                    Application.Session.isIOSstandalone = true;
                } else
                {
                    Application.Session.isIOSstandalone = false;
                }
            });

            //Application.Eval("window.navigator.standalone", (bool a) => { if (a == true) { Application.Session.isIOSstandalone = true; } else { Application.Session.isIOSstandalone = false; } }); // its standalone mode
                                                                                                                                                                                                                         // its not standalone mode
        }
Details

CodeConverter 8.41

Signature of Application.Eval method in C#

        //
        // Summary:
        //     Executes the JavaScript script on the client and receives the return value (or
        //     null) in the callback method.
        //
        // Parameters:
        //   script:
        //     The script to evaluate.
        //
        //   callback:
        //     Asynchronous callback method that receives the return value.
        public static void Eval(string script, Action<dynamic> callback);

Signature of Application.Eval method in VB

        '
        ' Summary:
        '     Executes the JavaScript script on the client and receives the return value (or
        '     null) in the callback method.
        '
        ' Parameters:
        '   script:
        '     The script to evaluate.
        '
        '   callback:
        '     Asynchronous callback method that receives the return value.
        Public Shared Sub Eval(script As String, <Dynamic({False, True})> callback As System.Action(Of Object))`
Langage dominant
C#
Étoiles
918
Forks
244
Merge moyen
1 j 10 h
PR mergées (30 j)
29

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de icsharpcode/CodeConverter

Toutes les issues de icsharpcode/CodeConverter

Issues similaires

Plus d'issues C#

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.