internal clientinvoice ToNative() { return(new clientinvoice { debitinvoicenr = DebitInvoiceNr.GetValueOrDefault(), debitinvoicenrSpecified = DebitInvoiceNr.HasValue, foreignid = ForeignId ?? string.Empty, ponr = PoNr ?? string.Empty, clientref = new clientreference { id = ClientId }, clientinvoicetemplateref = ClientInvoiceTemplateId.HasValue ? new clientinvoicetemplatereference { id = ClientInvoiceTemplateId.Value } : null, yourreference = YourReference ?? string.Empty, ourreference = new userreference { id = OurReferenceUserId.GetValueOrDefault(0) }, // 0 = not set according to docs approver = new userreference { id = ApproverUserId.GetValueOrDefault(0) }, // 0 = not set according to docs invoicedate = InvoiceDate, invoiceaddress = InvoiceAddress != null?InvoiceAddress.ToNative() : new Address().ToNative(), invoiceemail = InvoiceEmail ?? string.Empty, deliverydate = DeliveryDate ?? default(DateTime), deliveryname = DeliveryName ?? string.Empty, deliverytype = DeliveryType ?? string.Empty, deliveryaddress = DeliveryAddress != null?DeliveryAddress.ToNative() : new Address().ToNative(), deliveryemail = DeliveryEmail ?? string.Empty, duedate = DueDate, period = Period?.ToNative(), currency = Currency ?? string.Empty, currencyrate = CurrencyRate.GetValueOrDefault(), currencyrateSpecified = CurrencyRate.HasValue, certified = IsCertified, notes = Notes ?? string.Empty, gln = Gln ?? string.Empty, vatnr = VatNr ?? string.Empty, countrycode = CountryCode ?? string.Empty, disabled = IsDisabled, automaticactionsdisabled = IsAutomaticActionsDisabled.GetValueOrDefault(), automaticactionsdisabledSpecified = IsAutomaticActionsDisabled.HasValue, automaticactionsmessage = AutomaticActionsMessage ?? string.Empty, fields = Fields?.Select(x => x.ToNative()).ToArray(), files = Files?.Select(x => x.ToNative()).ToArray(), rows = Rows?.Select(x => x.ToNative()).ToArray() }); }