private async Task <bool> TryInitializeAsync(
                TService service,
                SemanticDocument document,
                SyntaxNode node,
                CancellationToken cancellationToken)
            {
                if (service.IsConstructorInitializerGeneration(document, node, cancellationToken))
                {
                    if (!await TryInitializeConstructorInitializerGenerationAsync(service, document, node, cancellationToken).ConfigureAwait(false))
                    {
                        return(false);
                    }
                }
                else if (service.IsSimpleNameGeneration(document, node, cancellationToken))
                {
                    if (!await TryInitializeSimpleNameGenerationAsync(service, document, node, cancellationToken).ConfigureAwait(false))
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }

                if (!new CSharpCodeGenerationService(document.Project.Solution.Workspace).CanAddTo(this.TypeToGenerateIn, document.Project.Solution, cancellationToken))
                {
                    return(false);
                }

                this.ParameterTypes    = this.ParameterTypes ?? GetParameterTypes(service, document, cancellationToken);
                this.ParameterRefKinds = this.Arguments.Select(service.GetRefKind).ToList();

                return(!ClashesWithExistingConstructor(service, document, cancellationToken));
            }
            private async Task <bool> TryInitializeAsync(
                SyntaxNode node, CancellationToken cancellationToken)
            {
                if (_service.IsConstructorInitializerGeneration(_document, node, cancellationToken))
                {
                    if (!await TryInitializeConstructorInitializerGenerationAsync(node, cancellationToken).ConfigureAwait(false))
                    {
                        return(false);
                    }
                }
                else if (_service.IsSimpleNameGeneration(_document, node, cancellationToken))
                {
                    if (!await TryInitializeSimpleNameGenerationAsync(node, cancellationToken).ConfigureAwait(false))
                    {
                        return(false);
                    }
                }
                else if (_service.IsImplicitObjectCreation(_document, node, cancellationToken))
                {
                    if (!await TryInitializeImplicitObjectCreationAsync(node, cancellationToken).ConfigureAwait(false))
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }

                Contract.ThrowIfNull(TypeToGenerateIn);
                if (!CodeGenerator.CanAdd(_document.Project.Solution, TypeToGenerateIn, cancellationToken))
                {
                    return(false);
                }

                ParameterTypes     = ParameterTypes.IsDefault ? GetParameterTypes(cancellationToken) : ParameterTypes;
                _parameterRefKinds = _arguments.SelectAsArray(a => a.RefKind);

                if (ClashesWithExistingConstructor())
                {
                    return(false);
                }

                if (!TryInitializeDelegatedConstructor(cancellationToken))
                {
                    InitializeNonDelegatedConstructor(cancellationToken);
                }

                IsContainedInUnsafeType = _service.ContainingTypesOrSelfHasUnsafeKeyword(TypeToGenerateIn);

                return(true);
            }
Beispiel #3
0
            private async Task <bool> TryInitializeAsync(
                SyntaxNode node, CancellationToken cancellationToken)
            {
                if (_service.IsConstructorInitializerGeneration(_document, node, cancellationToken))
                {
                    if (!await TryInitializeConstructorInitializerGenerationAsync(node, cancellationToken).ConfigureAwait(false))
                    {
                        return(false);
                    }
                }
                else if (_service.IsSimpleNameGeneration(_document, node, cancellationToken))
                {
                    if (!await TryInitializeSimpleNameGenerationAsync(node, cancellationToken).ConfigureAwait(false))
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }

                if (!CodeGenerator.CanAdd(_document.Project.Solution, TypeToGenerateIn, cancellationToken))
                {
                    return(false);
                }

                ParameterTypes     = ParameterTypes.IsDefault ? GetParameterTypes(cancellationToken) : ParameterTypes;
                _parameterRefKinds = _arguments.Select(_service.GetRefKind).ToImmutableArray();

                if (ClashesWithExistingConstructor())
                {
                    return(false);
                }

                if (!TryInitializeDelegatedConstructor(cancellationToken))
                {
                    InitializeNonDelegatedConstructor(cancellationToken);
                }

                return(true);
            }
            private async Task <bool> TryInitializeAsync(
                TService service,
                SemanticDocument document,
                SyntaxNode node,
                CancellationToken cancellationToken)
            {
                if (service.IsConstructorInitializerGeneration(document, node, cancellationToken))
                {
                    if (!await TryInitializeConstructorInitializerGenerationAsync(service, document, node, cancellationToken).ConfigureAwait(false))
                    {
                        return(false);
                    }
                }
                else if (service.IsSimpleNameGeneration(document, node, cancellationToken))
                {
                    if (!await TryInitializeSimpleNameGenerationAsync(service, document, node, cancellationToken).ConfigureAwait(false))
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }

                if (!CodeGenerator.CanAdd(document.Project.Solution, TypeToGenerateIn, cancellationToken))
                {
                    return(false);
                }

                ParameterTypes = ParameterTypes.IsDefault
                    ? GetParameterTypes(service, document, cancellationToken)
                    : ParameterTypes;
                ParameterRefKinds ??= Arguments.Select(service.GetRefKind).ToList();

                return(!ClashesWithExistingConstructor(document));
            }