コード例 #1
0
        private static string GenerateArguments(FieldModel field)
        {
            var argBuilder   = new StringBuilder();
            var paramBuilder = new StringBuilder();
            var first        = true;

            foreach (var arg in BuildUtilities.SortArgs(field.Args))
            {
                if (!first)
                {
                    argBuilder.Append(", ");
                    paramBuilder.Append(", ");
                }

                var argName = TypeUtilities.GetArgName(arg);
                argBuilder.Append(TypeUtilities.GetCSharpType(arg.Type));
                argBuilder.Append(' ');
                argBuilder.Append(argName);
                paramBuilder.Append(argName);

                if (arg.DefaultValue != null)
                {
                    argBuilder.Append(" = ");
                    argBuilder.Append(TypeUtilities.GetCSharpLiteral(arg.DefaultValue, arg.Type));
                }
                else if (arg.Type.Kind != TypeKind.NonNull)
                {
                    argBuilder.Append(" = null");
                }

                first = false;
            }

            return(argBuilder.ToString());
        }
コード例 #2
0
        private static string GenerateDocComments(FieldModel field, bool generate)
        {
            if (generate && !string.IsNullOrWhiteSpace(field.Description))
            {
                var builder = new StringBuilder();
                DocCommentGenerator.GenerateSummary(field.Description, 8, builder);

                if (field.Args != null)
                {
                    foreach (var arg in BuildUtilities.SortArgs(field.Args))
                    {
                        if (!string.IsNullOrWhiteSpace(arg.Description))
                        {
                            var description = string.Join(" ", arg.Description.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)).Trim();
                            builder.AppendLine($"        /// <param name=\"{arg.Name}\">{description}</param>");
                        }
                    }
                }

                return(builder.ToString());
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
        private static string GenerateArguments(FieldModel field)
        {
            var argBuilder   = new StringBuilder();
            var paramBuilder = new StringBuilder();
            var first        = true;

            foreach (var arg in BuildUtilities.SortArgs(field.Args))
            {
                if (!first)
                {
                    argBuilder.Append(", ");
                    paramBuilder.Append(", ");
                }

                var argName = TypeUtilities.GetArgName(arg);
                argBuilder.Append(TypeUtilities.GetWrappedArgType(arg.Type));
                argBuilder.Append(' ');
                argBuilder.Append(argName);
                paramBuilder.Append(argName);

                if (arg.Type.Kind != TypeKind.NonNull)
                {
                    argBuilder.Append(" = null");
                }
                else if (arg.DefaultValue != null)
                {
                    throw new Exception("Encountered default value for non-null type.");
                }

                first = false;
            }

            return(argBuilder.ToString());
        }