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 static InputModelSerializerDescriptor CreateInputModelSerializerDescriptor( ICSharpClientBuilderContext context, ComplexInputTypeModel model) { var typeNames = new HashSet <string>(); var methodNames = new HashSet <string>(); var fieldSerializers = new List <InputFieldSerializerDescriptor>(); var typeSerializers = new List <InputTypeSerializerMethodDescriptor>(); var valueSerializers = new List <ValueSerializerDescriptor>(); foreach (InputFieldModel field in model.Fields) { string typeName = field.Type.NamedType().Print(); string serializerName = CreateSerializerName(field.Type); fieldSerializers.Add(new InputFieldSerializerDescriptor( field.Name, field.Field.Name, serializerName)); if (typeNames.Add(typeName)) { valueSerializers.Add(new ValueSerializerDescriptor( typeName, CreateValueSerializerName(field.Type))); } RegisterTypeSerializer(serializerName, field.Type); } return(new InputModelSerializerDescriptor( GetClassName(model.Name, "InputSerializer"), context.Namespace, model.Type.Name, model.Name, fieldSerializers, valueSerializers, typeSerializers)); void RegisterTypeSerializer(string serializerName, IType type) { if (methodNames.Add(serializerName)) { string?innerSerializerName = type.IsListType() ? CreateSerializerName(type.ListType().ElementType) : null; typeSerializers.Add(new InputTypeSerializerMethodDescriptor( serializerName, type.IsNullableType(), type.IsListType(), type.IsListType() ? null : CreateValueSerializerName(type.NamedType()), innerSerializerName)); if (innerSerializerName is { }) { RegisterTypeSerializer(innerSerializerName, type.ListType().ElementType); } }