def add_constructor arg_name = "repo" # Create the constructor's object ctor = CodeConstructor.new ctor.Attributes = MemberAttributes.Public ctor.Parameters.Add(CodeParameterDeclarationExpression.new("IRepository", arg_name)) # Grab the references for both the parameter we just added and the field we created # earlier arg_ref = CodeArgumentReferenceExpression.new(arg_name) repo_ref = CodeFieldReferenceExpression.new repo_ref.FieldName = @repo_field_name # Creating the condition statement for the if/else that will wrap our assignment statement condition_statement = CodeSnippetExpression.new("#{arg_name} != null") # Create the statement that will be used when the condition statement is true assign_statement = CodeAssignStatement.new(repo_ref, arg_ref) ctor.Statements.Add(create_if_else_statement(condition_statement, assign_statement,@arg_null_exception_stmt)) @target_class.Members.Add(ctor) end