Exemplo n.º 1
0
        private void RenderSimpleField(ModelField field)
        {
            _generator.AppendLine($"Field(")
            .IncreaseIndentation()
            .AppendLine($"typeof({CsharpGenerator.Type(field.ResolvedType, false)}).GetGraphTypeFromType({field.Null.ToString().ToLower()}),")
            .AppendLine($"\"{field.Name.Camelize()}\",")
            .AppendLine($"@\"{field.Description}\",");

            if (field.ResolvedType.FieldType == FieldType.DateTime)
            {
                _generator.Append($"resolve: ctx => ctx.Source.{field.Name.Pascalize()}");
                if (field.Null)
                {
                    _generator.Append("?.");
                }
                else
                {
                    _generator.Append(".");
                }
                _generator.AppendLine("UtcDateTime");
            }
            else
            {
                _generator.AppendLine($"resolve: ctx => ctx.Source.{field.Name.Pascalize()}");
            }
            _generator.DecreaseIndentation()
            .AppendLine(");");
        }
Exemplo n.º 2
0
 private void RenderArgument(QLField arg, bool isLast)
 {
     _generator.AppendLine($"new QueryArgument(typeof({CsharpGenerator.Type(arg.ResolvedType, false)}).GetGraphTypeFromType({(arg.Default != null).ToString().ToLower()}))")
     .BeginBlock()
     .AppendLine($"Name = \"{arg.Name.Camelize()}\",")
     .AppendLine($"DefaultValue = {arg.Default},")
     .AppendLine($"Description = @\"{arg.Description?.Replace("\"", "\"\"") ?? ""}\"")
     .EndBlock(isLast ? "}" : "},");
 }
Exemplo n.º 3
0
 private void RenderField(ModelField field)
 {
     _generator.AppendLine($"/// <summary>")
     .AppendLine($"/// Gets or sets {field.Description}")
     .AppendLine($"/// /summary>");
     RenderAttributes(field);
     _generator.AppendLine($"public {CsharpGenerator.Type(field.ResolvedType, field.Null)} {field.Name.Pascalize()} {{ get; set; }}")
     .EnsureEmptyLine();
 }
Exemplo n.º 4
0
        private void RenderConstructor()
        {
            _generator.AppendLine($"/// <summary>")
            .AppendLine($"/// Initializes a new instance of the <see cref=\"{_project.Name.Pascalize()}{_suffix}Base\"/> class.")
            .AppendLine($"/// </summary>")
            .AppendLine($"public {_project.Name.Pascalize()}{_suffix}Base()")
            .BeginBlock();

            foreach (var field in _fields)
            {
                _generator.AppendLine($"Field<{CsharpGenerator.Type(field.ResolvedType, false)}Type>(")
                .IncreaseIndentation()
                .AppendLine($"\"{field.Name.Camelize()}\",")
                .AppendLine($"resolve: Resolve{field.Name.Pascalize()},");

                _generator.AppendLine($"description: @\"{field.Description?.Replace("\"", "\"\"") ?? ""}\",");

                if (field.Arguments != null)
                {
                    _generator.AppendLine("arguments: new QueryArguments(")
                    .IncreaseIndentation();

                    foreach (var arg in field.Arguments)
                    {
                        RenderArgument(arg, arg == field.Arguments.Last());
                    }

                    _generator.DecreaseIndentation()
                    .AppendLine(")");
                }
                else
                {
                    _generator.AppendLine("arguments: new QueryArguments()");
                }

                _generator.DecreaseIndentation()
                .AppendLine(");");
            }

            _generator.EndBlock()
            .EnsureEmptyLine();
        }