public override IEnumerable <MemberDeclarationSyntax> Generate() { string className = ((QualifiedNameSyntax)TypeInfo.Name).Right.Identifier.ValueText; ClassDeclarationSyntax declaration = ClassDeclaration(className) .AddElementAnnotation(Element, Context.ElementRegistry) .AddGeneratorAnnotation(this) .AddModifiers(Token(SyntaxKind.PublicKeyword)) .AddBaseListTypes(SimpleBaseType(RequestsNamespace.OperationRequest)); declaration = declaration.AddMembers( GenerateParameterProperties(className) .Concat(MemberGenerators .Select(p => p.Generate(Element, null))) .ToArray()); yield return(declaration); if (Element.GetRequestBody()?.GetMediaTypes().Any(p => SerializerSelector.Select(p) == null) ?? false) { var buildContentMethod = declaration.Members .OfType <MethodDeclarationSyntax>() .First(p => p.Identifier.Text == BuildContentMethodGenerator.BuildContentMethodName); var httpContentGenerator = new HttpContentRequestTypeGenerator(Element, Context, this, buildContentMethod); foreach (var otherMember in httpContentGenerator.Generate()) { yield return(otherMember); } } }
protected override YardarmTypeInfo GetTypeInfo() { SerializerDescriptor?serializerDescriptor = SerializerSelector.Select(Element)?.Descriptor; if (serializerDescriptor == null) { throw new InvalidOperationException($"No serializer configured for {Element}."); } INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(NameKind.Class); NameSyntax ns = Context.NamespaceProvider.GetNamespace(RequestTypeGenerator.Element); TypeSyntax name = QualifiedName(ns, IdentifierName(formatter.Format($"{RequestTypeGenerator.Element.Element.OperationId}-{serializerDescriptor.NameSegment}-Request"))); return(new YardarmTypeInfo(name)); }