Skip to content

Commit ebeedf3

Browse files
committed
Remove [NotificationXmlElement], switch to interface
1 parent 7eed078 commit ebeedf3

22 files changed

+95
-83
lines changed

Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveGroup.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements
88
{
9-
[NotificationXmlElement("group")]
10-
internal sealed class Element_AdaptiveGroup : IElement_TileBindingChild, IElement_ToastBindingChild, IElementWithDescendants
9+
internal sealed class Element_AdaptiveGroup : IElement_TileBindingChild, IElement_ToastBindingChild, IElementWithDescendants, INotificationXmlElement
1110
{
1211
public IList<Element_AdaptiveSubgroup> Children { get; private set; } = new List<Element_AdaptiveSubgroup>();
1312

@@ -25,5 +24,8 @@ public IEnumerable<object> Descendants()
2524
}
2625
}
2726
}
27+
28+
/// <inheritdoc/>
29+
string INotificationXmlElement.Name => "group";
2830
}
2931
}

Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements
66
{
7-
[NotificationXmlElement("image")]
8-
internal sealed class Element_AdaptiveImage : IElement_TileBindingChild, IElement_ToastBindingChild, IElement_AdaptiveSubgroupChild
7+
internal sealed class Element_AdaptiveImage : IElement_TileBindingChild, IElement_ToastBindingChild, IElement_AdaptiveSubgroupChild, INotificationXmlElement
98
{
109
internal const AdaptiveImagePlacement DEFAULT_PLACEMENT = AdaptiveImagePlacement.Inline;
1110
internal const AdaptiveImageCrop DEFAULT_CROP = AdaptiveImageCrop.Default;
@@ -67,5 +66,8 @@ public int? Overlay
6766

6867
[NotificationXmlAttribute("spritesheet-startingFrame")]
6968
public uint? SpriteSheetStartingFrame { get; set; }
69+
70+
/// <inheritdoc/>
71+
string INotificationXmlElement.Name => "image";
7072
}
7173
}

Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements
66
{
7-
[NotificationXmlElement("progress")]
8-
internal sealed class Element_AdaptiveProgressBar : IElement_ToastBindingChild
7+
internal sealed class Element_AdaptiveProgressBar : IElement_ToastBindingChild, INotificationXmlElement
98
{
109
[NotificationXmlAttribute("value")]
1110
public string Value { get; set; }
@@ -18,5 +17,8 @@ internal sealed class Element_AdaptiveProgressBar : IElement_ToastBindingChild
1817

1918
[NotificationXmlAttribute("status")]
2019
public string Status { get; set; }
20+
21+
/// <inheritdoc/>
22+
string INotificationXmlElement.Name => "progress";
2123
}
2224
}

Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements
99
{
10-
[NotificationXmlElement("subgroup")]
11-
internal sealed class Element_AdaptiveSubgroup : IElementWithDescendants
10+
internal sealed class Element_AdaptiveSubgroup : IElementWithDescendants, INotificationXmlElement
1211
{
1312
internal const AdaptiveSubgroupTextStacking DEFAULT_TEXT_STACKING = AdaptiveSubgroupTextStacking.Default;
1413

@@ -51,6 +50,9 @@ public IEnumerable<object> Descendants()
5150
yield return child;
5251
}
5352
}
53+
54+
/// <inheritdoc/>
55+
string INotificationXmlElement.Name => "subgroup";
5456
}
5557

5658
internal interface IElement_AdaptiveSubgroupChild

Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements
88
{
9-
[NotificationXmlElement("text")]
10-
internal sealed class Element_AdaptiveText : IElement_TileBindingChild, IElement_AdaptiveSubgroupChild, IElement_ToastBindingChild
9+
internal sealed class Element_AdaptiveText : IElement_TileBindingChild, IElement_AdaptiveSubgroupChild, IElement_ToastBindingChild, INotificationXmlElement
1110
{
1211
internal const AdaptiveTextStyle DEFAULT_STYLE = AdaptiveTextStyle.Default;
1312
internal const AdaptiveTextAlign DEFAULT_ALIGN = AdaptiveTextAlign.Default;
@@ -91,5 +90,8 @@ internal static void CheckMinLinesValue(int value)
9190

9291
[NotificationXmlAttribute("placement", DEFAULT_PLACEMENT)]
9392
public AdaptiveTextPlacement Placement { get; set; } = DEFAULT_PLACEMENT;
93+
94+
/// <inheritdoc/>
95+
string INotificationXmlElement.Name => "text";
9496
}
9597
}

Microsoft.Toolkit.Uwp.Notifications/Common/NotificationXmlElementAttribute.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace Microsoft.Toolkit.Uwp.Notifications;
6+
7+
/// <summary>
8+
/// An interface for a notification XML element.
9+
/// </summary>
10+
internal interface INotificationXmlElement
11+
{
12+
/// <summary>
13+
/// Gets the name of the current element.
14+
/// </summary>
15+
string Name { get; }
16+
}

Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ internal static class XmlWriterHelper
1818
{
1919
public static void Write(System.Xml.XmlWriter writer, object element)
2020
{
21-
NotificationXmlElementAttribute elAttr = GetElementAttribute(element.GetType());
22-
23-
// If it isn't an element attribute, don't write anything
24-
if (elAttr == null)
21+
// If it isn't an XML element, don't write anything
22+
if (element is not INotificationXmlElement xmlElement)
2523
{
2624
return;
2725
}
2826

29-
writer.WriteStartElement(elAttr.Name);
27+
writer.WriteStartElement(xmlElement.Name);
3028

3129
IEnumerable<PropertyInfo> properties = GetProperties(element.GetType());
3230

@@ -198,20 +196,6 @@ private static IEnumerable<PropertyInfo> GetProperties(Type type)
198196
#endif
199197
}
200198

201-
private static NotificationXmlElementAttribute GetElementAttribute(Type type)
202-
{
203-
return GetCustomAttributes(type).OfType<NotificationXmlElementAttribute>().FirstOrDefault();
204-
}
205-
206-
private static IEnumerable<Attribute> GetCustomAttributes(Type type)
207-
{
208-
#if NETFX_CORE
209-
return type.GetTypeInfo().GetCustomAttributes();
210-
#else
211-
return type.GetCustomAttributes(true).OfType<Attribute>();
212-
#endif
213-
}
214-
215199
private static IEnumerable<Attribute> GetCustomAttributes(PropertyInfo propertyInfo)
216200
{
217201
#if NETFX_CORE

Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_Tile.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
namespace Microsoft.Toolkit.Uwp.Notifications
66
{
7-
[NotificationXmlElement("tile")]
8-
internal sealed class Element_Tile : BaseElement
7+
internal sealed class Element_Tile : BaseElement, INotificationXmlElement
98
{
109
public Element_TileVisual Visual { get; set; }
10+
11+
/// <inheritdoc/>
12+
string INotificationXmlElement.Name => "tile";
1113
}
1214
}

Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
namespace Microsoft.Toolkit.Uwp.Notifications
99
{
10-
[NotificationXmlElement("binding")]
11-
internal sealed class Element_TileBinding : IElementWithDescendants
10+
internal sealed class Element_TileBinding : IElementWithDescendants, INotificationXmlElement
1211
{
1312
internal const TileBranding DEFAULT_BRANDING = TileBranding.Auto;
1413
internal const TileTextStacking DEFAULT_TEXT_STACKING = TileTextStacking.Top;
@@ -119,6 +118,9 @@ public IEnumerable<object> Descendants()
119118
}
120119
}
121120
}
121+
122+
/// <inheritdoc/>
123+
string INotificationXmlElement.Name => "binding";
122124
}
123125

124126
internal interface IElement_TileBindingChild

0 commit comments

Comments
 (0)