Esempio n. 1
0
        private static MethodDeclarationSyntax createRemoteMethod(MethodDeclarationSyntax method)
        {
            var original = method;

            var args = CSharp
                       .AnonymousObjectCreationExpression(CSharp.SeparatedList(method
                                                                               .ParameterList
                                                                               .Parameters
                                                                               .Select(parameter =>
            {
                var identifierName = CSharp.IdentifierName(parameter.Identifier);
                return(CSharp.AnonymousObjectMemberDeclarator(
                           CSharp.NameEquals(identifierName),
                           identifierName));
            })));

            var value = original
                        .ReturnType.ToString() == "void"
                ? Roslyn.@null
                : Templates
                        .RemoteResult
                        .Get <ExpressionSyntax>(original.ReturnType);

            return(method
                   .WithModifiers(CSharp.TokenList())
                   .AddModifiers(
                       CSharp.Token(SyntaxKind.ProtectedKeyword),
                       CSharp.Token(SyntaxKind.OverrideKeyword))
                   .WithBody(Templates
                             .RemoteInternalMethod
                             .Get <BlockSyntax>(
                                 Roslyn.Quoted(original.Identifier.ToString()),
                                 args,
                                 value)));
        }
Esempio n. 2
0
        private static SyntaxNode JPair(JSONParser.PairContext pair, Func <ParserRuleContext, Scope, SyntaxNode> continuation, Scope scope)
        {
            string identifier = null;
            var    id         = pair.Identifier();

            if (id != null)
            {
                identifier = id.GetText();
            }
            else
            {
                identifier = pair
                             .StringLiteral()
                             .GetText();

                identifier = identifier.Substring(1, identifier.Length - 2); //traditional jason
            }

            var expr = (ExpressionSyntax)continuation(pair.value(), scope);

            return(CSharp
                   .AnonymousObjectMemberDeclarator(CSharp
                                                    .NameEquals(CSharp
                                                                .IdentifierName(identifier)),
                                                    expr));
        }
Esempio n. 3
0
        private static ExpressionSyntax ParseBody(IEnumerable<SyntaxToken> body, Scope scope, out AnonymousObjectCreationExpressionSyntax parameters)
        {
            parameters = null;

            var builder = new StringBuilder();
            var @params = new List<AnonymousObjectMemberDeclaratorSyntax>();
            builder.Append("@\"");
            foreach (var token in body)
            {
                var str = token.ToFullString();
                if (token.IsKind(SyntaxKind.IdentifierToken) && str.StartsWith("@"))
                {
                    var newToken = CSharp.ParseToken(str.Substring(1))
                        .WithAdditionalAnnotations(token.GetAnnotations());

                    @params.Add(CSharp.AnonymousObjectMemberDeclarator(
                        CSharp.NameEquals(CSharp.IdentifierName(newToken)),
                        CSharp.IdentifierName(newToken)));
                }

                builder.Append(str);
            }
            builder.Append("\"");

            var result = CSharp.ParseExpression(builder.ToString());
            if (result == null)
            {
                Debug.Assert(false); //td: error
                return null;
            }

            parameters = CSharp.AnonymousObjectCreationExpression(CSharp.SeparatedList(
                @params));

            return result;
        }