using System.Xml.Serialization; using Elsa.Http.Contracts; namespace Elsa.Http.Parsers; /// /// Reads application/xml and text/xml content type streams. /// public class XmlHttpContentParser : IHttpContentParser { /// public int Priority => 0; /// public bool GetSupportsContentType(string contentType) => contentType.Contains("xml", StringComparison.InvariantCultureIgnoreCase); /// public async Task ReadAsync(Stream content, Type? returnType, CancellationToken cancellationToken) { using var reader = new StreamReader(content, leaveOpen: true); var xml = await reader.ReadToEndAsync(); if (returnType == null || returnType == typeof(string)) return xml; var serializer = new XmlSerializer(returnType); return serializer.Deserialize(reader)!; } }