Example #1
0
        public static Parties Convert(XElement xml)
        {
            if (xml == null) return null;

            var s = new XmlDeserializer();
            var parties = new Parties();

            foreach (var party in xml.Descendants("party"))
            {
                string partyType = String.Empty;

                var element = party.Element("type");
                if (element != null)
                    partyType = element.Value;

                if (String.IsNullOrEmpty(partyType))
                {
                    var attribute = party.Attribute("type");
                    if (attribute != null) partyType = attribute.Value;
                }

                if (String.IsNullOrEmpty(partyType)) continue;

                switch (partyType.ToLower())
                {
                    case "person":
                        var person = s.Deserialize<Person>(new RestResponse { Content = party.ToString() });

                        if (person != null)
                            parties.People.Add(person);

                        break;
                    case "company":
                        var company = s.Deserialize<Company>(new RestResponse { Content = party.ToString() });

                        if (company != null)
                            parties.Companies.Add(company);

                        break;
                }
            }

            return parties;
        }
Example #2
0
 protected internal void LoadParties(string xml)
 {
     Parties = PartyConverter.Convert(XDocument.Parse(xml).Descendants("parties").FirstOrDefault());
 }