Esempio n. 1
0
        private static void AddCodeFix(CodeFixContext context, SyntaxNode root,
                                       Diagnostic diagnostic, ClassDeclarationSyntax classNode)
        {
            var newRoot = IsBusinessObjectSerializableMakeSerializableCodeFix.AddAttribute(
                root, classNode, IsBusinessObjectSerializableMakeSerializableCodeFixConstants.SerializableName);

            if (!root.HasUsing(IsBusinessObjectSerializableMakeSerializableCodeFixConstants.SystemNamespace))
            {
                newRoot = (newRoot as CompilationUnitSyntax).AddUsings(
                    SyntaxFactory.UsingDirective(SyntaxFactory.ParseName(
                                                     IsBusinessObjectSerializableMakeSerializableCodeFixConstants.SystemNamespace)));
            }

            if (!root.HasUsing(IsBusinessObjectSerializableMakeSerializableCodeFixConstants.CslaSerializationNamespace))
            {
                newRoot = (newRoot as CompilationUnitSyntax).AddUsings(
                    SyntaxFactory.UsingDirective(SyntaxFactory.ParseName(
                                                     IsBusinessObjectSerializableMakeSerializableCodeFixConstants.CslaSerializationNamespace)));
            }

            context.RegisterCodeFix(
                CodeAction.Create(
                    IsBusinessObjectSerializableMakeSerializableCodeFixConstants.AddSerializableAndUsingDescription,
                    _ => Task.FromResult <Document>(context.Document.WithSyntaxRoot(newRoot))), diagnostic);
        }
Esempio n. 2
0
        private static void AddCodeFixWhenSystemUsingExists(CodeFixContext context, SyntaxNode root,
                                                            Diagnostic diagnostic, ClassDeclarationSyntax classNode)
        {
            var newRoot = IsBusinessObjectSerializableMakeSerializableCodeFix.AddAttribute(
                root, classNode, IsBusinessObjectSerializableMakeSerializableCodeFixConstants.SerializableName);

            context.RegisterCodeFix(
                CodeAction.Create(
                    IsBusinessObjectSerializableMakeSerializableCodeFixConstants.AddSerializableDescription,
                    _ => Task.FromResult <Document>(context.Document.WithSyntaxRoot(newRoot))), diagnostic);
        }
Esempio n. 3
0
        private static void AddCodeFixWhenSystemUsingDoesNotExist(CodeFixContext context, SyntaxNode root,
                                                                  Diagnostic diagnostic, ClassDeclarationSyntax classNode)
        {
            var qualifiedRoot = IsBusinessObjectSerializableMakeSerializableCodeFix.AddAttribute(
                root, classNode, IsBusinessObjectSerializableMakeSerializableCodeFixConstants.SerializableFullName);

            context.RegisterCodeFix(
                CodeAction.Create(
                    IsBusinessObjectSerializableMakeSerializableCodeFixConstants.AddSystemSerializableDescription,
                    _ => Task.FromResult <Document>(context.Document.WithSyntaxRoot(qualifiedRoot))), diagnostic);

            var unqualifiedRoot = IsBusinessObjectSerializableMakeSerializableCodeFix.AddAttribute(
                root, classNode, IsBusinessObjectSerializableMakeSerializableCodeFixConstants.SerializableName);

            unqualifiedRoot = (unqualifiedRoot as CompilationUnitSyntax).AddUsings(
                SyntaxFactory.UsingDirective(SyntaxFactory.ParseName(
                                                 IsBusinessObjectSerializableMakeSerializableCodeFixConstants.SystemNamespace)));

            context.RegisterCodeFix(
                CodeAction.Create(
                    IsBusinessObjectSerializableMakeSerializableCodeFixConstants.AddSerializableAndUsingDescription,
                    _ => Task.FromResult <Document>(context.Document.WithSyntaxRoot(unqualifiedRoot))), diagnostic);
        }