MixinRefactoring.AddFieldDeclarationForMixinCommand.InternalExecute C# (CSharp) Method

InternalExecute() protected method

protected InternalExecute ( ClassWithSourceCode childClass, Microsoft.CodeAnalysis.SemanticModel semantic, Settings settings = null ) : Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax
childClass ClassWithSourceCode
semantic Microsoft.CodeAnalysis.SemanticModel
settings Settings
return Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax
        protected override ClassDeclarationSyntax InternalExecute(
            ClassWithSourceCode childClass, 
            SemanticModel semantic, 
            Settings settings = null)
        {
            // create a field declaration and add it to the child class
            // check the following cases:
            // 1. if mixin type is a concrete type that has a parameterless constructor
            //    if injection setting is not set => init field with new instance of type
            // 2. if mixin is interface or does not have a parameterless constructor
            //    do nothing
            var positionOfClassInSourceFile = childClass.SourceCode.GetLocation().SourceSpan.Start;
            var typeSyntax = ParseTypeName(
                _mixin.Class.TypeSymbol.ReduceQualifiedTypeName(semantic,positionOfClassInSourceFile));
            var newFieldDeclaration =
                FieldDeclaration(
                    VariableDeclaration(typeSyntax)
                    .WithVariables(
                        SingletonSeparatedList(
                            VariableDeclarator(_mixin.Name))))
                .WithModifiers(TokenList(Token(SyntaxKind.PrivateKeyword)));

            var newClassDeclaration = childClass.SourceCode.AddMembers(newFieldDeclaration);

            return newClassDeclaration;
        }
    }