static void EnsureSelectionSetsHaveUniqueName(GenContext context) { foreach (var ns in context.Namespaces) { var douplicates = ns.SelectionSets.GroupBy(g => g.Name) .Where(g => g.Count() > 1) .ToArray(); foreach (var douplicateGroup in douplicates) { var douplicate = douplicateGroup.ToList(); foreach (var genType in douplicate) { genType.Name += douplicate.IndexOf(genType) + 1; } } } }
public static string RenderSingleFile(GenContext context) { var text = new StringBuilder(); text.AppendLine("using System;"); text.AppendLine("using GraphQL.Client;"); text.AppendLine("using Newtonsoft.Json.Linq;"); text.AppendLine("using GraphQL.Common.Request;"); text.AppendLine("using System.Threading.Tasks;"); RenderNamespace(text, context, context.Fragments); foreach (var ns in context.Namespaces) { RenderNamespace(text, context, ns); } RenderClient(text, context); return(text.ToString()); }
static void RenderNamespace(StringBuilder text, GenContext context, GenNamespace ns) { text.AppendLine(); text.AppendLine("namespace " + NamespaceDeclarionName(context, ns)); text.AppendLine("{"); var useInterface = ns == context.Fragments; foreach (var genType in ns.SelectionSets) { if (useInterface) { RenderInterface(text, context, genType); } else { RenderClass(text, context, genType); } } text.AppendLine("}"); }
static string TypeReferenceName(GenContext context, IGenReference reference, bool fullname = false) { switch (reference) { case GenSelectionSet set: { var name = TypeName(set); var clrType = GetClrType(set); if (clrType != null) { return(ClrTypeFullName(clrType)); } if (fullname) { name = "global::" + NamespaceDeclarionName(context, set.Namespace) + "." + name; } return(name); } case GenList list: { var element = TypeReferenceName(context, list.Element, fullname); return(ClrTypeFullName(typeof(List <>)) + "<" + element + ">"); } case GenNonNull nonNull: { return(TypeReferenceName(context, nonNull.Element, fullname)); } default: throw new NotImplementedException(reference.GetType().FullName); } }
static string PropertyBody(GenContext context) => context.Config.ReadOnly ? "{get;}" : "{get; set;}";