private static string CreateClass_ColorNames(List <ColorEntity> entities, ProgressBar progress) { string classDeclaration; using (var child = progress.Spawn(entities.Count, "enum items added", childOptions)) { var members = entities.Select((entity, index) => { //double prog = (double)index / entities.Count / STEPS; //progress.Report(PROGRESS_STEP * lastStep + prog); child.Tick(); // Console.WriteLine($"Converted {index} of {entities.Count} entities!"); return(Syntax.EnumMemberDeclaration(identifier: Syntax.Identifier(entity.Name.SanitizeEnum()))); }); // TODO // Console.WriteLine("Declaring enum!"); var declaration = Syntax.EnumDeclaration( new SyntaxList <AttributeListSyntax>(), identifier: Syntax.Identifier("ColorNames"), modifiers: Syntax.TokenList(Syntax.Token(SyntaxKind.PublicKeyword)), baseList: null, members: Syntax.SeparatedList(members)) .NormalizeWhitespace(); classDeclaration = declaration.ToFullString(); } return(classDeclaration); }
SeparatedSyntaxList <EnumMemberDeclarationSyntax> CreateValues() { return(SF.SeparatedList(Type.Members.Select(GetMemberDeclaration))); EnumMemberDeclarationSyntax GetMemberDeclaration(EnumMember member) { EnumMemberDeclarationSyntax declaration = SF.EnumMemberDeclaration ( SF.List(new[] { SF.AttributeList(SF.SeparatedList(new[] { SF.Attribute( SF.ParseName("JsiiEnumMember"), SF.ParseAttributeArgumentList($"(\"{member.Name}\")") ) })) }), Symbols.GetNameSyntaxToken(Type, member), null ); if (member.Docs != null) { DocCommentGeneratorBase <EnumMember> generator = new EnumMemberDocCommentGenerator(member); SyntaxTriviaList trivia = SF.TriviaList(generator.CreateDocComment()); declaration = declaration.WithLeadingTrivia(trivia); } return(declaration); } }
SeparatedSyntaxList <EnumMemberDeclarationSyntax> CreateValues() { return(SF.SeparatedList(Type.Members.Select(GetMemberDeclaration))); EnumMemberDeclarationSyntax GetMemberDeclaration(EnumMember member) { EnumMemberDeclarationSyntax declaration = SF.EnumMemberDeclaration ( SF.List(GetAttributeLists()), Symbols.GetNameSyntaxToken(Type, member), null ); if (member.Docs != null) { DocCommentGeneratorBase <EnumMember> generator = new EnumMemberDocCommentGenerator(member); SyntaxTriviaList trivia = SF.TriviaList(generator.CreateDocComment()); declaration = declaration.WithLeadingTrivia(trivia); } return(declaration); IEnumerable <AttributeListSyntax> GetAttributeLists() { yield return(SF.AttributeList(SF.SingletonSeparatedList( SF.Attribute( SF.ParseName("JsiiEnumMember"), SF.ParseAttributeArgumentList($"(name: \"{member.Name}\")") ) ))); if (member.Docs?.Stability == Stability.Deprecated) { var argument = member.Docs?.Deprecated != null?SF.Literal(member.Docs?.Deprecated).ToString() : ""; yield return(SF.AttributeList(SF.SingletonSeparatedList( SF.Attribute( SF.ParseName("System.Obsolete"), SF.ParseAttributeArgumentList($"({argument})") ) ))); } } } }