Esempio n. 1
0
 public override SyntaxNode CreateMethodDeclaration(
     IMethodSymbol method, CodeGenerationDestination destination, CodeGenerationOptions options)
 {
     if (method.IsConstructor())
     {
         return(ConstructorGenerator.GenerateConstructorDeclaration(method, destination, options));
     }
     else if (method.IsDestructor())
     {
         return(DestructorGenerator.GenerateDestructorDeclaration(method, destination, options));
     }
     else
     {
         return(MethodGenerator.GenerateMethodDeclaration(method, destination, options));
     }
 }
Esempio n. 2
0
        public override SyntaxNode CreateMethodDeclaration(
            IMethodSymbol method, CodeGenerationDestination destination, CodeGenerationOptions options)
        {
            // Synthesized methods for properties/events are not things we actually generate
            // declarations for.
            if (method.AssociatedSymbol is IEventSymbol)
            {
                return(null);
            }

            if (method.AssociatedSymbol is IPropertySymbol)
            {
                // we will ignore the method if the associated property can be generated.
                var property = (IPropertySymbol)method.AssociatedSymbol;
                if (PropertyGenerator.CanBeGenerated(property))
                {
                    return(null);
                }
            }

            if (method.IsConstructor())
            {
                return(ConstructorGenerator.GenerateConstructorDeclaration(
                           method, destination, Workspace, options, options.ParseOptions));
            }
            else if (method.IsDestructor())
            {
                return(DestructorGenerator.GenerateDestructorDeclaration(method, destination, options));
            }
            else if (method.IsUserDefinedOperator())
            {
                return(OperatorGenerator.GenerateOperatorDeclaration(
                           method, destination, Workspace, options, options.ParseOptions));
            }
            else if (method.IsConversion())
            {
                return(ConversionGenerator.GenerateConversionDeclaration(
                           method, destination, Workspace, options, options.ParseOptions));
            }
            else
            {
                return(MethodGenerator.GenerateMethodDeclaration(
                           method, destination, Workspace, options, options.ParseOptions));
            }
        }
        protected override TDeclarationNode AddMethod <TDeclarationNode>(TDeclarationNode destination, IMethodSymbol method, CodeGenerationOptions options, IList <bool> availableIndices)
        {
            CheckDeclarationNode <TypeDeclarationSyntax, CompilationUnitSyntax, NamespaceDeclarationSyntax>(destination);

            // Synthesized methods for properties/events are not things we actually generate
            // declarations for.
            if (method.AssociatedSymbol is IEventSymbol)
            {
                return(destination);
            }
            // we will ignore the method if the associated property can be generated.

            if (method.AssociatedSymbol is IPropertySymbol property)
            {
                if (PropertyGenerator.CanBeGenerated(property))
                {
                    return(destination);
                }
            }

            if (destination is TypeDeclarationSyntax typeDeclaration)
            {
                if (method.IsConstructor())
                {
                    return(Cast <TDeclarationNode>(ConstructorGenerator.AddConstructorTo(
                                                       typeDeclaration, method, Workspace, options, availableIndices)));
                }

                if (method.IsDestructor())
                {
                    return(Cast <TDeclarationNode>(DestructorGenerator.AddDestructorTo(typeDeclaration, method, options, availableIndices)));
                }

                if (method.MethodKind == MethodKind.Conversion)
                {
                    return(Cast <TDeclarationNode>(ConversionGenerator.AddConversionTo(
                                                       typeDeclaration, method, Workspace, options, availableIndices)));
                }

                if (method.MethodKind == MethodKind.UserDefinedOperator)
                {
                    return(Cast <TDeclarationNode>(OperatorGenerator.AddOperatorTo(
                                                       typeDeclaration, method, Workspace, options, availableIndices)));
                }

                return(Cast <TDeclarationNode>(MethodGenerator.AddMethodTo(
                                                   typeDeclaration, method, Workspace, options, availableIndices)));
            }

            if (method.IsConstructor() ||
                method.IsDestructor())
            {
                return(destination);
            }

            if (destination is CompilationUnitSyntax compilationUnit)
            {
                return(Cast <TDeclarationNode>(
                           MethodGenerator.AddMethodTo(compilationUnit, method, Workspace, options, availableIndices)));
            }

            var ns = Cast <NamespaceDeclarationSyntax>(destination);

            return(Cast <TDeclarationNode>(
                       MethodGenerator.AddMethodTo(ns, method, Workspace, options, availableIndices)));
        }
Esempio n. 4
0
        protected override TDeclarationNode AddMethod <TDeclarationNode>(TDeclarationNode destination, IMethodSymbol method, CodeGenerationOptions options, IList <bool> availableIndices)
        {
            // https://github.com/dotnet/roslyn/issues/44425: Add handling for top level statements
            if (destination is GlobalStatementSyntax)
            {
                return(destination);
            }

            CheckDeclarationNode <TypeDeclarationSyntax, CompilationUnitSyntax, BaseNamespaceDeclarationSyntax>(destination);

            options = options.With(options: options.Options ?? Workspace.Options);

            // Synthesized methods for properties/events are not things we actually generate
            // declarations for.
            if (method.AssociatedSymbol is IEventSymbol)
            {
                return(destination);
            }
            // we will ignore the method if the associated property can be generated.

            if (method.AssociatedSymbol is IPropertySymbol property)
            {
                if (PropertyGenerator.CanBeGenerated(property))
                {
                    return(destination);
                }
            }

            if (destination is TypeDeclarationSyntax typeDeclaration)
            {
                if (method.IsConstructor())
                {
                    return(Cast <TDeclarationNode>(ConstructorGenerator.AddConstructorTo(
                                                       typeDeclaration, method, options, availableIndices)));
                }

                if (method.IsDestructor())
                {
                    return(Cast <TDeclarationNode>(DestructorGenerator.AddDestructorTo(typeDeclaration, method, options, availableIndices)));
                }

                if (method.MethodKind == MethodKind.Conversion)
                {
                    return(Cast <TDeclarationNode>(ConversionGenerator.AddConversionTo(
                                                       typeDeclaration, method, options, availableIndices)));
                }

                if (method.MethodKind == MethodKind.UserDefinedOperator)
                {
                    return(Cast <TDeclarationNode>(OperatorGenerator.AddOperatorTo(
                                                       typeDeclaration, method, options, availableIndices)));
                }

                return(Cast <TDeclarationNode>(MethodGenerator.AddMethodTo(
                                                   typeDeclaration, method, options, availableIndices)));
            }

            if (method.IsConstructor() ||
                method.IsDestructor())
            {
                return(destination);
            }

            if (destination is CompilationUnitSyntax compilationUnit)
            {
                return(Cast <TDeclarationNode>(
                           MethodGenerator.AddMethodTo(compilationUnit, method, options, availableIndices)));
            }

            var ns = Cast <BaseNamespaceDeclarationSyntax>(destination);

            return(Cast <TDeclarationNode>(
                       MethodGenerator.AddMethodTo(ns, method, options, availableIndices)));
        }