コード例 #1
0
ファイル: Extension.cs プロジェクト: tylike/Excess
        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)));
        }
コード例 #2
0
        private static SyntaxNode ParsePairs(IEnumerable <JSONParser.PairContext> pairs, Func <ParserRuleContext, Scope, SyntaxNode> continuation, Scope scope)
        {
            var members = new List <AnonymousObjectMemberDeclaratorSyntax>();

            foreach (var pair in pairs)
            {
                members.Add((AnonymousObjectMemberDeclaratorSyntax)continuation(pair, scope));
            }

            return(CSharp
                   .AnonymousObjectCreationExpression(CSharp.SeparatedList(
                                                          members)));
        }
コード例 #3
0
ファイル: Extension.cs プロジェクト: tylike/Excess
        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;
        }