forked from CommunityToolkit/WindowsCommunityToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseElement.cs
More file actions
56 lines (50 loc) · 1.74 KB
/
BaseElement.cs
File metadata and controls
56 lines (50 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.IO;
using System.Text;
#if WINDOWS_UAP
using Windows.Data.Xml.Dom;
#endif
namespace Microsoft.Toolkit.Uwp.Notifications
{
internal abstract class BaseElement
{
/// <summary>
/// Retrieves the notification XML content as a string.
/// </summary>
/// <returns>The notification XML content as a string.</returns>
public string GetContent()
{
using (MemoryStream stream = new MemoryStream())
{
using (System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(stream, new System.Xml.XmlWriterSettings()
{
Encoding = Encoding.UTF8, // Use UTF-8 encoding to save space (it defaults to UTF-16 which is 2x the size)
Indent = false,
NewLineOnAttributes = false
}))
{
XmlWriterHelper.Write(writer, this);
}
stream.Position = 0;
using (StreamReader reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
#if WINDOWS_UAP
/// <summary>
/// Retrieves the notification XML content as a WinRT XML document.
/// </summary>
/// <returns>The notification XML content as a WinRT XML document.</returns>
public XmlDocument GetXml()
{
XmlDocument xml = new XmlDocument();
xml.LoadXml(GetContent());
return xml;
}
#endif
}
}