internal override void ReadXml(XmlTextReader reader) { while (reader.Read()) { if (reader.Name == "invoice_collection" && reader.NodeType == XmlNodeType.EndElement) { break; } if (reader.NodeType != XmlNodeType.Element) { continue; } switch (reader.Name) { case "charge_invoice": var invoice = new Invoice(); invoice.ReadXml(reader, "charge_invoice"); ChargeInvoice = invoice; break; case "credit_invoices": var invoices = new InvoiceList(); invoices.ReadXml(reader); CreditInvoices = invoices; break; } } }
/// <summary> /// If the given collection has any elements, writes the contents of the <paramref name="items"/> to the <see cref="T:System.Xml.XmlTextWriter"/> /// using each element's <see cref="Recurly.RecurlyEntity.WriteXml"/> implementation. If the collection needs to write an empty element for an empty collection, it will do so. /// </summary> /// <typeparam name="T">The type of each element of <paramref name="items"/>, derived from <see cref="Recurly.RecurlyEntity"/>.</typeparam> /// <param name="writer">The <see cref="T:System.Xml.XmlTextWriter"/> to write to.</param> /// <param name="collectionName">The value to use for the encompassing XML tag if the collection is written.</param> /// <param name="items">The collection to test and then write if it has any elements.</param> public static void WriteIfCollectionHasAny <T>(this XmlTextWriter writer, string collectionName, RecurlyList <T> items) where T : RecurlyEntity { if (!items.includeEmptyTag() && !items.HasAny()) { return; } WriteCollection(writer, collectionName, items); }
internal Invoice() { Adjustments = new AdjustmentList(); Transactions = new TransactionList(); }
internal override void ReadXml(XmlTextReader reader) { while (reader.Read()) { // End of invoice element, get out of here if (reader.Name == "invoice" && reader.NodeType == XmlNodeType.EndElement) { break; } if (reader.NodeType != XmlNodeType.Element) { continue; } switch (reader.Name) { case "account": var accountHref = reader.GetAttribute("href"); AccountCode = Uri.UnescapeDataString(accountHref.Substring(accountHref.LastIndexOf("/") + 1)); break; case "subscription": var subHref = reader.GetAttribute("href"); SubscriptionUuid = Uri.UnescapeDataString(subHref.Substring(subHref.LastIndexOf("/") + 1)); break; case "original_invoice": var originalInvoiceHref = reader.GetAttribute("href"); var invoiceNumber = Uri.UnescapeDataString(originalInvoiceHref.Substring(originalInvoiceHref.LastIndexOf("/") + 1)); OriginalInvoiceNumber = Convert.ToInt32(invoiceNumber); break; case "uuid": Uuid = reader.ReadElementContentAsString(); break; case "state": State = reader.ReadElementContentAsString().ParseAsEnum <InvoiceState>(); break; case "invoice_number": int invNumber; if (Int32.TryParse(reader.ReadElementContentAsString(), out invNumber)) { InvoiceNumber = invNumber; } break; case "po_number": PoNumber = reader.ReadElementContentAsString(); break; case "vat_number": VatNumber = reader.ReadElementContentAsString(); break; case "subtotal_in_cents": SubtotalInCents = reader.ReadElementContentAsInt(); break; case "tax_in_cents": TaxInCents = reader.ReadElementContentAsInt(); break; case "total_in_cents": TotalInCents = reader.ReadElementContentAsInt(); break; case "currency": Currency = reader.ReadElementContentAsString(); break; case "created_at": DateTime createdAt; if (DateTime.TryParse(reader.ReadElementContentAsString(), out createdAt)) { CreatedAt = createdAt; } break; case "closed_at": DateTime closedAt; if (DateTime.TryParse(reader.ReadElementContentAsString(), out closedAt)) { ClosedAt = closedAt; } break; case "tax_type": TaxType = reader.ReadElementContentAsString(); break; case "tax_rate": TaxRate = reader.ReadElementContentAsDecimal(); break; case "net_terms": NetTerms = reader.ReadElementContentAsInt(); break; case "collection_method": CollectionMethod = reader.ReadElementContentAsString(); break; case "line_items": // overrite existing value with the Recurly API response Adjustments = new AdjustmentList(); Adjustments.ReadXml(reader); break; case "transactions": // overrite existing value with the Recurly API response Transactions = new TransactionList(); Transactions.ReadXml(reader); break; case "address": Address = new Address(reader); break; } } }