//=============== Write ================================================== public override System.Threading.Tasks.Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext) { return(System.Threading.Tasks.Task.Factory.StartNew(() => { XmlWriter writer = new XmlTextWriter(writeStream, new System.Text.UTF8Encoding(false)); if (type.IsAssignableFrom(typeof(Resource))) { Resource Resource = (Resource)value; var Summary = SummaryType.False; if (Resource is IAnnotated Annotated) { var SummaryTypeAnnotationList = Annotated.Annotations(typeof(SummaryType)); if (SummaryTypeAnnotationList.FirstOrDefault() is SummaryType AnnotationSummary) { Summary = AnnotationSummary; } } FhirXmlSerializer FhirXmlSerializer = new FhirXmlSerializer(); FhirXmlSerializer.Serialize(Resource, writer, Summary); //Now obsolete in FHRI .NET API //FhirSerializer.SerializeResource(Resource, writer, Summary); } writer.Flush(); return System.Threading.Tasks.Task.CompletedTask; })); }
//=============== Write ================================================== public override System.Threading.Tasks.Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext) { StreamWriter writer = new StreamWriter(writeStream); // This will use the BetterJsonWriter which handles precision correctly JsonWriter jsonwriter = SerializationUtil.CreateJsonTextWriter(writer); if (typeof(Resource).IsAssignableFrom(type)) { if (value != null) { Resource Resource = value as Resource; var Summary = SummaryType.False; if (Resource is IAnnotated Annotated) { var SummaryTypeAnnotationList = Annotated.Annotations(typeof(SummaryType)); if (SummaryTypeAnnotationList.FirstOrDefault() is SummaryType AnnotationSummary) { Summary = AnnotationSummary; } } FhirJsonSerializer FhirJsonSerializer = new FhirJsonSerializer(); FhirJsonSerializer.Serialize(Resource, jsonwriter, Summary); //Now obsolete in FHIR .NET API //FhirSerializer.SerializeResource(Resource, jsonwriter, Summary); } } writer.Flush(); return(System.Threading.Tasks.Task.CompletedTask); }