MixinRefactoring.IncludeMixinCommand.CanExecute C# (CSharp) Method

CanExecute() public method

public CanExecute ( ClassWithSourceCode childClass, Settings settings = null ) : bool
childClass ClassWithSourceCode
settings Settings
return bool
        public override bool CanExecute(ClassWithSourceCode childClass, Settings settings = null)
        {
            if (_mixin == null || childClass == null)
                return false;
            // do the mixin operation the first time
            if (_mixer == null)
            {
                _mixer = new Mixer();
                _mixer.IncludeMixinInChild(_mixin, childClass);
            }

            // command can be executed if we either have to forward members or extend a constructor
            return _mixer.MembersToImplement.Any();
        }

Usage Example

        public void ClassWithNativeFields_CanExecuteMixinCommand_CannotExecute()
        {
            WithSourceFiles(Files.Person);
            var person = CreateClass(nameof(PersonWithNativeTypes));
            var fieldDeclarations = person.SourceCode.DescendantNodes().OfType<FieldDeclarationSyntax>();

            var mixinFactory = new MixinReferenceFactory(Semantic);

            foreach (var fieldDeclaration in fieldDeclarations)
            {
                var mixin = mixinFactory.Create(fieldDeclaration);
                var mixinCommand = new IncludeMixinCommand(mixin);
                Assert.IsFalse(mixinCommand.CanExecute(person));
            }
        }