Example #1
0
            protected override async Task <IEnumerable <CodeActionOperation> > ComputeOperationsAsync(object options, CancellationToken cancellationToken)
            {
                var result = (PickMembersResult)options;

                if (result.IsCanceled)
                {
                    return(SpecializedCollections.EmptyEnumerable <CodeActionOperation>());
                }

                // If we presented the user any options, then persist whatever values
                // the user chose.  That way we'll keep that as the default for the
                // next time the user opens the dialog.
                var implementIEqutableOption = result.Options.FirstOrDefault(o => o.Id == ImplementIEquatableId);

                if (implementIEqutableOption != null)
                {
                    _implementIEqutableOptionValue = implementIEqutableOption.Value;
                }

                var generateOperatorsOption = result.Options.FirstOrDefault(o => o.Id == GenerateOperatorsId);

                if (generateOperatorsOption != null)
                {
                    _generateOperatorsOptionValue = generateOperatorsOption.Value;
                }

                var implementIEquatable = (implementIEqutableOption?.Value ?? false);
                var generatorOperators  = (generateOperatorsOption?.Value ?? false);

                var action = new GenerateEqualsAndGetHashCodeAction(
                    _document, _typeDeclaration, _containingType, result.Members, _fallbackOptions,
                    _generateEquals, _generateGetHashCode, implementIEquatable, generatorOperators);

                return(await action.GetOperationsAsync(cancellationToken).ConfigureAwait(false));
            }
Example #2
0
            protected override async Task <IEnumerable <CodeActionOperation> > ComputeOperationsAsync(object options, CancellationToken cancellationToken)
            {
                var result = (PickMembersResult)options;

                if (result.IsCanceled)
                {
                    return(ImmutableArray <CodeActionOperation> .Empty);
                }

                var generateOperatorsOption = result.Options.FirstOrDefault(o => o.Id == GenerateOperatorsId);

                if (generateOperatorsOption != null)
                {
                    // If we presented the 'Generate operators' option, then persist whatever value
                    // the user chose.  That way we'll keep that as the default for the next time
                    // the user opens the dialog.
                    var workspace = _document.Project.Solution.Workspace;
                    workspace.Options = workspace.Options.WithChangedOption(
                        GenerateEqualsAndGetHashCodeFromMembersOptions.GenerateOperators,
                        _document.Project.Language,
                        generateOperatorsOption.Value);
                }

                var generatorOperators = (generateOperatorsOption?.Value).GetValueOrDefault();
                var action             = new GenerateEqualsAndGetHashCodeAction(
                    _service, _document, _textSpan, _containingType, result.Members,
                    _generateEquals, _generateGetHashCode, generatorOperators);

                return(await action.GetOperationsAsync(cancellationToken).ConfigureAwait(false));
            }
            protected override async Task <IEnumerable <CodeActionOperation> > ComputeOperationsAsync(object options, CancellationToken cancellationToken)
            {
                var result = (PickMembersResult)options;

                if (result.IsCanceled)
                {
                    return(ImmutableArray <CodeActionOperation> .Empty);
                }

                var action = new GenerateEqualsAndGetHashCodeAction(
                    _service, _document, _textSpan, _containingType, result.Members, _generateEquals, _generateGetHashCode);

                return(await action.GetOperationsAsync(cancellationToken).ConfigureAwait(false));
            }
            protected override async Task <IEnumerable <CodeActionOperation> > ComputeOperationsAsync(object options, CancellationToken cancellationToken)
            {
                var result = (PickMembersResult)options;

                if (result.IsCanceled)
                {
                    return(SpecializedCollections.EmptyEnumerable <CodeActionOperation>());
                }

                // If we presented the user any options, then persist whatever values
                // the user chose to the global options.  That way we'll keep that as the default for the
                // next time the user opens the dialog.
                var implementIEqutableOption = result.Options.FirstOrDefault(o => o.Id == ImplementIEquatableId);
                var generateOperatorsOption  = result.Options.FirstOrDefault(o => o.Id == GenerateOperatorsId);

                if (generateOperatorsOption != null || implementIEqutableOption != null)
                {
                    var globalOptions = _document.Project.Solution.Services.GetRequiredService <ILegacyGlobalOptionsWorkspaceService>();

                    if (generateOperatorsOption != null)
                    {
                        globalOptions.SetGenerateEqualsAndGetHashCodeFromMembersGenerateOperators(_document.Project.Language, generateOperatorsOption.Value);
                    }

                    if (implementIEqutableOption != null)
                    {
                        globalOptions.SetGenerateEqualsAndGetHashCodeFromMembersImplementIEquatable(_document.Project.Language, implementIEqutableOption.Value);
                    }
                }

                var implementIEquatable = implementIEqutableOption?.Value ?? false;
                var generatorOperators  = generateOperatorsOption?.Value ?? false;

                var action = new GenerateEqualsAndGetHashCodeAction(
                    _document, _typeDeclaration, _containingType, result.Members, _fallbackOptions,
                    _generateEquals, _generateGetHashCode, implementIEquatable, generatorOperators);

                return(await action.GetOperationsAsync(cancellationToken).ConfigureAwait(false));
            }