public static void SerializeChoice(Hl7.Fhir.Model.Choice value, IFhirWriter writer, bool summary) { writer.WriteStartComplexContent(); // Serialize element _id if (value.LocalIdElement != null) { writer.WritePrimitiveContents("_id", value.LocalIdElement, XmlSerializationHint.Attribute); } // Serialize element extension if (value.Extension != null && !summary && value.Extension.Count > 0) { writer.WriteStartArrayElement("extension"); foreach (var item in value.Extension) { writer.WriteStartArrayMember("extension"); ExtensionSerializer.SerializeExtension(item, writer, summary); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element code if (value.CodeElement != null) { writer.WriteStartElement("code"); CodeSerializer.SerializeCode(value.CodeElement, writer, summary); writer.WriteEndElement(); } // Serialize element option if (value.Option != null && value.Option.Count > 0) { writer.WriteStartArrayElement("option"); foreach (var item in value.Option) { writer.WriteStartArrayMember("option"); ChoiceSerializer.SerializeChoiceOptionComponent(item, writer, summary); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element isOrdered if (value.IsOrderedElement != null) { writer.WriteStartElement("isOrdered"); FhirBooleanSerializer.SerializeFhirBoolean(value.IsOrderedElement, writer, summary); writer.WriteEndElement(); } writer.WriteEndComplexContent(); }
/// <summary> /// Parse Choice /// </summary> public static Hl7.Fhir.Model.Choice ParseChoice(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Choice existingInstance = null) { Hl7.Fhir.Model.Choice result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Choice(); string currentElementName = reader.CurrentElementName; reader.EnterElement(); while (reader.HasMoreElements()) { var atName = reader.CurrentElementName; // Parse element extension if (atName == "extension") { result.Extension = new List <Hl7.Fhir.Model.Extension>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "extension")) { result.Extension.Add(ExtensionParser.ParseExtension(reader, errors)); } reader.LeaveArray(); } // Parse element _id else if (atName == "_id") { result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id))); } // Parse element code else if (atName == "code") { result.CodeElement = CodeParser.ParseCode(reader, errors); } // Parse element option else if (atName == "option") { result.Option = new List <Hl7.Fhir.Model.Choice.ChoiceOptionComponent>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "option")) { result.Option.Add(ChoiceParser.ParseChoiceOptionComponent(reader, errors)); } reader.LeaveArray(); } // Parse element isOrdered else if (atName == "isOrdered") { result.IsOrderedElement = FhirBooleanParser.ParseFhirBoolean(reader, errors); } else { errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader); reader.SkipSubElementsFor(currentElementName); result = null; } } reader.LeaveElement(); return(result); }