C# Class MixinRefactoring.InjectConstructorImplementationStrategy

this method injects the mixin as parameter into the child class constructor. The logic works by the following rules: 1. Every constructor in the class will be extended 2. If a constructor does not have an initialization list with a constructor of the same class, the mixin field will be assigned in this constructors body. 3. If the constructor initializer has a constructor of the same class, the parameter will be delegated to this constructor. 4. If the constructor already has a parameter of the same type with the same name, do not add it again Example: public class Test { private Mixin _mixin; public Test(){} public Test(int i):this(){} } becomes: public class Test { private Mixin _mixin; public Test(Mixin mixin){_mixin = mixin;} public Test(int i,Mixin mixin=null):this(mixin){} } In that way, the mixin instance will always be initialized, no matter which constructor is called.
ファイルを表示 Open project: pgenfer/mixinSharp Class Usage Examples

Public Methods

Method Description
CreateNewConstructor ( string className ) : Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax
ExtendConstructorInitialization ( ConstructorInitializerSyntax oldConstructorInitializer ) : ConstructorInitializerSyntax

the constructor initializer will be extended so that it will accept the mixin as parameter. See rule 3 from above

ExtendExistingConstructor ( Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax oldConstructor ) : Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax

if the child class already has a constructor, a new parameter will be added to the constructor

InjectConstructorImplementationStrategy ( MixinReference mixin, Microsoft.CodeAnalysis.SemanticModel semanticModel, int positionInSourceFile ) : System.Collections.Generic

Private Methods

Method Description
CreateAssigmentStatementForConstructorBody ( string parameterName ) : Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionStatementSyntax
CreateConstructorParameterForMixin ( string parameterName ) : Microsoft.CodeAnalysis.CSharp.Syntax.ParameterSyntax

Method Details

CreateNewConstructor() public method

public CreateNewConstructor ( string className ) : Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax
className string
return Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax

ExtendConstructorInitialization() public method

the constructor initializer will be extended so that it will accept the mixin as parameter. See rule 3 from above
public ExtendConstructorInitialization ( ConstructorInitializerSyntax oldConstructorInitializer ) : ConstructorInitializerSyntax
oldConstructorInitializer ConstructorInitializerSyntax
return ConstructorInitializerSyntax

ExtendExistingConstructor() public method

if the child class already has a constructor, a new parameter will be added to the constructor
public ExtendExistingConstructor ( Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax oldConstructor ) : Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax
oldConstructor Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax constructor to which /// we are going to add the new parameter
return Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax

InjectConstructorImplementationStrategy() public method

public InjectConstructorImplementationStrategy ( MixinReference mixin, Microsoft.CodeAnalysis.SemanticModel semanticModel, int positionInSourceFile ) : System.Collections.Generic
mixin MixinReference
semanticModel Microsoft.CodeAnalysis.SemanticModel
positionInSourceFile int
return System.Collections.Generic