Exemplo n.º 1
0
        private static async Task <Solution> GenerateRegisterProperty(string registerPropertyMethodName, Document document,
                                                                      PropertyDeclarationSyntax propertyDeclaration, IPropertySymbol propertySymbol,
                                                                      bool returnsMounter, CancellationToken ct)
        {
            var staticConstructor = await GetStaticConstructor(propertySymbol, ct);

            ClassDeclarationSyntax classDeclaration;

            if (staticConstructor != null)
            {
                document         = document.Project.GetDocument(staticConstructor.SyntaxTree);
                classDeclaration = staticConstructor.FirstAncestor <ClassDeclarationSyntax>();
            }
            else
            {
                classDeclaration = propertyDeclaration.FirstAncestor <ClassDeclarationSyntax>();
            }

            var editor = await DocumentEditor.CreateAsync(document, ct);

            if (returnsMounter)
            {
                GenerateMounterFieldDeclaration(editor, registerPropertyMethodName, classDeclaration, propertySymbol, ct);
            }
            else if (staticConstructor == null)
            {
                GenerateStaticConstructor(editor, classDeclaration, registerPropertyMethodName, propertySymbol, returnsMounter, ct);
            }
            else
            {
                GenerateRegistrationStatement(editor, classDeclaration, staticConstructor, registerPropertyMethodName, propertySymbol, returnsMounter, ct);
            }

            return(editor.GetChangedDocument().Project.Solution);
        }
Exemplo n.º 2
0
        private static async Task <Solution> GenerateRegisterChildModel(Document document, SemanticModel semanticModel,
                                                                        PropertyDeclarationSyntax propertyDeclaration, IPropertySymbol childProperty, IPropertySymbol foreignKey, CancellationToken ct)
        {
            var staticConstructor = await GetStaticConstructor(childProperty, ct);

            ClassDeclarationSyntax classDeclaration;

            if (staticConstructor != null)
            {
                document         = document.Project.GetDocument(staticConstructor.SyntaxTree);
                classDeclaration = staticConstructor.FirstAncestor <ClassDeclarationSyntax>();
            }
            else
            {
                classDeclaration = propertyDeclaration.FirstAncestor <ClassDeclarationSyntax>();
            }

            var editor = await DocumentEditor.CreateAsync(document, ct);

            GenerateRegisterChildModel(editor, staticConstructor, classDeclaration, semanticModel, childProperty, foreignKey);

            return(editor.GetChangedDocument().Project.Solution);
        }