public TaxYearDefinition(int year, string folderPath) { TaxComputationWorksheet taxComputationWorksheet = null; PdfInfo pdfInfo = null; var forms = new Dictionary <string, FormDefinition>(); foreach (var path in Directory.GetFiles(folderPath, "*.xml")) { try { var doc = XDocument.Load(path, LoadOptions.SetLineInfo); switch (doc.Root.Name.LocalName) { case "Form": var form = new FormDefinition(Path.GetFileNameWithoutExtension(path), doc); forms.Add(form.Name, form); break; case "TaxComputationWorksheet": if (taxComputationWorksheet is not null) { throw new Exception("Duplicate TaxComputationWorksheet"); } taxComputationWorksheet = new TaxComputationWorksheet(doc); break; case "PdfInfo": if (pdfInfo is not null) { throw new Exception("Duplicate PdfInfo"); } pdfInfo = new PdfInfo(folderPath, doc); break; default: throw new FileLoadException(doc.Root, "Unexpected document type: " + doc.Root.Name); } } catch (Exception ex) { throw new FileLoadException("Failed to load from " + path, ex); } } this.Year = year; this.Forms = new(forms); this.Rates = new TaxRates(taxComputationWorksheet); this.PdfInfo = pdfInfo; TypeCheck(); }
public FormInstances(FormDefinition def) { this.Definition = def ?? throw new ArgumentNullException(nameof(def)); this.Forms = new List <FormInstance>(); }