Пример #1
0
        private IEnumerable <CodeAction> GetActions(Document document, State state)
        {
            if (state == null)
            {
                yield break;
            }

            if (state.MembersWithoutExplicitOrImplicitImplementationWhichCanBeImplicitlyImplemented.Length > 0)
            {
                yield return(ImplementInterfaceCodeAction.CreateImplementCodeAction(this, document, state));

                if (ShouldImplementDisposePattern(state, explicitly: false))
                {
                    yield return(ImplementInterfaceWithDisposePatternCodeAction.CreateImplementWithDisposePatternCodeAction(this, document, state));
                }

                var delegatableMembers = GetDelegatableMembers(state);
                foreach (var member in delegatableMembers)
                {
                    yield return(ImplementInterfaceCodeAction.CreateImplementThroughMemberCodeAction(this, document, state, member));
                }

                if (state.ClassOrStructType.IsAbstract)
                {
                    yield return(ImplementInterfaceCodeAction.CreateImplementAbstractlyCodeAction(this, document, state));
                }
            }

            if (state.MembersWithoutExplicitImplementation.Length > 0)
            {
                yield return(ImplementInterfaceCodeAction.CreateImplementExplicitlyCodeAction(this, document, state));

                if (ShouldImplementDisposePattern(state, explicitly: true))
                {
                    yield return(ImplementInterfaceWithDisposePatternCodeAction.CreateImplementExplicitlyWithDisposePatternCodeAction(this, document, state));
                }
            }

            if (AnyImplementedImplicitly(state))
            {
                yield return(ImplementInterfaceCodeAction.CreateImplementRemainingExplicitlyCodeAction(this, document, state));
            }
        }
Пример #2
0
        private IEnumerable <CodeAction> GetActions(Document document, State state)
        {
            if (state == null)
            {
                yield break;
            }

            if (state.UnimplementedMembers != null && state.UnimplementedMembers.Count > 0)
            {
                yield return(ImplementInterfaceCodeAction.CreateImplementCodeAction(this, document, state));

                if (ShouldImplementDisposePattern(document, state, explicitly: false))
                {
                    yield return(ImplementInterfaceWithDisposePatternCodeAction.CreateImplementWithDisposePatternCodeAction(this, document, state));
                }

                var delegatableMembers = GetDelegatableMembers(state);
                foreach (var member in delegatableMembers)
                {
                    yield return(ImplementInterfaceCodeAction.CreateImplementThroughMemberCodeAction(this, document, state, member));
                }

                if (state.ClassOrStructType.IsAbstract)
                {
                    yield return(ImplementInterfaceCodeAction.CreateImplementAbstractlyCodeAction(this, document, state));
                }
            }

            if (state.UnimplementedExplicitMembers != null && state.UnimplementedExplicitMembers.Count > 0)
            {
                yield return(ImplementInterfaceCodeAction.CreateImplementExplicitlyCodeAction(this, document, state));

                if (ShouldImplementDisposePattern(document, state, explicitly: true))
                {
                    yield return(ImplementInterfaceWithDisposePatternCodeAction.CreateImplementExplicitlyWithDisposePatternCodeAction(this, document, state));
                }
            }
        }
        private IEnumerable <CodeAction> GetActions(Document document, ImplementTypeOptions options, State state)
        {
            if (state == null)
            {
                yield break;
            }

            if (state.MembersWithoutExplicitOrImplicitImplementationWhichCanBeImplicitlyImplemented.Length > 0)
            {
                var totalMemberCount        = 0;
                var inaccessibleMemberCount = 0;

                foreach (var(_, members) in state.MembersWithoutExplicitOrImplicitImplementationWhichCanBeImplicitlyImplemented)
                {
                    foreach (var member in members)
                    {
                        totalMemberCount++;

                        if (AccessibilityHelper.IsLessAccessibleThan(member, state.ClassOrStructType))
                        {
                            inaccessibleMemberCount++;
                        }
                    }
                }

                // If all members to implement are inaccessible, then "Implement interface" codeaction
                // will be the same as "Implement interface explicitly", so there is no point in having both of them
                if (totalMemberCount != inaccessibleMemberCount)
                {
                    yield return(ImplementInterfaceCodeAction.CreateImplementCodeAction(this, document, options, state));
                }

                if (ShouldImplementDisposePattern(state, explicitly: false))
                {
                    yield return(ImplementInterfaceWithDisposePatternCodeAction.CreateImplementWithDisposePatternCodeAction(this, document, options, state));
                }

                var delegatableMembers = GetDelegatableMembers(state);
                foreach (var member in delegatableMembers)
                {
                    yield return(ImplementInterfaceCodeAction.CreateImplementThroughMemberCodeAction(this, document, options, state, member));
                }

                if (state.ClassOrStructType.IsAbstract)
                {
                    yield return(ImplementInterfaceCodeAction.CreateImplementAbstractlyCodeAction(this, document, options, state));
                }
            }

            if (state.MembersWithoutExplicitImplementation.Length > 0)
            {
                yield return(ImplementInterfaceCodeAction.CreateImplementExplicitlyCodeAction(this, document, options, state));

                if (ShouldImplementDisposePattern(state, explicitly: true))
                {
                    yield return(ImplementInterfaceWithDisposePatternCodeAction.CreateImplementExplicitlyWithDisposePatternCodeAction(this, document, options, state));
                }
            }

            if (AnyImplementedImplicitly(state))
            {
                yield return(ImplementInterfaceCodeAction.CreateImplementRemainingExplicitlyCodeAction(this, document, options, state));
            }
        }