private ClassDeclarationSyntax GenerateReadReplicaGrain(ClassDeclarationSyntax grainClass, ITypeSymbol swmrInterface)
        {
            string readReplicaGrainName             = SwmrUtils.GetReadReplicaGrainName(grainClass.Identifier.Text);
            string readReplicaInterfaceName         = SwmrUtils.GetReadReplicaInterfaceName(swmrInterface.Name);
            ClassDeclarationSyntax readReplicaGrain = GenerateClassSqueleton(readReplicaGrainName).WithBaseList(RoslynUtils.BaseList(new[] { "Grain", readReplicaInterfaceName }));

            string grainStateTypeName = FindGrainStateTypeName(grainClass);

            readReplicaGrain = readReplicaGrain.AddMembers(SF.FieldDeclaration(SF.VariableDeclaration(SF.ParseTypeName(grainStateTypeName), SF.SeparatedList(new[] { SF.VariableDeclarator(SF.Identifier("State")) }))).AddModifiers(SF.Token(SyntaxKind.PrivateKeyword)));

            readReplicaGrain = readReplicaGrain.AddMembers(GenerateReadReplicaOnActivateAsync(swmrInterface));

            foreach (ISymbol member in swmrInterface.GetMembers())
            {
                IMethodSymbol methodSymbol = member as IMethodSymbol;
                if (methodSymbol == null || !IsReadOnlyMethod(methodSymbol))
                {
                    continue;
                }
                MethodDeclarationSyntax methodImpl = RoslynUtils.FindImplementation(methodSymbol, grainClass);
                readReplicaGrain = readReplicaGrain.AddMembers(methodImpl.WithLeadingTrivia(SF.EndOfLine("")));
            }

            readReplicaGrain = readReplicaGrain.AddMembers(GenerateSetStateMethod(grainStateTypeName));

            return(readReplicaGrain);
        }
示例#2
0
 public static ClassDeclarationSyntax AddField(ClassDeclarationSyntax classDeclaration, string type, string name)
 {
     return(classDeclaration.AddMembers(
                SF.FieldDeclaration(SF.VariableDeclaration(SF.ParseTypeName(type),
                                                           SF.SeparatedList(new[] { SF.VariableDeclarator(SF.Identifier(name)) })))
                .AddModifiers(SF.Token(SyntaxKind.PrivateKeyword))));
 }
示例#3
0
 public FieldDeclarationSyntax Build() =>
 SF.FieldDeclaration(
     GeneratorHelper.EmptyAttributeList(),
     SF.TokenList(this.modifiers),
     SF.VariableDeclaration(
         fieldType,
         SF.SeparatedList(
             this.variableNames.Select(n => SF.VariableDeclarator(n)))));
        static IEnumerable <MemberDeclarationSyntax> ColumnToMembers(string column, IEnumerable <IFieldSymbol> fields)
        {
            var        fieldsList = fields.ToList();
            TypeSyntax columnElementType;

            if (fieldsList.Count > 1)
            {
                var fieldGroupTypeName = SF.IdentifierName($"{column}_t");
                yield return(SF.StructDeclaration(fieldGroupTypeName.Identifier)
                             .WithMembers(SF.List(fields.Select(x => SF.FieldDeclaration(SF.VariableDeclaration(
                                                                                             SF.IdentifierName(x.Type.Name),
                                                                                             SF.SingletonSeparatedList(SF.VariableDeclarator(x.Name))))).Cast <MemberDeclarationSyntax>())));

                columnElementType = fieldGroupTypeName;
            }
            else
            {
                columnElementType = SF.IdentifierName(fields.First().Type.Name);
            }

            yield return(SF.FieldDeclaration(SF.VariableDeclaration(
                                                 SF.ArrayType(columnElementType, SF.SingletonList(SF.ArrayRankSpecifier())),
                                                 SF.SingletonSeparatedList(SF.VariableDeclarator(column)))));
        }