Exemplo n.º 1
0
 /// <summary>
 /// Generates the full class syntax, including the namespace, all leading/trailing members, and the localisation members.
 /// </summary>
 /// <returns>The syntax.</returns>
 public static SyntaxNode GenerateClassSyntax(Workspace workspace, LocalisationFile localisationFile)
 => SyntaxFactory.ParseCompilationUnit(SyntaxTemplates.FILE_HEADER_SIGNATURE)
 .AddMembers(
     SyntaxFactory.NamespaceDeclaration(
         SyntaxFactory.IdentifierName(localisationFile.Namespace))
     .WithMembers(
         SyntaxFactory.SingletonList <MemberDeclarationSyntax>(
             SyntaxFactory.ClassDeclaration(localisationFile.Name)
             .WithMembers(SyntaxFactory.List(
                              localisationFile.Members
                              .Select(m => m.Parameters.Length == 0 ? GeneratePropertySyntax(m) : GenerateMethodSyntax(workspace, m))
                              .Prepend(GeneratePrefixSyntax(localisationFile))
                              .Append(GenerateGetKeySyntax())))
             .WithModifiers(
                 new SyntaxTokenList(
                     SyntaxFactory.Token(SyntaxKind.PublicKeyword),
                     SyntaxFactory.Token(SyntaxKind.StaticKeyword))))));
Exemplo n.º 2
0
 /// <summary>
 /// Generates the syntax for the prefix constant.
 /// </summary>
 public static MemberDeclarationSyntax GeneratePrefixSyntax(LocalisationFile localisationFile)
 => SyntaxFactory.ParseMemberDeclaration(string.Format(SyntaxTemplates.PREFIX_CONST_TEMPLATE, $"{localisationFile.Namespace}.{localisationFile.Prefix}")) !;
Exemplo n.º 3
0
 /// <summary>
 /// Generates the syntax for accessing the member.
 /// </summary>
 public static MemberAccessExpressionSyntax GenerateMemberAccessSyntax(LocalisationFile localisationFile, LocalisationMember member)
 => SyntaxFactory.MemberAccessExpression(
     SyntaxKind.SimpleMemberAccessExpression,
     SyntaxFactory.IdentifierName(localisationFile.Name),
     SyntaxFactory.IdentifierName(member.Name));