The situation is this. In Main, I call the following code:

new GeneratedCode.WordGen().CreatePackage(@"D:\Temp\Output.docx", foo, ZAKAZCHIK); 

In the WordGen class, the CreatePackage method is called, which calls the CreateParts method, in which the GenerateMainDocumentPart1Content is called. The question is how do I transfer the ZAKAZCHIK to the GenerateMainDocumentPart1Content method?

How to transfer to CreatePackage is understandable, but I do not need it. Directly necessary method from main is impossible for me.

  public void CreatePackage(string filePath, string foo, string ZAKAZCHIK) { using(WordprocessingDocument package = WordprocessingDocument.Create(filePath, WordprocessingDocumentType.Document)) { CreateParts(package); } } private void CreateParts(WordprocessingDocument document) { ExtendedFilePropertiesPart extendedFilePropertiesPart1 = document.AddNewPart<ExtendedFilePropertiesPart>("rId3"); GenerateExtendedFilePropertiesPart1Content(extendedFilePropertiesPart1); } } private void GenerateMainDocumentPart1Content(MainDocumentPart mainDocumentPart1) { 
  • Well, add to the CreateParts and GenerateMainDocumentPart1Content methods one more parameter string ZAKAZCHIK and pass. Or, which seems to me doubtful, make a class field, in CreatePackage assign it a value from ZAKAZCHIK , and in GenerateMainDocumentPart1Content take a value from it - Donil
  • 3
    For ZAKAZCHIK sake, customer , not ZAKAZCHIK ! - VladD

2 answers 2

I will offer this option:

Add the Customer property to the class

 public class WordGen { string Customer {private get; private set;} //ваш код } 

Then in the method

 public void CreatePackage(string filePath, string foo, string customer) { //можно добавить Customer=customer; //и дальше ваш код } 

(provided that private void GenerateMainDocumentPart1Content is a member of WordGen )

in the GenerateMainDocumentPart1Content property of the Customer will be available to you.

UPD . I believe that it would be more logical to use even a field, and not a property.

     public void CreatePackage(string filePath, string foo, string ZAKAZCHIK) { using(WordprocessingDocument package = WordprocessingDocument.Create(filePath, WordprocessingDocumentType.Document)) { CreateParts(package,ZAKAZCHIK); } } private void CreateParts(WordprocessingDocument document, string ZAKAZCHIK) { ExtendedFilePropertiesPart extendedFilePropertiesPart1 = document.AddNewPart<ExtendedFilePropertiesPart>("rId3"); GenerateExtendedFilePropertiesPart1Content(extendedFilePropertiesPart1,ZAKAZCHIK); } } private void GenerateMainDocumentPart1Content(MainDocumentPart mainDocumentPart1, string ZAKAZCHIK) { 
    • or define the ZAKAZCHIK parameter at the beginning of the class description public class Test1 {private string ZAKAZCHIK; public void CreatePackage (string filePath, string foo, string ZAKAZCHIK) {ZAKAZCHIK = ZAKAZCHIK; // some code} // somr method private void GenerateMainDocumentPart1Content (MainDocumentPart mainDocumentPart1) {vat t1 = this.ZAKAZCHIK; // some code}} - naguwal