コード例 #1
0
        static void RenderClass(StringBuilder text, GenContext context, GenSelectionSet selectionSet)
        {
            text.Append("  public class " + TypeName(selectionSet));

            if (selectionSet.RefFragments.Any())
            {
                text.Append(" : ");
                text.AppendJoin(", ", selectionSet.RefFragments.Select(f => TypeReferenceName(context, f, true)));
            }

            text.AppendLine();
            text.AppendLine("  {");

            foreach (var fragment in selectionSet.RefFragments)
            {
                foreach (var property in fragment.Fields)
                {
                    text.AppendLine("    public " + TypeReferenceName(context, property.Type) + " " + UpperCaseFirst(property.Name) + " " + PropertyBody(context));
                }
            }

            foreach (var property in selectionSet.Fields)
            {
                text.AppendLine("    public " + TypeReferenceName(context, property.Type) + " " + UpperCaseFirst(property.Name) + " " + PropertyBody(context));
            }

            text.AppendLine("  }");
        }
コード例 #2
0
        static string TypeName(GenSelectionSet selectionSet)
        {
            var name = selectionSet.Name;

            name = UpperCaseFirst(name);
            return(name);
        }
コード例 #3
0
        static void Run(GenContext context, SelectionSet set, GenSelectionSet selectionSet)
        {
            foreach (var selection in set.Selections)
            {
                switch (selection)
                {
                case Field field:
                {
                    var fieldType = ((ObjectGraphType)selectionSet.GraphType).GetField(field.Name);

                    var propertyType = selectionSet.Namespace.CreateReference(fieldType.ResolvedType, field);
                    selectionSet.AddField(field.Alias ?? field.Name, propertyType);

                    Run(context, field.SelectionSet, propertyType.GetSelectionSet());

                    break;
                }

                case FragmentSpread fragment:
                {
                    var fragmentType = context.Fragments.SelectionSets.Find(t => t.Name == fragment.Name);
                    selectionSet.AddFragment(fragmentType);
                    break;
                }

                case InlineFragment inline:
                {
                    throw new NotImplementedException();
                }

                default:
                    throw new InvalidOperationException("Uh whats that?");
                }
            }
        }
コード例 #4
0
        static void RenderInterface(StringBuilder text, GenContext context, GenSelectionSet selectionSet)
        {
            text.AppendLine("  public interface " + TypeName(selectionSet));
            text.AppendLine("  {");

            foreach (var property in selectionSet.Fields)
            {
                text.AppendLine("    " + TypeReferenceName(context, property.Type) + " " + UpperCaseFirst(property.Name) + " " + PropertyBody(context));
            }

            text.AppendLine("  }");
        }
コード例 #5
0
        public GenSelectionSet CreateSelectionSet(IGraphType graphType, INode node)
        {
            if (graphType == null)
            {
                return(null);
            }
            var selectionSet = new GenSelectionSet {
                Namespace = this, Name = graphType.Name, GraphType = graphType, Node = node
            };

            if (!selectionSet.MapsToBuildInType)
            {
                SelectionSets.Add(selectionSet);
            }
            return(selectionSet);
        }
コード例 #6
0
        static Type GetClrType(GenSelectionSet selectionSet)
        {
            switch (selectionSet.GraphType)
            {
            case IntGraphType _:
                return(typeof(long));

            case FloatGraphType _:
                return(typeof(double));

            case DecimalGraphType _:
                return(typeof(decimal));

            case StringGraphType _:
                return(typeof(string));

            case BooleanGraphType _:
                return(typeof(bool));

            case DateGraphType _:
                return(typeof(DateTime));

            case DateTimeOffsetGraphType _:
                return(typeof(DateTimeOffset));

            case TimeSpanSecondsGraphType _:
                return(typeof(TimeSpan));

            case IdGraphType _:
                return(typeof(string));

            case ShortGraphType _:
                return(typeof(short));

            case UShortGraphType _:
                return(typeof(ushort));

            case ULongGraphType _:
                return(typeof(ulong));

            case UIntGraphType _:
                return(typeof(uint));
            }
            return(null);
        }
コード例 #7
0
        static void Run(GenSelectionSet set)
        {
            switch (set.GraphType)
            {
            case IComplexGraphType complexType:
            {
                foreach (var fieldType in complexType.Fields)
                {
                    var fieldReference = set.Namespace.CreateReference(fieldType.ResolvedType, null);
                    set.AddField(fieldType.Name, fieldReference);
                    Run(fieldReference.GetSelectionSet());
                }
                break;
            }

            default:
                return;
            }
        }
コード例 #8
0
 public void AddFragment(GenSelectionSet fragment)
 => RefFragments.Add(fragment);