Beispiel #1
0
            public async Task <SyntaxTree> ReplaceVars(SyntaxTree syntaxTree, MonoProxy proxy, MessageId msg_id, int scope_id, CancellationToken token)
            {
                CompilationUnitSyntax root = syntaxTree.GetCompilationUnitRoot();

                foreach (var var in variables)
                {
                    ClassDeclarationSyntax  classDeclaration = root.Members.ElementAt(0) as ClassDeclarationSyntax;
                    MethodDeclarationSyntax method           = classDeclaration.Members.ElementAt(0) as MethodDeclarationSyntax;

                    JToken value = await proxy.TryGetVariableValue(msg_id, scope_id, var.Identifier.Text, false, token);

                    if (value == null)
                    {
                        throw new Exception($"The name {var.Identifier.Text} does not exist in the current context");
                    }

                    values.Add(ConvertJSToCSharpType(value ["value"]));

                    var updatedMethod = method.AddParameterListParameters(
                        SyntaxFactory.Parameter(
                            SyntaxFactory.Identifier(var.Identifier.Text))
                        .WithType(SyntaxFactory.ParseTypeName(GetTypeFullName(value["value"]))));
                    root = root.ReplaceNode(method, updatedMethod);
                }
                syntaxTree = syntaxTree.WithRootAndOptions(root, syntaxTree.Options);
                return(syntaxTree);
            }
Beispiel #2
0
            public async Task CheckIfIsProperty(MonoProxy proxy, MessageId msg_id, int scope_id, CancellationToken token)
            {
                foreach (var var in thisExpressions)
                {
                    JToken value = await proxy.TryGetVariableValue(msg_id, scope_id, var, true, token);

                    if (value == null)
                    {
                        throw new Exception($"The property {var} does not exist in the current context");
                    }
                }
            }