XDocument.LoadRootElementAsync

This commit is contained in:
ClemensFischer 2025-09-19 11:53:25 +02:00
parent fedf5eba12
commit cd40a627ce
6 changed files with 53 additions and 42 deletions

View file

@ -0,0 +1,19 @@
using System.IO;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace MapControl
{
internal static class XDocument
{
public static async Task<XElement> LoadRootElementAsync(Stream stream)
{
#if NETFRAMEWORK
var document = await Task.Run(() => System.Xml.Linq.XDocument.Load(stream, LoadOptions.None));
#else
var document = await System.Xml.Linq.XDocument.LoadAsync(stream, LoadOptions.None, System.Threading.CancellationToken.None);
#endif
return document.Root;
}
}
}