private static void DecomposeType( ICSharpClientBuilderContext context, IType type, ICollection <ResultTypeComponentDescriptor> components) { if (type.IsListType()) { components.Add(new ResultTypeComponentDescriptor( context.GetFullTypeName((IOutputType)type, null), type.IsNullableType(), type.IsListType(), context.IsReferenceType((IOutputType)type, null))); DecomposeType( context, type.ElementType(), components); } else { components.Add(new ResultTypeComponentDescriptor( context.GetFullTypeName((IOutputType)type, null), true, type.IsListType(), context.IsReferenceType((IOutputType)type, null))); } }
public static ClientClassDescriptor CreateClientClassDescriptor( ICSharpClientBuilderContext context, ClientModel model) { bool needsStreamExecutor = false; bool needsOperationExecutor = false; var operations = new List <ClientOperationMethodDescriptor>(); foreach (OperationModel operation in model.Documents.SelectMany(t => t.Operations)) { var arguments = new List <ClientOperationMethodParameterDescriptor>(); foreach (ArgumentModel argument in operation.Arguments) { bool isOptional = argument.Type.IsNullableType() || argument.DefaultValue is { }; arguments.Add(new ClientOperationMethodParameterDescriptor( GetParameterName(argument.Name), GetPropertyName(argument.Name), context.GetFullTypeName(argument.Type, isOptional), isOptional, null)); } bool isStream = operation.Operation.Operation == OperationType.Subscription; if (!isStream) { needsOperationExecutor = true; } if (isStream) { needsStreamExecutor = true; } operations.Add(new ClientOperationMethodDescriptor( GetPropertyName(operation.Operation.Name !.Value), operation.Name, isStream, context.GetFullTypeName(operation.Parser.ReturnType), arguments)); } return(new ClientClassDescriptor( context.Name, context.Namespace, GetInterfaceName(context.Name), context.Types.IOperationExecutorPool, needsOperationExecutor ? context.Types.IOperationExecutor : null, needsStreamExecutor ? context.Types.IOperationStreamExecutor : null, operations)); }
private static void RegisterDeserializationMethod( ICSharpClientBuilderContext context, HashSet <string> methodNames, List <ResultParserDeserializerMethodDescriptor> deserializerMethods, List <ValueSerializerDescriptor> valueSerializers, string deserializerName, IType type) { if (methodNames.Add(deserializerName)) { string leafTypeName = type.NamedType().Print(); ValueSerializerDescriptor?serializer = valueSerializers.FirstOrDefault(t => t.Name == leafTypeName); if (serializer is null) { serializer = new ValueSerializerDescriptor( leafTypeName, GetFieldName(leafTypeName, "Serializer")); } var runtimeTypeComponents = new List <ResultTypeComponentDescriptor>(); DecomposeType(context, type, runtimeTypeComponents); deserializerMethods.Add(new ResultParserDeserializerMethodDescriptor( deserializerName, context.GetSerializationTypeName(type), context.GetFullTypeName((IOutputType)type, null), runtimeTypeComponents, serializer)); } }
public static EnumValueSerializerDescriptor CreateEnumValueSerializerDescriptor( ICSharpClientBuilderContext context, EnumTypeModel model) { return(new EnumValueSerializerDescriptor( context.CreateTypeName($"{model.Name}ValueSerializer"), context.Namespace, model.Type.Name, context.GetFullTypeName((EnumType)model.Type), CreateEnumElementDescriptors(model))); }
public static InputModelDescriptor CreateInputModelDescriptor( ICSharpClientBuilderContext context, ComplexInputTypeModel model) { var fields = new List <InputFieldDescriptor>(); foreach (InputFieldModel field in model.Fields) { fields.Add(new InputFieldDescriptor( field.Name, context.GetFullTypeName(field.Type))); } return(new InputModelDescriptor( model.Name, context.Namespace, fields)); }
public ResultParserDescriptor Create( ICSharpClientBuilderContext context, ParserModel model) { var temp = new StringBuilder(); var typeNames = new HashSet <string>(); var methodNames = new HashSet <string>(); var parserMethods = new List <ResultParserMethodDescriptor>(); var deserializerMethods = new List <ResultParserDeserializerMethodDescriptor>(); var valueSerializers = new List <ValueSerializerDescriptor>(); foreach (FieldParserModel fieldParser in model.FieldParsers) { var possibleTypes = new List <ResultTypeDescriptor>(); foreach (ComplexOutputTypeModel possibleType in fieldParser.PossibleTypes) { var components = new List <ResultTypeComponentDescriptor>(); var fields = new List <ResultFieldDescriptor>(); foreach (OutputFieldModel field in possibleType.Fields) { string?methodName; if (field.Type.IsLeafType()) { methodName = CreateDeserializerName(fieldParser.FieldType); RegisterDeserializationMethod( context, methodNames, deserializerMethods, valueSerializers, CreateDeserializerName(fieldParser.FieldType), fieldParser.FieldType); } else { methodName = $"Parse{GetPathName(field.Path)}"; } fields.Add(new ResultFieldDescriptor(field.Name, methodName)); } IType possibleFieldType = RewriteType(fieldParser.FieldType, possibleType.Type); DecomposeType(context, possibleFieldType, components); possibleTypes.Add(new ResultTypeDescriptor( context.GetFullTypeName( (IOutputType)possibleFieldType, fieldParser.Selection.SelectionSet), possibleFieldType.NamedType().Name, components, fields)); } var returnTypeComponents = new List <ResultTypeComponentDescriptor>(); DecomposeType(context, fieldParser.FieldType, returnTypeComponents); parserMethods.Add(new ResultParserMethodDescriptor( $"Parse{GetPathName(fieldParser.Path)}", new ResultTypeDescriptor( context.GetFullTypeName( (IOutputType)fieldParser.FieldType, fieldParser.Selection.SelectionSet), fieldParser.FieldType.NamedType().Name, returnTypeComponents, Array.Empty <ResultFieldDescriptor>()), possibleTypes, false)); } return(new ResultParserDescriptor( model.Name, context.Namespace, context.GetFullTypeName(model.ReturnType), parserMethods, deserializerMethods, valueSerializers)); }