Exemplo n.º 1
0
        private List <MethodArgument> GetMethodArguments(ParameterListSyntax node)
        {
            var items      = new List <MethodArgument>();
            var parameters = node.ChildNodes().OfType <ParameterSyntax>();

            foreach (var parameter in parameters)
            {
                var isIn         = parameter.ChildTokens().Any(x => x.Kind() == SyntaxKind.InKeyword);
                var isOut        = parameter.ChildTokens().Any(x => x.Kind() == SyntaxKind.OutKeyword);
                var isByRef      = parameter.ChildTokens().Any(x => x.Kind() == SyntaxKind.RefKeyword);
                var isByVal      = !isByRef;
                var isOptional   = parameter.ChildNodes().Any(x => x is EqualsValueClauseSyntax);
                var isParamArray = parameter.ChildTokens().Any(x => x.Kind() == SyntaxKind.ParamsKeyword);

                var parameterName = parameter.ChildTokens().FirstOrDefault(x => x.Kind() == SyntaxKind.IdentifierToken).ToString();
                var parameterType = parameter.ChildNodes().FirstOrDefault().ToString();

                items.Add(new MethodArgument
                {
                    IsByVal      = isByVal,
                    IsByRef      = isByRef,
                    IsIn         = isIn,
                    IsOut        = isOut,
                    IsOptional   = isOptional,
                    IsParamArray = isParamArray,
                    DefineName   = parameterName,
                    DefineType   = RemoveNamespace(parameterType),
                });
            }

            return(items);
        }
Exemplo n.º 2
0
        internal static ArgumentListSyntax FromParams(ParameterListSyntax paramList)
        {
            var parameters = paramList.ChildNodes()
                             .OfType <ParameterSyntax>();
            var arguments = SyntaxFactory.SeparatedList <ArgumentSyntax>(
                parameters.Select(param =>
            {
                var name     = param.Identifier.Text;
                var arg      = SyntaxFactory.Argument(SyntaxFactory.IdentifierName(name));
                var modifier = param.Modifiers.FirstOrDefault();
                if (modifier != null)
                {
                    switch (modifier.Text)
                    {
                    case "out":
                        arg = arg.WithRefKindKeyword(Token(SyntaxKind.OutKeyword));
                        break;

                    case "ref":
                        arg = arg.WithRefKindKeyword(Token(SyntaxKind.RefKeyword));
                        break;
                    }
                }
                return(arg);
            }));

            return(SyntaxFactory.ArgumentList(
                       Token(SyntaxKind.OpenParenToken),
                       arguments,
                       Token(SyntaxKind.CloseParenToken)
                       ));
        }
Exemplo n.º 3
0
        private List <MethodArgument> GetMethodArguments(ParameterListSyntax node)
        {
            var items      = new List <MethodArgument>();
            var parameters = node.ChildNodes().OfType <ParameterSyntax>();

            foreach (var parameter in parameters)
            {
                var isByRef      = parameter.ChildTokens().Any(x => x.Kind() == SyntaxKind.ByRefKeyword);
                var isByVal      = !isByRef;
                var isOptional   = parameter.ChildTokens().Any(x => x.Kind() == SyntaxKind.OptionalKeyword);
                var isParamArray = parameter.ChildTokens().Any(x => x.Kind() == SyntaxKind.ParamArrayKeyword);

                var modified      = parameter.ChildNodes().FirstOrDefault(x => x is ModifiedIdentifierSyntax);
                var parameterName = modified.ChildTokens().FirstOrDefault(x => x.Kind() == SyntaxKind.IdentifierToken).ToString();

                var asNode        = parameter.ChildNodes().FirstOrDefault(x => x is SimpleAsClauseSyntax);
                var parameterType = asNode.ChildNodes().FirstOrDefault().ToString();

                var hasArrayRank = modified.ChildNodes().Any();
                if (hasArrayRank)
                {
                    var arrayRank = modified.ChildNodes().FirstOrDefault().ToString();
                    parameterType = $"{parameterType}{arrayRank}";
                }

                items.Add(new MethodArgument
                {
                    IsByVal      = isByVal,
                    IsByRef      = isByRef,
                    IsOptional   = isOptional,
                    IsParamArray = isParamArray,
                    DefineName   = parameterName,
                    DefineType   = ConvertCSharpType(parameterType),
                });
            }

            return(items);
        }