From ebeedf3308cc98674551849ba122a6716f0453ea Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 10 May 2022 17:06:49 +0200 Subject: [PATCH 01/10] Remove [NotificationXmlElement], switch to interface --- .../Elements/Element_AdaptiveGroup.cs | 6 +++-- .../Elements/Element_AdaptiveImage.cs | 6 +++-- .../Elements/Element_AdaptiveProgressBar.cs | 6 +++-- .../Elements/Element_AdaptiveSubgroup.cs | 6 +++-- .../Adaptive/Elements/Element_AdaptiveText.cs | 6 +++-- .../Common/NotificationXmlElementAttribute.cs | 26 ------------------- .../Serialization/INotificationXmlElement.cs | 16 ++++++++++++ .../Common/XmlWriterHelper.cs | 22 +++------------- .../Tiles/Elements/Element_Tile.cs | 6 +++-- .../Tiles/Elements/Element_TileBinding.cs | 6 +++-- .../Tiles/Elements/Element_TileVisual.cs | 6 +++-- .../Toasts/Elements/Element_Toast.cs | 6 +++-- .../Toasts/Elements/Element_ToastAction.cs | 6 +++-- .../Toasts/Elements/Element_ToastActions.cs | 6 +++-- .../Toasts/Elements/Element_ToastAudio.cs | 6 +++-- .../Toasts/Elements/Element_ToastBinding.cs | 6 +++-- .../Toasts/Elements/Element_ToastHeader.cs | 6 +++-- .../Toasts/Elements/Element_ToastImage.cs | 6 +++-- .../Toasts/Elements/Element_ToastInput.cs | 6 +++-- .../Toasts/Elements/Element_ToastSelection.cs | 6 +++-- .../Toasts/Elements/Element_ToastText.cs | 6 +++-- .../Toasts/Elements/Element_ToastVisual.cs | 6 +++-- 22 files changed, 95 insertions(+), 83 deletions(-) delete mode 100644 Microsoft.Toolkit.Uwp.Notifications/Common/NotificationXmlElementAttribute.cs create mode 100644 Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/INotificationXmlElement.cs diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveGroup.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveGroup.cs index dbb0d52753e..aae9d5dffd3 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveGroup.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveGroup.cs @@ -6,8 +6,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { - [NotificationXmlElement("group")] - internal sealed class Element_AdaptiveGroup : IElement_TileBindingChild, IElement_ToastBindingChild, IElementWithDescendants + internal sealed class Element_AdaptiveGroup : IElement_TileBindingChild, IElement_ToastBindingChild, IElementWithDescendants, INotificationXmlElement { public IList Children { get; private set; } = new List(); @@ -25,5 +24,8 @@ public IEnumerable Descendants() } } } + + /// + string INotificationXmlElement.Name => "group"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs index 8cf0b92b62b..74d9b7369df 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs @@ -4,8 +4,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { - [NotificationXmlElement("image")] - internal sealed class Element_AdaptiveImage : IElement_TileBindingChild, IElement_ToastBindingChild, IElement_AdaptiveSubgroupChild + internal sealed class Element_AdaptiveImage : IElement_TileBindingChild, IElement_ToastBindingChild, IElement_AdaptiveSubgroupChild, INotificationXmlElement { internal const AdaptiveImagePlacement DEFAULT_PLACEMENT = AdaptiveImagePlacement.Inline; internal const AdaptiveImageCrop DEFAULT_CROP = AdaptiveImageCrop.Default; @@ -67,5 +66,8 @@ public int? Overlay [NotificationXmlAttribute("spritesheet-startingFrame")] public uint? SpriteSheetStartingFrame { get; set; } + + /// + string INotificationXmlElement.Name => "image"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs index 17fd0001ab6..c2884ced9cc 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs @@ -4,8 +4,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { - [NotificationXmlElement("progress")] - internal sealed class Element_AdaptiveProgressBar : IElement_ToastBindingChild + internal sealed class Element_AdaptiveProgressBar : IElement_ToastBindingChild, INotificationXmlElement { [NotificationXmlAttribute("value")] public string Value { get; set; } @@ -18,5 +17,8 @@ internal sealed class Element_AdaptiveProgressBar : IElement_ToastBindingChild [NotificationXmlAttribute("status")] public string Status { get; set; } + + /// + string INotificationXmlElement.Name => "progress"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs index acfd9eedb3b..d4e68bc3585 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs @@ -7,8 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { - [NotificationXmlElement("subgroup")] - internal sealed class Element_AdaptiveSubgroup : IElementWithDescendants + internal sealed class Element_AdaptiveSubgroup : IElementWithDescendants, INotificationXmlElement { internal const AdaptiveSubgroupTextStacking DEFAULT_TEXT_STACKING = AdaptiveSubgroupTextStacking.Default; @@ -51,6 +50,9 @@ public IEnumerable Descendants() yield return child; } } + + /// + string INotificationXmlElement.Name => "subgroup"; } internal interface IElement_AdaptiveSubgroupChild diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs index 7641d962838..0a387f7c9ad 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs @@ -6,8 +6,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { - [NotificationXmlElement("text")] - internal sealed class Element_AdaptiveText : IElement_TileBindingChild, IElement_AdaptiveSubgroupChild, IElement_ToastBindingChild + internal sealed class Element_AdaptiveText : IElement_TileBindingChild, IElement_AdaptiveSubgroupChild, IElement_ToastBindingChild, INotificationXmlElement { internal const AdaptiveTextStyle DEFAULT_STYLE = AdaptiveTextStyle.Default; internal const AdaptiveTextAlign DEFAULT_ALIGN = AdaptiveTextAlign.Default; @@ -91,5 +90,8 @@ internal static void CheckMinLinesValue(int value) [NotificationXmlAttribute("placement", DEFAULT_PLACEMENT)] public AdaptiveTextPlacement Placement { get; set; } = DEFAULT_PLACEMENT; + + /// + string INotificationXmlElement.Name => "text"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/NotificationXmlElementAttribute.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/NotificationXmlElementAttribute.cs deleted file mode 100644 index 7b7018739d9..00000000000 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/NotificationXmlElementAttribute.cs +++ /dev/null @@ -1,26 +0,0 @@ -// 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; -#if WINDOWS_UWP - -#endif - -namespace Microsoft.Toolkit.Uwp.Notifications -{ - internal sealed class NotificationXmlElementAttribute : Attribute - { - public string Name { get; private set; } - - public NotificationXmlElementAttribute(string name) - { - if (string.IsNullOrWhiteSpace(name)) - { - throw new ArgumentNullException("name cannot be null or whitespace"); - } - - Name = name; - } - } -} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/INotificationXmlElement.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/INotificationXmlElement.cs new file mode 100644 index 00000000000..f23a04815cf --- /dev/null +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/INotificationXmlElement.cs @@ -0,0 +1,16 @@ +// 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. + +namespace Microsoft.Toolkit.Uwp.Notifications; + +/// +/// An interface for a notification XML element. +/// +internal interface INotificationXmlElement +{ + /// + /// Gets the name of the current element. + /// + string Name { get; } +} diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs index 2318b4d819e..b26ebaee7e1 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs @@ -18,15 +18,13 @@ internal static class XmlWriterHelper { public static void Write(System.Xml.XmlWriter writer, object element) { - NotificationXmlElementAttribute elAttr = GetElementAttribute(element.GetType()); - - // If it isn't an element attribute, don't write anything - if (elAttr == null) + // If it isn't an XML element, don't write anything + if (element is not INotificationXmlElement xmlElement) { return; } - writer.WriteStartElement(elAttr.Name); + writer.WriteStartElement(xmlElement.Name); IEnumerable properties = GetProperties(element.GetType()); @@ -198,20 +196,6 @@ private static IEnumerable GetProperties(Type type) #endif } - private static NotificationXmlElementAttribute GetElementAttribute(Type type) - { - return GetCustomAttributes(type).OfType().FirstOrDefault(); - } - - private static IEnumerable GetCustomAttributes(Type type) - { -#if NETFX_CORE - return type.GetTypeInfo().GetCustomAttributes(); -#else - return type.GetCustomAttributes(true).OfType(); -#endif - } - private static IEnumerable GetCustomAttributes(PropertyInfo propertyInfo) { #if NETFX_CORE diff --git a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_Tile.cs b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_Tile.cs index 636c4369279..ff34e1c8d8e 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_Tile.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_Tile.cs @@ -4,9 +4,11 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("tile")] - internal sealed class Element_Tile : BaseElement + internal sealed class Element_Tile : BaseElement, INotificationXmlElement { public Element_TileVisual Visual { get; set; } + + /// + string INotificationXmlElement.Name => "tile"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs index 8dfe545f273..fbf255ef314 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs @@ -7,8 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("binding")] - internal sealed class Element_TileBinding : IElementWithDescendants + internal sealed class Element_TileBinding : IElementWithDescendants, INotificationXmlElement { internal const TileBranding DEFAULT_BRANDING = TileBranding.Auto; internal const TileTextStacking DEFAULT_TEXT_STACKING = TileTextStacking.Top; @@ -119,6 +118,9 @@ public IEnumerable Descendants() } } } + + /// + string INotificationXmlElement.Name => "binding"; } internal interface IElement_TileBindingChild diff --git a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs index 1d22c1cc5a1..d22021cf198 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs @@ -7,8 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("visual")] - internal sealed class Element_TileVisual + internal sealed class Element_TileVisual : INotificationXmlElement { internal const TileBranding DEFAULT_BRANDING = TileBranding.Auto; internal const bool DEFAULT_ADD_IMAGE_QUERY = false; @@ -35,5 +34,8 @@ internal sealed class Element_TileVisual public string Arguments { get; set; } public IList Bindings { get; private set; } = new List(); + + /// + string INotificationXmlElement.Name => "visual"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs index 3db2c757839..63a7676be3d 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs @@ -7,8 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("toast")] - internal sealed class Element_Toast : BaseElement, IElement_ToastActivatable, IElement_AdditionalProperties + internal sealed class Element_Toast : BaseElement, IElement_ToastActivatable, IElement_AdditionalProperties, INotificationXmlElement { internal const ToastScenario DEFAULT_SCENARIO = ToastScenario.Default; internal const Element_ToastActivationType DEFAULT_ACTIVATION_TYPE = Element_ToastActivationType.Foreground; @@ -82,6 +81,9 @@ public static Element_ToastActivationType ConvertActivationType(ToastActivationT throw new NotImplementedException(); } } + + /// + string INotificationXmlElement.Name => "toast"; } /// diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAction.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAction.cs index cd31e550866..61872283e13 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAction.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAction.cs @@ -4,8 +4,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("action")] - internal sealed class Element_ToastAction : IElement_ToastActionsChild, IElement_ToastActivatable + internal sealed class Element_ToastAction : IElement_ToastActionsChild, IElement_ToastActivatable, INotificationXmlElement { internal const Element_ToastActivationType DEFAULT_ACTIVATION_TYPE = Element_ToastActivationType.Foreground; internal const ToastAfterActivationBehavior DEFAULT_AFTER_ACTIVATION_BEHAVIOR = ToastAfterActivationBehavior.Default; @@ -49,6 +48,9 @@ internal sealed class Element_ToastAction : IElement_ToastActionsChild, IElement [NotificationXmlAttribute("hint-actionId")] public string HintActionId { get; set; } + + /// + string INotificationXmlElement.Name => "action"; } internal enum Element_ToastActionPlacement diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs index fd8e1e77771..f37d22cf0a2 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs @@ -6,8 +6,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("actions")] - internal sealed class Element_ToastActions + internal sealed class Element_ToastActions : INotificationXmlElement { internal const ToastSystemCommand DEFAULT_SYSTEM_COMMAND = ToastSystemCommand.None; @@ -15,6 +14,9 @@ internal sealed class Element_ToastActions public ToastSystemCommand SystemCommands { get; set; } = ToastSystemCommand.None; public IList Children { get; private set; } = new List(); + + /// + string INotificationXmlElement.Name => "actions"; } internal interface IElement_ToastActionsChild diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAudio.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAudio.cs index 88adb5317c8..f6f482d40d2 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAudio.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAudio.cs @@ -6,8 +6,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("audio")] - internal sealed class Element_ToastAudio + internal sealed class Element_ToastAudio : INotificationXmlElement { internal const bool DEFAULT_LOOP = false; internal const bool DEFAULT_SILENT = false; @@ -26,5 +25,8 @@ internal sealed class Element_ToastAudio /// [NotificationXmlAttribute("silent", DEFAULT_SILENT)] public bool Silent { get; set; } = DEFAULT_SILENT; + + /// + string INotificationXmlElement.Name => "audio"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs index b4dd8d784b9..857daa6c378 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs @@ -7,8 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("binding")] - internal sealed class Element_ToastBinding + internal sealed class Element_ToastBinding : INotificationXmlElement { public Element_ToastBinding(ToastTemplateType template) { @@ -46,6 +45,9 @@ public Element_ToastBinding(ToastTemplateType template) public string ExperienceType { get; set; } public IList Children { get; private set; } = new List(); + + /// + string INotificationXmlElement.Name => "binding"; } internal interface IElement_ToastBindingChild diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastHeader.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastHeader.cs index a5ebd37240c..36901dbc999 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastHeader.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastHeader.cs @@ -6,8 +6,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("header")] - internal sealed class Element_ToastHeader : IElement_ToastActivatable + internal sealed class Element_ToastHeader : IElement_ToastActivatable, INotificationXmlElement { [NotificationXmlAttribute("id")] public string Id { get; set; } @@ -40,5 +39,8 @@ public ToastAfterActivationBehavior AfterActivationBehavior } } } + + /// + string INotificationXmlElement.Name => "header"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastImage.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastImage.cs index 7df0eb94692..0764d3062d5 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastImage.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastImage.cs @@ -4,8 +4,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("image")] - internal sealed class Element_ToastImage : IElement_ToastBindingChild + internal sealed class Element_ToastImage : IElement_ToastBindingChild, INotificationXmlElement { internal const ToastImagePlacement DEFAULT_PLACEMENT = ToastImagePlacement.Inline; internal const bool DEFAULT_ADD_IMAGE_QUERY = false; @@ -25,6 +24,9 @@ internal sealed class Element_ToastImage : IElement_ToastBindingChild [NotificationXmlAttribute("hint-crop", DEFAULT_CROP)] public ToastImageCrop Crop { get; set; } = DEFAULT_CROP; + + /// + string INotificationXmlElement.Name => "image"; } /// diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs index 6b4c9527d34..64ec4b3cee8 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs @@ -6,8 +6,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("input")] - internal sealed class Element_ToastInput : IElement_ToastActionsChild + internal sealed class Element_ToastInput : IElement_ToastActionsChild, INotificationXmlElement { /// /// Gets or sets the required attributes for developers to retrieve user inputs once the app is activated (in the foreground or background). @@ -37,6 +36,9 @@ internal sealed class Element_ToastInput : IElement_ToastActionsChild public string DefaultInput { get; set; } public IList Children { get; private set; } = new List(); + + /// + string INotificationXmlElement.Name => "input"; } internal interface IElement_ToastInputChild diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastSelection.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastSelection.cs index 2b67b41194e..985f75314c1 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastSelection.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastSelection.cs @@ -4,8 +4,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("selection")] - internal sealed class Element_ToastSelection : IElement_ToastInputChild + internal sealed class Element_ToastSelection : IElement_ToastInputChild, INotificationXmlElement { /// /// Gets or sets the id attribute for apps to retrieve back the user selected input after the app is activated. Required @@ -18,5 +17,8 @@ internal sealed class Element_ToastSelection : IElement_ToastInputChild /// [NotificationXmlAttribute("content")] public string Content { get; set; } + + /// + string INotificationXmlElement.Name => "selection"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs index 22754eaf0bf..8888183d5c2 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs @@ -4,8 +4,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("text")] - internal sealed class Element_ToastText : IElement_ToastBindingChild + internal sealed class Element_ToastText : IElement_ToastBindingChild, INotificationXmlElement { internal const ToastTextPlacement DEFAULT_PLACEMENT = ToastTextPlacement.Inline; @@ -17,6 +16,9 @@ internal sealed class Element_ToastText : IElement_ToastBindingChild [NotificationXmlAttribute("placement", DEFAULT_PLACEMENT)] public ToastTextPlacement Placement { get; set; } = DEFAULT_PLACEMENT; + + /// + string INotificationXmlElement.Name => "text"; } internal enum ToastTextPlacement diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs index 736f2d7ac22..ea9846a0f97 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs @@ -7,8 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("visual")] - internal sealed class Element_ToastVisual + internal sealed class Element_ToastVisual : INotificationXmlElement { internal const bool DEFAULT_ADD_IMAGE_QUERY = false; @@ -25,5 +24,8 @@ internal sealed class Element_ToastVisual public int? Version { get; set; } public IList Bindings { get; private set; } = new List(); + + /// + string INotificationXmlElement.Name => "visual"; } } \ No newline at end of file From 35dacb4dcb794e2a012630bd358225afb666ef0d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 10 May 2022 18:17:25 +0200 Subject: [PATCH 02/10] Rename INotificationXmlElement to IHaveXmlName --- .../Adaptive/Elements/Element_AdaptiveGroup.cs | 4 ++-- .../Adaptive/Elements/Element_AdaptiveImage.cs | 4 ++-- .../Adaptive/Elements/Element_AdaptiveProgressBar.cs | 4 ++-- .../Adaptive/Elements/Element_AdaptiveSubgroup.cs | 4 ++-- .../Adaptive/Elements/Element_AdaptiveText.cs | 4 ++-- .../{INotificationXmlElement.cs => IHaveXmlName.cs} | 4 ++-- Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs | 2 +- .../Tiles/Elements/Element_Tile.cs | 4 ++-- .../Tiles/Elements/Element_TileBinding.cs | 4 ++-- .../Tiles/Elements/Element_TileVisual.cs | 4 ++-- .../Toasts/Elements/Element_Toast.cs | 4 ++-- .../Toasts/Elements/Element_ToastAction.cs | 4 ++-- .../Toasts/Elements/Element_ToastActions.cs | 4 ++-- .../Toasts/Elements/Element_ToastAudio.cs | 4 ++-- .../Toasts/Elements/Element_ToastBinding.cs | 4 ++-- .../Toasts/Elements/Element_ToastHeader.cs | 4 ++-- .../Toasts/Elements/Element_ToastImage.cs | 4 ++-- .../Toasts/Elements/Element_ToastInput.cs | 4 ++-- .../Toasts/Elements/Element_ToastSelection.cs | 4 ++-- .../Toasts/Elements/Element_ToastText.cs | 4 ++-- .../Toasts/Elements/Element_ToastVisual.cs | 4 ++-- 21 files changed, 41 insertions(+), 41 deletions(-) rename Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/{INotificationXmlElement.cs => IHaveXmlName.cs} (80%) diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveGroup.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveGroup.cs index aae9d5dffd3..ebe2905de19 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveGroup.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveGroup.cs @@ -6,7 +6,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { - internal sealed class Element_AdaptiveGroup : IElement_TileBindingChild, IElement_ToastBindingChild, IElementWithDescendants, INotificationXmlElement + internal sealed class Element_AdaptiveGroup : IElement_TileBindingChild, IElement_ToastBindingChild, IElementWithDescendants, IHaveXmlName { public IList Children { get; private set; } = new List(); @@ -26,6 +26,6 @@ public IEnumerable Descendants() } /// - string INotificationXmlElement.Name => "group"; + string IHaveXmlName.Name => "group"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs index 74d9b7369df..7787e5de064 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs @@ -4,7 +4,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { - internal sealed class Element_AdaptiveImage : IElement_TileBindingChild, IElement_ToastBindingChild, IElement_AdaptiveSubgroupChild, INotificationXmlElement + internal sealed class Element_AdaptiveImage : IElement_TileBindingChild, IElement_ToastBindingChild, IElement_AdaptiveSubgroupChild, IHaveXmlName { internal const AdaptiveImagePlacement DEFAULT_PLACEMENT = AdaptiveImagePlacement.Inline; internal const AdaptiveImageCrop DEFAULT_CROP = AdaptiveImageCrop.Default; @@ -68,6 +68,6 @@ public int? Overlay public uint? SpriteSheetStartingFrame { get; set; } /// - string INotificationXmlElement.Name => "image"; + string IHaveXmlName.Name => "image"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs index c2884ced9cc..9ddb4400129 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs @@ -4,7 +4,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { - internal sealed class Element_AdaptiveProgressBar : IElement_ToastBindingChild, INotificationXmlElement + internal sealed class Element_AdaptiveProgressBar : IElement_ToastBindingChild, IHaveXmlName { [NotificationXmlAttribute("value")] public string Value { get; set; } @@ -19,6 +19,6 @@ internal sealed class Element_AdaptiveProgressBar : IElement_ToastBindingChild, public string Status { get; set; } /// - string INotificationXmlElement.Name => "progress"; + string IHaveXmlName.Name => "progress"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs index d4e68bc3585..ee2c8b9152d 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { - internal sealed class Element_AdaptiveSubgroup : IElementWithDescendants, INotificationXmlElement + internal sealed class Element_AdaptiveSubgroup : IElementWithDescendants, IHaveXmlName { internal const AdaptiveSubgroupTextStacking DEFAULT_TEXT_STACKING = AdaptiveSubgroupTextStacking.Default; @@ -52,7 +52,7 @@ public IEnumerable Descendants() } /// - string INotificationXmlElement.Name => "subgroup"; + string IHaveXmlName.Name => "subgroup"; } internal interface IElement_AdaptiveSubgroupChild diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs index 0a387f7c9ad..9cd4248b073 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs @@ -6,7 +6,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { - internal sealed class Element_AdaptiveText : IElement_TileBindingChild, IElement_AdaptiveSubgroupChild, IElement_ToastBindingChild, INotificationXmlElement + internal sealed class Element_AdaptiveText : IElement_TileBindingChild, IElement_AdaptiveSubgroupChild, IElement_ToastBindingChild, IHaveXmlName { internal const AdaptiveTextStyle DEFAULT_STYLE = AdaptiveTextStyle.Default; internal const AdaptiveTextAlign DEFAULT_ALIGN = AdaptiveTextAlign.Default; @@ -92,6 +92,6 @@ internal static void CheckMinLinesValue(int value) public AdaptiveTextPlacement Placement { get; set; } = DEFAULT_PLACEMENT; /// - string INotificationXmlElement.Name => "text"; + string IHaveXmlName.Name => "text"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/INotificationXmlElement.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlName.cs similarity index 80% rename from Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/INotificationXmlElement.cs rename to Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlName.cs index f23a04815cf..fc6b25e8490 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/INotificationXmlElement.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlName.cs @@ -5,9 +5,9 @@ namespace Microsoft.Toolkit.Uwp.Notifications; /// -/// An interface for a notification XML element. +/// An interface for a notification XML element with a name. /// -internal interface INotificationXmlElement +internal interface IHaveXmlName { /// /// Gets the name of the current element. diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs index b26ebaee7e1..44014807cd8 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs @@ -19,7 +19,7 @@ internal static class XmlWriterHelper public static void Write(System.Xml.XmlWriter writer, object element) { // If it isn't an XML element, don't write anything - if (element is not INotificationXmlElement xmlElement) + if (element is not IHaveXmlName xmlElement) { return; } diff --git a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_Tile.cs b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_Tile.cs index ff34e1c8d8e..b8742ed4d67 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_Tile.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_Tile.cs @@ -4,11 +4,11 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_Tile : BaseElement, INotificationXmlElement + internal sealed class Element_Tile : BaseElement, IHaveXmlName { public Element_TileVisual Visual { get; set; } /// - string INotificationXmlElement.Name => "tile"; + string IHaveXmlName.Name => "tile"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs index fbf255ef314..8d3792eb74e 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_TileBinding : IElementWithDescendants, INotificationXmlElement + internal sealed class Element_TileBinding : IElementWithDescendants, IHaveXmlName { internal const TileBranding DEFAULT_BRANDING = TileBranding.Auto; internal const TileTextStacking DEFAULT_TEXT_STACKING = TileTextStacking.Top; @@ -120,7 +120,7 @@ public IEnumerable Descendants() } /// - string INotificationXmlElement.Name => "binding"; + string IHaveXmlName.Name => "binding"; } internal interface IElement_TileBindingChild diff --git a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs index d22021cf198..4727a4805f4 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_TileVisual : INotificationXmlElement + internal sealed class Element_TileVisual : IHaveXmlName { internal const TileBranding DEFAULT_BRANDING = TileBranding.Auto; internal const bool DEFAULT_ADD_IMAGE_QUERY = false; @@ -36,6 +36,6 @@ internal sealed class Element_TileVisual : INotificationXmlElement public IList Bindings { get; private set; } = new List(); /// - string INotificationXmlElement.Name => "visual"; + string IHaveXmlName.Name => "visual"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs index 63a7676be3d..c8f593b70f3 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_Toast : BaseElement, IElement_ToastActivatable, IElement_AdditionalProperties, INotificationXmlElement + internal sealed class Element_Toast : BaseElement, IElement_ToastActivatable, IElement_AdditionalProperties, IHaveXmlName { internal const ToastScenario DEFAULT_SCENARIO = ToastScenario.Default; internal const Element_ToastActivationType DEFAULT_ACTIVATION_TYPE = Element_ToastActivationType.Foreground; @@ -83,7 +83,7 @@ public static Element_ToastActivationType ConvertActivationType(ToastActivationT } /// - string INotificationXmlElement.Name => "toast"; + string IHaveXmlName.Name => "toast"; } /// diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAction.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAction.cs index 61872283e13..ec2ea70055d 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAction.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAction.cs @@ -4,7 +4,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastAction : IElement_ToastActionsChild, IElement_ToastActivatable, INotificationXmlElement + internal sealed class Element_ToastAction : IElement_ToastActionsChild, IElement_ToastActivatable, IHaveXmlName { internal const Element_ToastActivationType DEFAULT_ACTIVATION_TYPE = Element_ToastActivationType.Foreground; internal const ToastAfterActivationBehavior DEFAULT_AFTER_ACTIVATION_BEHAVIOR = ToastAfterActivationBehavior.Default; @@ -50,7 +50,7 @@ internal sealed class Element_ToastAction : IElement_ToastActionsChild, IElement public string HintActionId { get; set; } /// - string INotificationXmlElement.Name => "action"; + string IHaveXmlName.Name => "action"; } internal enum Element_ToastActionPlacement diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs index f37d22cf0a2..712f2e1dcf3 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs @@ -6,7 +6,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastActions : INotificationXmlElement + internal sealed class Element_ToastActions : IHaveXmlName { internal const ToastSystemCommand DEFAULT_SYSTEM_COMMAND = ToastSystemCommand.None; @@ -16,7 +16,7 @@ internal sealed class Element_ToastActions : INotificationXmlElement public IList Children { get; private set; } = new List(); /// - string INotificationXmlElement.Name => "actions"; + string IHaveXmlName.Name => "actions"; } internal interface IElement_ToastActionsChild diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAudio.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAudio.cs index f6f482d40d2..ae685cfd773 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAudio.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAudio.cs @@ -6,7 +6,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastAudio : INotificationXmlElement + internal sealed class Element_ToastAudio : IHaveXmlName { internal const bool DEFAULT_LOOP = false; internal const bool DEFAULT_SILENT = false; @@ -27,6 +27,6 @@ internal sealed class Element_ToastAudio : INotificationXmlElement public bool Silent { get; set; } = DEFAULT_SILENT; /// - string INotificationXmlElement.Name => "audio"; + string IHaveXmlName.Name => "audio"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs index 857daa6c378..9ee1a719fd4 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastBinding : INotificationXmlElement + internal sealed class Element_ToastBinding : IHaveXmlName { public Element_ToastBinding(ToastTemplateType template) { @@ -47,7 +47,7 @@ public Element_ToastBinding(ToastTemplateType template) public IList Children { get; private set; } = new List(); /// - string INotificationXmlElement.Name => "binding"; + string IHaveXmlName.Name => "binding"; } internal interface IElement_ToastBindingChild diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastHeader.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastHeader.cs index 36901dbc999..2e35d465fd4 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastHeader.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastHeader.cs @@ -6,7 +6,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastHeader : IElement_ToastActivatable, INotificationXmlElement + internal sealed class Element_ToastHeader : IElement_ToastActivatable, IHaveXmlName { [NotificationXmlAttribute("id")] public string Id { get; set; } @@ -41,6 +41,6 @@ public ToastAfterActivationBehavior AfterActivationBehavior } /// - string INotificationXmlElement.Name => "header"; + string IHaveXmlName.Name => "header"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastImage.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastImage.cs index 0764d3062d5..c872b90c2c2 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastImage.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastImage.cs @@ -4,7 +4,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastImage : IElement_ToastBindingChild, INotificationXmlElement + internal sealed class Element_ToastImage : IElement_ToastBindingChild, IHaveXmlName { internal const ToastImagePlacement DEFAULT_PLACEMENT = ToastImagePlacement.Inline; internal const bool DEFAULT_ADD_IMAGE_QUERY = false; @@ -26,7 +26,7 @@ internal sealed class Element_ToastImage : IElement_ToastBindingChild, INotifica public ToastImageCrop Crop { get; set; } = DEFAULT_CROP; /// - string INotificationXmlElement.Name => "image"; + string IHaveXmlName.Name => "image"; } /// diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs index 64ec4b3cee8..bb8b33c31f7 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs @@ -6,7 +6,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastInput : IElement_ToastActionsChild, INotificationXmlElement + internal sealed class Element_ToastInput : IElement_ToastActionsChild, IHaveXmlName { /// /// Gets or sets the required attributes for developers to retrieve user inputs once the app is activated (in the foreground or background). @@ -38,7 +38,7 @@ internal sealed class Element_ToastInput : IElement_ToastActionsChild, INotifica public IList Children { get; private set; } = new List(); /// - string INotificationXmlElement.Name => "input"; + string IHaveXmlName.Name => "input"; } internal interface IElement_ToastInputChild diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastSelection.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastSelection.cs index 985f75314c1..b8f2d812535 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastSelection.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastSelection.cs @@ -4,7 +4,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastSelection : IElement_ToastInputChild, INotificationXmlElement + internal sealed class Element_ToastSelection : IElement_ToastInputChild, IHaveXmlName { /// /// Gets or sets the id attribute for apps to retrieve back the user selected input after the app is activated. Required @@ -19,6 +19,6 @@ internal sealed class Element_ToastSelection : IElement_ToastInputChild, INotifi public string Content { get; set; } /// - string INotificationXmlElement.Name => "selection"; + string IHaveXmlName.Name => "selection"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs index 8888183d5c2..8eaa1c2182b 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs @@ -4,7 +4,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastText : IElement_ToastBindingChild, INotificationXmlElement + internal sealed class Element_ToastText : IElement_ToastBindingChild, IHaveXmlName { internal const ToastTextPlacement DEFAULT_PLACEMENT = ToastTextPlacement.Inline; @@ -18,7 +18,7 @@ internal sealed class Element_ToastText : IElement_ToastBindingChild, INotificat public ToastTextPlacement Placement { get; set; } = DEFAULT_PLACEMENT; /// - string INotificationXmlElement.Name => "text"; + string IHaveXmlName.Name => "text"; } internal enum ToastTextPlacement diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs index ea9846a0f97..32a00173a25 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastVisual : INotificationXmlElement + internal sealed class Element_ToastVisual : IHaveXmlName { internal const bool DEFAULT_ADD_IMAGE_QUERY = false; @@ -26,6 +26,6 @@ internal sealed class Element_ToastVisual : INotificationXmlElement public IList Bindings { get; private set; } = new List(); /// - string INotificationXmlElement.Name => "visual"; + string IHaveXmlName.Name => "visual"; } } \ No newline at end of file From 63fa2e6552485320277485805803e6311ed0a1b8 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 11 May 2022 03:43:20 +0200 Subject: [PATCH 03/10] Add interface for [NotificationXmlAttribute] --- .../Elements/Element_AdaptiveImage.cs | 35 +++++++++++- .../Elements/Element_AdaptiveProgressBar.cs | 13 ++++- .../Elements/Element_AdaptiveSubgroup.cs | 13 ++++- .../Adaptive/Elements/Element_AdaptiveText.cs | 30 +++++++++- .../Common/EnumFormatter.cs | 56 +++++++++++++++++++ .../Serialization/IHaveXmlNamedProperties.cs | 22 ++++++++ .../Common/XmlWriterHelper.cs | 16 +++--- .../Tiles/Elements/Element_TileBinding.cs | 29 +++++++++- .../Tiles/Elements/Element_TileVisual.cs | 19 ++++++- .../Toasts/Elements/Element_Toast.cs | 34 ++++++++++- .../Toasts/Elements/Element_ToastAction.cs | 33 ++++++++++- .../Toasts/Elements/Element_ToastActions.cs | 11 +++- .../Toasts/Elements/Element_ToastAudio.cs | 19 ++++++- .../Toasts/Elements/Element_ToastBinding.cs | 12 +++- .../Toasts/Elements/Element_ToastHeader.cs | 23 +++++++- .../Toasts/Elements/Element_ToastImage.cs | 26 ++++++++- .../Toasts/Elements/Element_ToastInput.cs | 12 +++- .../Toasts/Elements/Element_ToastSelection.cs | 11 +++- .../Toasts/Elements/Element_ToastText.cs | 15 ++++- .../Toasts/Elements/Element_ToastVisual.cs | 11 +++- 20 files changed, 416 insertions(+), 24 deletions(-) create mode 100644 Microsoft.Toolkit.Uwp.Notifications/Common/EnumFormatter.cs create mode 100644 Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlNamedProperties.cs diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs index 7787e5de064..b8dabe7e99c 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs @@ -2,9 +2,11 @@ // 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.Collections.Generic; + namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { - internal sealed class Element_AdaptiveImage : IElement_TileBindingChild, IElement_ToastBindingChild, IElement_AdaptiveSubgroupChild, IHaveXmlName + internal sealed class Element_AdaptiveImage : IElement_TileBindingChild, IElement_ToastBindingChild, IElement_AdaptiveSubgroupChild, IHaveXmlName, IHaveXmlNamedProperties { internal const AdaptiveImagePlacement DEFAULT_PLACEMENT = AdaptiveImagePlacement.Inline; internal const AdaptiveImageCrop DEFAULT_CROP = AdaptiveImageCrop.Default; @@ -69,5 +71,36 @@ public int? Overlay /// string IHaveXmlName.Name => "image"; + + /// + IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() + { + yield return new("id", Id); + yield return new("src", Src); + yield return new("alt", Alt); + yield return new("addImageQuery", AddImageQuery); + + if (Placement != DEFAULT_PLACEMENT) + { + yield return new("placement", Placement.ToPascalCaseString()); + } + + if (Align != DEFAULT_ALIGN) + { + yield return new("hint-align", Align.ToPascalCaseString()); + } + + if (Crop != DEFAULT_CROP) + { + yield return new("hint-crop", Crop.ToPascalCaseString()); + } + + yield return new("hint-removeMargin", RemoveMargin); + yield return new("hint-overlay", Overlay); + yield return new("spritesheet-src", SpriteSheetSrc); + yield return new("spritesheet-height", SpriteSheetHeight); + yield return new("spritesheet-fps", SpriteSheetFps); + yield return new("spritesheet-startingFrame", SpriteSheetStartingFrame); + } } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs index 9ddb4400129..7880c3f816f 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs @@ -2,9 +2,11 @@ // 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.Collections.Generic; + namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { - internal sealed class Element_AdaptiveProgressBar : IElement_ToastBindingChild, IHaveXmlName + internal sealed class Element_AdaptiveProgressBar : IElement_ToastBindingChild, IHaveXmlName, IHaveXmlNamedProperties { [NotificationXmlAttribute("value")] public string Value { get; set; } @@ -20,5 +22,14 @@ internal sealed class Element_AdaptiveProgressBar : IElement_ToastBindingChild, /// string IHaveXmlName.Name => "progress"; + + /// + IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() + { + yield return new("value", Value); + yield return new("title", Title); + yield return new("valueStringOverride", ValueStringOverride); + yield return new("status", Status); + } } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs index ee2c8b9152d..306900f474f 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { - internal sealed class Element_AdaptiveSubgroup : IElementWithDescendants, IHaveXmlName + internal sealed class Element_AdaptiveSubgroup : IElementWithDescendants, IHaveXmlName, IHaveXmlNamedProperties { internal const AdaptiveSubgroupTextStacking DEFAULT_TEXT_STACKING = AdaptiveSubgroupTextStacking.Default; @@ -53,6 +53,17 @@ public IEnumerable Descendants() /// string IHaveXmlName.Name => "subgroup"; + + /// + IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() + { + if (TextStacking != DEFAULT_TEXT_STACKING) + { + yield return new("hint-textStacking", TextStacking.ToPascalCaseString()); + } + + yield return new("hint-weight", Weight); + } } internal interface IElement_AdaptiveSubgroupChild diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs index 9cd4248b073..d92d49cbc40 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs @@ -3,10 +3,11 @@ // See the LICENSE file in the project root for more information. using System; +using System.Collections.Generic; namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { - internal sealed class Element_AdaptiveText : IElement_TileBindingChild, IElement_AdaptiveSubgroupChild, IElement_ToastBindingChild, IHaveXmlName + internal sealed class Element_AdaptiveText : IElement_TileBindingChild, IElement_AdaptiveSubgroupChild, IElement_ToastBindingChild, IHaveXmlName, IHaveXmlNamedProperties { internal const AdaptiveTextStyle DEFAULT_STYLE = AdaptiveTextStyle.Default; internal const AdaptiveTextAlign DEFAULT_ALIGN = AdaptiveTextAlign.Default; @@ -93,5 +94,32 @@ internal static void CheckMinLinesValue(int value) /// string IHaveXmlName.Name => "text"; + + /// + IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() + { + yield return new("id", Id); + yield return new("lang", Lang); + + if (Align != DEFAULT_ALIGN) + { + yield return new("hint-align", Align.ToPascalCaseString()); + } + + yield return new("hint-maxLines", MaxLines); + yield return new("hint-minLines", MinLines); + + if (Style != DEFAULT_STYLE) + { + yield return new("hint-style", Style.ToPascalCaseString()); + } + + yield return new("hint-wrap", Wrap); + + if (Placement != DEFAULT_PLACEMENT) + { + yield return new("placement", Placement.ToPascalCaseString()); + } + } } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/EnumFormatter.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/EnumFormatter.cs new file mode 100644 index 00000000000..197b0c8ef46 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/EnumFormatter.cs @@ -0,0 +1,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; + +#nullable enable + +namespace Microsoft.Toolkit.Uwp.Notifications; + +/// +/// A helper class that can be used to format values. +/// +internal static class EnumFormatter +{ + /// + /// Returns a representation of an enum value with pascal casing. + /// + /// The type to format. + /// The value to format. + /// The pascal case representation of . + public static string? ToPascalCaseString(this T? value) + where T : unmanaged, Enum + { + if (value is null) + { + return null; + } + + return ToPascalCaseString(value.Value); + } + + /// + /// Returns a representation of an enum value with pascal casing. + /// + /// The type to format. + /// The value to format. + /// The pascal case representation of . + public static string? ToPascalCaseString(this T value) + where T : unmanaged, Enum + { + string? text = value.ToString(); + + if (text is null or { Length: 0 }) + { + return text; + } + + if (text is { Length: 1 }) + { + return text.ToLowerInvariant(); + } + + return $"{char.ToLowerInvariant(text[0])}{text.Substring(1)}"; + } +} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlNamedProperties.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlNamedProperties.cs new file mode 100644 index 00000000000..9322746075d --- /dev/null +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlNamedProperties.cs @@ -0,0 +1,22 @@ +// 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.Collections.Generic; + +#nullable enable + +namespace Microsoft.Toolkit.Uwp.Notifications; + +/// +/// An interface for a notification XML element with named properties. +/// +internal interface IHaveXmlNamedProperties +{ + /// + /// Enumerates the available named properties for the element. + /// + /// A sequence of named properties for the element. + /// The returned values must be valid XML values when is called on them. + IEnumerable> EnumerateNamedProperties(); +} diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs index 44014807cd8..f2aec0d3248 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs @@ -55,13 +55,7 @@ public static void Write(System.Xml.XmlWriter writer, object element) // If it's an attribute else if (attr != null) { - object defaultValue = attr.DefaultValue; - - // If the value is not the default value (and it's not null) we'll write it - if (!object.Equals(propertyValue, defaultValue) && propertyValue != null) - { - writer.WriteAttributeString(attr.Name, PropertyValueToString(propertyValue)); - } + continue; } // If it's a content attribute @@ -80,6 +74,14 @@ public static void Write(System.Xml.XmlWriter writer, object element) } } + foreach (var property in (element as IHaveXmlNamedProperties)?.EnumerateNamedProperties() ?? Enumerable.Empty>()) + { + if (property.Value is not null) + { + writer.WriteAttributeString(property.Key, PropertyValueToString(property.Value)); + } + } + // Then write children foreach (object el in elements) { diff --git a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs index 8d3792eb74e..0d9e67afd73 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_TileBinding : IElementWithDescendants, IHaveXmlName + internal sealed class Element_TileBinding : IElementWithDescendants, IHaveXmlName, IHaveXmlNamedProperties { internal const TileBranding DEFAULT_BRANDING = TileBranding.Auto; internal const TileTextStacking DEFAULT_TEXT_STACKING = TileTextStacking.Top; @@ -121,6 +121,33 @@ public IEnumerable Descendants() /// string IHaveXmlName.Name => "binding"; + + /// + IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() + { + yield return new("template", Template); + yield return new("addImageQuery", AddImageQuery); + yield return new("baseUri", BaseUri); + + if (Branding != DEFAULT_BRANDING) + { + yield return new("branding", Branding); + } + + yield return new("contentId", ContentId); + yield return new("displayName", DisplayName); + yield return new("lang", Language); + yield return new("hint-lockDetailedStatus1", LockDetailedStatus1); + yield return new("hint-lockDetailedStatus2", LockDetailedStatus2); + yield return new("hint-lockDetailedStatus3", LockDetailedStatus3); + yield return new("arguments", Arguments); + yield return new("hint-presentation", Presentation.ToPascalCaseString()); + + if (TextStacking != DEFAULT_TEXT_STACKING) + { + yield return new("hint-textStacking", TextStacking.ToPascalCaseString()); + } + } } internal interface IElement_TileBindingChild diff --git a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs index 4727a4805f4..e5643e69845 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_TileVisual : IHaveXmlName + internal sealed class Element_TileVisual : IHaveXmlName, IHaveXmlNamedProperties { internal const TileBranding DEFAULT_BRANDING = TileBranding.Auto; internal const bool DEFAULT_ADD_IMAGE_QUERY = false; @@ -37,5 +37,22 @@ internal sealed class Element_TileVisual : IHaveXmlName /// string IHaveXmlName.Name => "visual"; + + /// + IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() + { + yield return new("addImageQuery", AddImageQuery); + yield return new("baseUri", BaseUri); + + if (Branding != DEFAULT_BRANDING) + { + yield return new("branding", Branding.ToPascalCaseString()); + } + + yield return new("contentId", ContentId); + yield return new("displayName", DisplayName); + yield return new("lang", Language); + yield return new("arguments", Arguments); + } } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs index c8f593b70f3..b3de75324b1 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_Toast : BaseElement, IElement_ToastActivatable, IElement_AdditionalProperties, IHaveXmlName + internal sealed class Element_Toast : BaseElement, IElement_ToastActivatable, IElement_AdditionalProperties, IHaveXmlName, IHaveXmlNamedProperties { internal const ToastScenario DEFAULT_SCENARIO = ToastScenario.Default; internal const Element_ToastActivationType DEFAULT_ACTIVATION_TYPE = Element_ToastActivationType.Foreground; @@ -84,6 +84,38 @@ public static Element_ToastActivationType ConvertActivationType(ToastActivationT /// string IHaveXmlName.Name => "toast"; + + /// + IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() + { + if (ActivationType != DEFAULT_ACTIVATION_TYPE) + { + yield return new("activationType", ActivationType.ToPascalCaseString()); + } + + yield return new("protocolActivationTargetApplicationPfn", ProtocolActivationTargetApplicationPfn); + + if (AfterActivationBehavior != ToastAfterActivationBehavior.Default) + { + yield return new("afterActivationBehavior", AfterActivationBehavior.ToPascalCaseString()); + } + + if (Duration != DEFAULT_DURATION) + { + yield return new("duration", Duration.ToPascalCaseString()); + } + + yield return new("launch", Launch); + + if (Scenario != DEFAULT_SCENARIO) + { + yield return new("scenario", Scenario.ToPascalCaseString()); + } + + yield return new("displayTimestamp", DisplayTimestamp); + yield return new("hint-toastId", HintToastId); + yield return new("hint-people", HintPeople); + } } /// diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAction.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAction.cs index ec2ea70055d..2e4fff04740 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAction.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAction.cs @@ -2,9 +2,11 @@ // 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.Collections.Generic; + namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastAction : IElement_ToastActionsChild, IElement_ToastActivatable, IHaveXmlName + internal sealed class Element_ToastAction : IElement_ToastActionsChild, IElement_ToastActivatable, IHaveXmlName, IHaveXmlNamedProperties { internal const Element_ToastActivationType DEFAULT_ACTIVATION_TYPE = Element_ToastActivationType.Foreground; internal const ToastAfterActivationBehavior DEFAULT_AFTER_ACTIVATION_BEHAVIOR = ToastAfterActivationBehavior.Default; @@ -51,6 +53,35 @@ internal sealed class Element_ToastAction : IElement_ToastActionsChild, IElement /// string IHaveXmlName.Name => "action"; + + /// + IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() + { + yield return new("content", Content); + yield return new("arguments", Arguments); + + if (ActivationType != DEFAULT_ACTIVATION_TYPE) + { + yield return new("activationType", ActivationType.ToPascalCaseString()); + } + + yield return new("protocolActivationTargetApplicationPfn", ProtocolActivationTargetApplicationPfn); + + if (AfterActivationBehavior != DEFAULT_AFTER_ACTIVATION_BEHAVIOR) + { + yield return new("afterActivationBehavior", AfterActivationBehavior.ToPascalCaseString()); + } + + yield return new("imageUri", ImageUri); + yield return new("hint-inputId", InputId); + + if (Placement != DEFAULT_PLACEMENT) + { + yield return new("placement", Placement.ToPascalCaseString()); + } + + yield return new("hint-actionId", HintActionId); + } } internal enum Element_ToastActionPlacement diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs index 712f2e1dcf3..59aeaaf61d8 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs @@ -6,7 +6,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastActions : IHaveXmlName + internal sealed class Element_ToastActions : IHaveXmlName, IHaveXmlNamedProperties { internal const ToastSystemCommand DEFAULT_SYSTEM_COMMAND = ToastSystemCommand.None; @@ -17,6 +17,15 @@ internal sealed class Element_ToastActions : IHaveXmlName /// string IHaveXmlName.Name => "actions"; + + /// + IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() + { + if (SystemCommands != DEFAULT_SYSTEM_COMMAND) + { + yield return new("hint-systemCommands", SystemCommands); + } + } } internal interface IElement_ToastActionsChild diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAudio.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAudio.cs index ae685cfd773..b24c4bb2b6f 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAudio.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAudio.cs @@ -3,10 +3,11 @@ // See the LICENSE file in the project root for more information. using System; +using System.Collections.Generic; namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastAudio : IHaveXmlName + internal sealed class Element_ToastAudio : IHaveXmlName, IHaveXmlNamedProperties { internal const bool DEFAULT_LOOP = false; internal const bool DEFAULT_SILENT = false; @@ -28,5 +29,21 @@ internal sealed class Element_ToastAudio : IHaveXmlName /// string IHaveXmlName.Name => "audio"; + + /// + IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() + { + yield return new("src", Src); + + if (Loop != DEFAULT_LOOP) + { + yield return new("loop", Loop); + } + + if (Silent != DEFAULT_SILENT) + { + yield return new("silent", Silent); + } + } } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs index 9ee1a719fd4..423ea8eb79d 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastBinding : IHaveXmlName + internal sealed class Element_ToastBinding : IHaveXmlName, IHaveXmlNamedProperties { public Element_ToastBinding(ToastTemplateType template) { @@ -48,6 +48,16 @@ public Element_ToastBinding(ToastTemplateType template) /// string IHaveXmlName.Name => "binding"; + + /// + IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() + { + yield return new("template", Template); + yield return new("addImageQuery", AddImageQuery); + yield return new("baseUri", BaseUri); + yield return new("lang", Language); + yield return new("experienceType", ExperienceType); + } } internal interface IElement_ToastBindingChild diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastHeader.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastHeader.cs index 2e35d465fd4..b7025e52ecd 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastHeader.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastHeader.cs @@ -3,10 +3,11 @@ // See the LICENSE file in the project root for more information. using System; +using System.Collections.Generic; namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastHeader : IElement_ToastActivatable, IHaveXmlName + internal sealed class Element_ToastHeader : IElement_ToastActivatable, IHaveXmlName, IHaveXmlNamedProperties { [NotificationXmlAttribute("id")] public string Id { get; set; } @@ -42,5 +43,25 @@ public ToastAfterActivationBehavior AfterActivationBehavior /// string IHaveXmlName.Name => "header"; + + /// + IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() + { + yield return new("id", Id); + yield return new("title", Title); + yield return new("arguments", Arguments); + + if (ActivationType != Element_ToastActivationType.Foreground) + { + yield return new("activationType", ActivationType.ToPascalCaseString()); + } + + yield return new("protocolActivationTargetApplicationPfn", ProtocolActivationTargetApplicationPfn); + + if (AfterActivationBehavior != ToastAfterActivationBehavior.Default) + { + yield return new("afterActivationBehavior", AfterActivationBehavior.ToPascalCaseString()); + } + } } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastImage.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastImage.cs index c872b90c2c2..7c26a8708e0 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastImage.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastImage.cs @@ -2,9 +2,11 @@ // 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.Collections.Generic; + namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastImage : IElement_ToastBindingChild, IHaveXmlName + internal sealed class Element_ToastImage : IElement_ToastBindingChild, IHaveXmlName, IHaveXmlNamedProperties { internal const ToastImagePlacement DEFAULT_PLACEMENT = ToastImagePlacement.Inline; internal const bool DEFAULT_ADD_IMAGE_QUERY = false; @@ -27,6 +29,28 @@ internal sealed class Element_ToastImage : IElement_ToastBindingChild, IHaveXmlN /// string IHaveXmlName.Name => "image"; + + /// + IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() + { + yield return new("src", Src); + yield return new("alt", Alt); + + if (AddImageQuery != DEFAULT_ADD_IMAGE_QUERY) + { + yield return new("addImageQuery", AddImageQuery); + } + + if (Placement != DEFAULT_PLACEMENT) + { + yield return new("placement", Placement.ToPascalCaseString()); + } + + if (Crop != DEFAULT_CROP) + { + yield return new("crop", Crop.ToPascalCaseString()); + } + } } /// diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs index bb8b33c31f7..63ad76fd227 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs @@ -6,7 +6,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastInput : IElement_ToastActionsChild, IHaveXmlName + internal sealed class Element_ToastInput : IElement_ToastActionsChild, IHaveXmlName, IHaveXmlNamedProperties { /// /// Gets or sets the required attributes for developers to retrieve user inputs once the app is activated (in the foreground or background). @@ -39,6 +39,16 @@ internal sealed class Element_ToastInput : IElement_ToastActionsChild, IHaveXmlN /// string IHaveXmlName.Name => "input"; + + /// + IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() + { + yield return new("id", Id); + yield return new("type", Type.ToPascalCaseString()); + yield return new("title", Title); + yield return new("placeHolderContent", PlaceholderContent); + yield return new("defaultInput", DefaultInput); + } } internal interface IElement_ToastInputChild diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastSelection.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastSelection.cs index b8f2d812535..fa57d48ec00 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastSelection.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastSelection.cs @@ -2,9 +2,11 @@ // 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.Collections.Generic; + namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastSelection : IElement_ToastInputChild, IHaveXmlName + internal sealed class Element_ToastSelection : IElement_ToastInputChild, IHaveXmlName, IHaveXmlNamedProperties { /// /// Gets or sets the id attribute for apps to retrieve back the user selected input after the app is activated. Required @@ -20,5 +22,12 @@ internal sealed class Element_ToastSelection : IElement_ToastInputChild, IHaveXm /// string IHaveXmlName.Name => "selection"; + + /// + IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() + { + yield return new("id", Id); + yield return new("content", Content); + } } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs index 8eaa1c2182b..d795e15d2e7 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs @@ -2,9 +2,11 @@ // 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.Collections.Generic; + namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastText : IElement_ToastBindingChild, IHaveXmlName + internal sealed class Element_ToastText : IElement_ToastBindingChild, IHaveXmlName, IHaveXmlNamedProperties { internal const ToastTextPlacement DEFAULT_PLACEMENT = ToastTextPlacement.Inline; @@ -19,6 +21,17 @@ internal sealed class Element_ToastText : IElement_ToastBindingChild, IHaveXmlNa /// string IHaveXmlName.Name => "text"; + + /// + IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() + { + yield return new("lang", Lang); + + if (Placement != DEFAULT_PLACEMENT) + { + yield return new("placement", Placement.ToPascalCaseString()); + } + } } internal enum ToastTextPlacement diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs index 32a00173a25..c54ecc5882b 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastVisual : IHaveXmlName + internal sealed class Element_ToastVisual : IHaveXmlName, IHaveXmlNamedProperties { internal const bool DEFAULT_ADD_IMAGE_QUERY = false; @@ -27,5 +27,14 @@ internal sealed class Element_ToastVisual : IHaveXmlName /// string IHaveXmlName.Name => "visual"; + + /// + IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() + { + yield return new("addImageQuery", AddImageQuery); + yield return new("baseUri", BaseUri); + yield return new("lang", Language); + yield return new("version", Version); + } } } \ No newline at end of file From 1302d392f8850228b0a1e4cb577b6a662ff9ad51 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 11 May 2022 03:50:31 +0200 Subject: [PATCH 04/10] Rename IElement_AdditionalProperties to IHaveAdditionalProperties Fix --- .../IHaveAdditionalProperties.cs | 20 +++++++++++++++++++ .../Common/XmlWriterHelper.cs | 15 +++++++------- .../Toasts/Elements/Element_Toast.cs | 4 ++-- .../Elements/IElement_AdditionalProperties.cs | 13 ------------ .../Toasts/ToastContent.cs | 2 +- 5 files changed, 30 insertions(+), 24 deletions(-) create mode 100644 Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveAdditionalProperties.cs delete mode 100644 Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/IElement_AdditionalProperties.cs diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveAdditionalProperties.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveAdditionalProperties.cs new file mode 100644 index 00000000000..285fa45a1ac --- /dev/null +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveAdditionalProperties.cs @@ -0,0 +1,20 @@ +// 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.Collections.Generic; + +#nullable enable + +namespace Microsoft.Toolkit.Uwp.Notifications; + +/// +/// An interface for a notification XML element with additional properties. +/// +internal interface IHaveAdditionalProperties +{ + /// + /// Gets the mapping of additional properties. + /// + IReadOnlyDictionary AdditionalProperties { get; } +} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs index f2aec0d3248..be3d5b4a8e9 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs @@ -41,15 +41,9 @@ public static void Write(System.Xml.XmlWriter writer, object element) object propertyValue = GetPropertyValue(p, element); // If it's the additional properties item - if (p.Name == nameof(IElement_AdditionalProperties.AdditionalProperties) && element is IElement_AdditionalProperties && p.PropertyType == typeof(IDictionary)) + if (p.Name == nameof(IHaveXmlAdditionalProperties.AdditionalProperties) && element is IHaveXmlAdditionalProperties && p.PropertyType == typeof(IReadOnlyDictionary)) { - if (propertyValue != null) - { - foreach (var additionalProp in propertyValue as IDictionary) - { - writer.WriteAttributeString(additionalProp.Key, additionalProp.Value); - } - } + continue; } // If it's an attribute @@ -74,6 +68,11 @@ public static void Write(System.Xml.XmlWriter writer, object element) } } + foreach (var property in (element as IHaveAdditionalProperties)?.AdditionalProperties ?? Enumerable.Empty>()) + { + writer.WriteAttributeString(property.Key, property.Value); + } + foreach (var property in (element as IHaveXmlNamedProperties)?.EnumerateNamedProperties() ?? Enumerable.Empty>()) { if (property.Value is not null) diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs index b3de75324b1..22aa99a358e 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_Toast : BaseElement, IElement_ToastActivatable, IElement_AdditionalProperties, IHaveXmlName, IHaveXmlNamedProperties + internal sealed class Element_Toast : BaseElement, IElement_ToastActivatable, IHaveAdditionalProperties, IHaveXmlName, IHaveXmlNamedProperties { internal const ToastScenario DEFAULT_SCENARIO = ToastScenario.Default; internal const Element_ToastActivationType DEFAULT_ACTIVATION_TYPE = Element_ToastActivationType.Foreground; @@ -62,7 +62,7 @@ public ToastAfterActivationBehavior AfterActivationBehavior [NotificationXmlAttribute("hint-people")] public string HintPeople { get; set; } - public IDictionary AdditionalProperties { get; set; } + public IReadOnlyDictionary AdditionalProperties { get; set; } public static Element_ToastActivationType ConvertActivationType(ToastActivationType publicType) { diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/IElement_AdditionalProperties.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/IElement_AdditionalProperties.cs deleted file mode 100644 index 5fa96c14252..00000000000 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/IElement_AdditionalProperties.cs +++ /dev/null @@ -1,13 +0,0 @@ -// 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.Collections.Generic; - -namespace Microsoft.Toolkit.Uwp.Notifications -{ - internal interface IElement_AdditionalProperties - { - IDictionary AdditionalProperties { get; set; } - } -} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/ToastContent.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/ToastContent.cs index f08d5d1e476..dfb44c75833 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/ToastContent.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/ToastContent.cs @@ -144,7 +144,7 @@ internal Element_Toast ConvertToElement() Scenario = Scenario, DisplayTimestamp = strippedDisplayTimestamp, HintToastId = HintToastId, - AdditionalProperties = AdditionalProperties + AdditionalProperties = (Dictionary)AdditionalProperties }; ActivationOptions?.PopulateElement(toast); From f40a419a5461e533dec97baf0e3fe8d89d1150f8 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 11 May 2022 03:54:58 +0200 Subject: [PATCH 05/10] Add interface for [NotificationXmlContent] --- .../Adaptive/Elements/Element_AdaptiveText.cs | 2 +- ...erties.cs => IHaveXmlAdditionalProperties.cs} | 2 +- .../Common/Serialization/IHaveXmlContent.cs | 16 ++++++++++++++++ .../Common/XmlWriterHelper.cs | 6 ++++-- .../Toasts/Elements/Element_Toast.cs | 2 +- .../Toasts/Elements/Element_ToastText.cs | 2 +- 6 files changed, 24 insertions(+), 6 deletions(-) rename Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/{IHaveAdditionalProperties.cs => IHaveXmlAdditionalProperties.cs} (92%) create mode 100644 Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlContent.cs diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs index d92d49cbc40..2fbcd386a65 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { - internal sealed class Element_AdaptiveText : IElement_TileBindingChild, IElement_AdaptiveSubgroupChild, IElement_ToastBindingChild, IHaveXmlName, IHaveXmlNamedProperties + internal sealed class Element_AdaptiveText : IElement_TileBindingChild, IElement_AdaptiveSubgroupChild, IElement_ToastBindingChild, IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlText { internal const AdaptiveTextStyle DEFAULT_STYLE = AdaptiveTextStyle.Default; internal const AdaptiveTextAlign DEFAULT_ALIGN = AdaptiveTextAlign.Default; diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveAdditionalProperties.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlAdditionalProperties.cs similarity index 92% rename from Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveAdditionalProperties.cs rename to Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlAdditionalProperties.cs index 285fa45a1ac..6c5d85d3b38 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveAdditionalProperties.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlAdditionalProperties.cs @@ -11,7 +11,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications; /// /// An interface for a notification XML element with additional properties. /// -internal interface IHaveAdditionalProperties +internal interface IHaveXmlAdditionalProperties { /// /// Gets the mapping of additional properties. diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlContent.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlContent.cs new file mode 100644 index 00000000000..1ffab08022c --- /dev/null +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlContent.cs @@ -0,0 +1,16 @@ +// 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. + +namespace Microsoft.Toolkit.Uwp.Notifications; + +/// +/// An interface for a notification XML element with an explicit XML text content. +/// +internal interface IHaveXmlText +{ + /// + /// Gets the text content of the current element. + /// + string Text { get; } +} diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs index be3d5b4a8e9..f70661bcd16 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs @@ -55,7 +55,7 @@ public static void Write(System.Xml.XmlWriter writer, object element) // If it's a content attribute else if (attributes.OfType().Any()) { - content = propertyValue; + continue; } // Otherwise it's an element or collection of elements @@ -68,7 +68,9 @@ public static void Write(System.Xml.XmlWriter writer, object element) } } - foreach (var property in (element as IHaveAdditionalProperties)?.AdditionalProperties ?? Enumerable.Empty>()) + content = (element as IHaveXmlText)?.Text; + + foreach (var property in (element as IHaveXmlAdditionalProperties)?.AdditionalProperties ?? Enumerable.Empty>()) { writer.WriteAttributeString(property.Key, property.Value); } diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs index 22aa99a358e..b0cd5a09c43 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_Toast : BaseElement, IElement_ToastActivatable, IHaveAdditionalProperties, IHaveXmlName, IHaveXmlNamedProperties + internal sealed class Element_Toast : BaseElement, IElement_ToastActivatable, IHaveXmlAdditionalProperties, IHaveXmlName, IHaveXmlNamedProperties { internal const ToastScenario DEFAULT_SCENARIO = ToastScenario.Default; internal const Element_ToastActivationType DEFAULT_ACTIVATION_TYPE = Element_ToastActivationType.Foreground; diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs index d795e15d2e7..5c900deccd1 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs @@ -6,7 +6,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastText : IElement_ToastBindingChild, IHaveXmlName, IHaveXmlNamedProperties + internal sealed class Element_ToastText : IElement_ToastBindingChild, IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlText { internal const ToastTextPlacement DEFAULT_PLACEMENT = ToastTextPlacement.Inline; From e929ee953e78de5d01dbaad849477a05f42b4f0a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 11 May 2022 04:30:44 +0200 Subject: [PATCH 06/10] Add interface for root child elements --- .../Elements/Element_AdaptiveGroup.cs | 5 +++- .../Elements/Element_AdaptiveSubgroup.cs | 5 +++- .../Common/Serialization/IHaveXmlChildren.cs | 20 +++++++++++++++ .../Common/XmlWriterHelper.cs | 25 ++++++++----------- .../Tiles/Elements/Element_Tile.cs | 7 +++++- .../Tiles/Elements/Element_TileBinding.cs | 5 +++- .../Tiles/Elements/Element_TileVisual.cs | 5 +++- .../Toasts/Elements/Element_Toast.cs | 5 +++- .../Toasts/Elements/Element_ToastActions.cs | 5 +++- .../Toasts/Elements/Element_ToastBinding.cs | 5 +++- .../Toasts/Elements/Element_ToastInput.cs | 5 +++- .../Toasts/Elements/Element_ToastVisual.cs | 5 +++- 12 files changed, 72 insertions(+), 25 deletions(-) create mode 100644 Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlChildren.cs diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveGroup.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveGroup.cs index ebe2905de19..819bfef43bc 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveGroup.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveGroup.cs @@ -6,7 +6,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { - internal sealed class Element_AdaptiveGroup : IElement_TileBindingChild, IElement_ToastBindingChild, IElementWithDescendants, IHaveXmlName + internal sealed class Element_AdaptiveGroup : IElement_TileBindingChild, IElement_ToastBindingChild, IElementWithDescendants, IHaveXmlName, IHaveXmlChildren { public IList Children { get; private set; } = new List(); @@ -27,5 +27,8 @@ public IEnumerable Descendants() /// string IHaveXmlName.Name => "group"; + + /// + IEnumerable IHaveXmlChildren.Children => Children; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs index 306900f474f..2943c1316a9 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { - internal sealed class Element_AdaptiveSubgroup : IElementWithDescendants, IHaveXmlName, IHaveXmlNamedProperties + internal sealed class Element_AdaptiveSubgroup : IElementWithDescendants, IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlChildren { internal const AdaptiveSubgroupTextStacking DEFAULT_TEXT_STACKING = AdaptiveSubgroupTextStacking.Default; @@ -54,6 +54,9 @@ public IEnumerable Descendants() /// string IHaveXmlName.Name => "subgroup"; + /// + IEnumerable IHaveXmlChildren.Children => Children; + /// IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() { diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlChildren.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlChildren.cs new file mode 100644 index 00000000000..9bc07e8a099 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlChildren.cs @@ -0,0 +1,20 @@ +// 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.Collections.Generic; + +#nullable enable + +namespace Microsoft.Toolkit.Uwp.Notifications; + +/// +/// An interface for a notification XML element with additional children. +/// +internal interface IHaveXmlChildren +{ + /// + /// Gets the children of the current element. + /// + IEnumerable Children { get; } +} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs index f70661bcd16..d2ad6cb0cbe 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs @@ -57,14 +57,15 @@ public static void Write(System.Xml.XmlWriter writer, object element) { continue; } + else if (p.Name == nameof(IHaveXmlChildren.Children) && element is IHaveXmlChildren && p.PropertyType == typeof(IEnumerable)) + { + continue; + } // Otherwise it's an element or collection of elements else { - if (propertyValue != null) - { - elements.Add(propertyValue); - } + continue; } } @@ -83,20 +84,14 @@ public static void Write(System.Xml.XmlWriter writer, object element) } } + foreach (var child in (element as IHaveXmlChildren)?.Children ?? Enumerable.Empty()) + { + elements.Add(child); + } + // Then write children foreach (object el in elements) { - // If it's a collection of children - if (el is IEnumerable) - { - foreach (object child in el as IEnumerable) - { - Write(writer, child); - } - - continue; - } - // Otherwise just write the single element Write(writer, el); } diff --git a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_Tile.cs b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_Tile.cs index b8742ed4d67..402268f8361 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_Tile.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_Tile.cs @@ -2,13 +2,18 @@ // 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.Collections.Generic; + namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_Tile : BaseElement, IHaveXmlName + internal sealed class Element_Tile : BaseElement, IHaveXmlName, IHaveXmlChildren { public Element_TileVisual Visual { get; set; } /// string IHaveXmlName.Name => "tile"; + + /// + IEnumerable IHaveXmlChildren.Children => new[] { Visual }; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs index 0d9e67afd73..7a663b7d132 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_TileBinding : IElementWithDescendants, IHaveXmlName, IHaveXmlNamedProperties + internal sealed class Element_TileBinding : IElementWithDescendants, IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlChildren { internal const TileBranding DEFAULT_BRANDING = TileBranding.Auto; internal const TileTextStacking DEFAULT_TEXT_STACKING = TileTextStacking.Top; @@ -122,6 +122,9 @@ public IEnumerable Descendants() /// string IHaveXmlName.Name => "binding"; + /// + IEnumerable IHaveXmlChildren.Children => Children; + /// IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() { diff --git a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs index e5643e69845..d3a0c54a1e3 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_TileVisual : IHaveXmlName, IHaveXmlNamedProperties + internal sealed class Element_TileVisual : IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlChildren { internal const TileBranding DEFAULT_BRANDING = TileBranding.Auto; internal const bool DEFAULT_ADD_IMAGE_QUERY = false; @@ -38,6 +38,9 @@ internal sealed class Element_TileVisual : IHaveXmlName, IHaveXmlNamedProperties /// string IHaveXmlName.Name => "visual"; + /// + IEnumerable IHaveXmlChildren.Children => Bindings; + /// IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() { diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs index b0cd5a09c43..c2ddb39a477 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_Toast : BaseElement, IElement_ToastActivatable, IHaveXmlAdditionalProperties, IHaveXmlName, IHaveXmlNamedProperties + internal sealed class Element_Toast : BaseElement, IElement_ToastActivatable, IHaveXmlAdditionalProperties, IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlChildren { internal const ToastScenario DEFAULT_SCENARIO = ToastScenario.Default; internal const Element_ToastActivationType DEFAULT_ACTIVATION_TYPE = Element_ToastActivationType.Foreground; @@ -85,6 +85,9 @@ public static Element_ToastActivationType ConvertActivationType(ToastActivationT /// string IHaveXmlName.Name => "toast"; + /// + IEnumerable IHaveXmlChildren.Children => new object[] { Visual, Audio, Actions, Header }; + /// IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() { diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs index 59aeaaf61d8..13a291ffc26 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs @@ -6,7 +6,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastActions : IHaveXmlName, IHaveXmlNamedProperties + internal sealed class Element_ToastActions : IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlChildren { internal const ToastSystemCommand DEFAULT_SYSTEM_COMMAND = ToastSystemCommand.None; @@ -18,6 +18,9 @@ internal sealed class Element_ToastActions : IHaveXmlName, IHaveXmlNamedProperti /// string IHaveXmlName.Name => "actions"; + /// + IEnumerable IHaveXmlChildren.Children => Children; + /// IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() { diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs index 423ea8eb79d..40de2ba4281 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastBinding : IHaveXmlName, IHaveXmlNamedProperties + internal sealed class Element_ToastBinding : IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlChildren { public Element_ToastBinding(ToastTemplateType template) { @@ -49,6 +49,9 @@ public Element_ToastBinding(ToastTemplateType template) /// string IHaveXmlName.Name => "binding"; + /// + IEnumerable IHaveXmlChildren.Children => Children; + /// IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() { diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs index 63ad76fd227..8d4d0ad6a57 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs @@ -6,7 +6,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastInput : IElement_ToastActionsChild, IHaveXmlName, IHaveXmlNamedProperties + internal sealed class Element_ToastInput : IElement_ToastActionsChild, IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlChildren { /// /// Gets or sets the required attributes for developers to retrieve user inputs once the app is activated (in the foreground or background). @@ -40,6 +40,9 @@ internal sealed class Element_ToastInput : IElement_ToastActionsChild, IHaveXmlN /// string IHaveXmlName.Name => "input"; + /// + IEnumerable IHaveXmlChildren.Children => Children; + /// IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() { diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs index c54ecc5882b..8cc6343b58f 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs @@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - internal sealed class Element_ToastVisual : IHaveXmlName, IHaveXmlNamedProperties + internal sealed class Element_ToastVisual : IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlChildren { internal const bool DEFAULT_ADD_IMAGE_QUERY = false; @@ -28,6 +28,9 @@ internal sealed class Element_ToastVisual : IHaveXmlName, IHaveXmlNamedPropertie /// string IHaveXmlName.Name => "visual"; + /// + IEnumerable IHaveXmlChildren.Children => Bindings; + /// IEnumerable> IHaveXmlNamedProperties.EnumerateNamedProperties() { From 736fc281d5e03c445f2052c1eb68fee934a767ef Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 11 May 2022 04:38:29 +0200 Subject: [PATCH 07/10] Remove reflection use in XmlWriterHelper --- .../Common/XmlWriterHelper.cs | 178 ++---------------- 1 file changed, 19 insertions(+), 159 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs index d2ad6cb0cbe..9350b5e12d4 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs @@ -3,20 +3,15 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Reflection; - -#if WINDOWS_UWP - -#endif +using System.Xml; namespace Microsoft.Toolkit.Uwp.Notifications { internal static class XmlWriterHelper { - public static void Write(System.Xml.XmlWriter writer, object element) + public static void Write(XmlWriter writer, object element) { // If it isn't an XML element, don't write anything if (element is not IHaveXmlName xmlElement) @@ -26,56 +21,7 @@ public static void Write(System.Xml.XmlWriter writer, object element) writer.WriteStartElement(xmlElement.Name); - IEnumerable properties = GetProperties(element.GetType()); - - List elements = new List(); - object content = null; - - // Write the attributes first - foreach (PropertyInfo p in properties) - { - IEnumerable attributes = GetCustomAttributes(p); - - NotificationXmlAttributeAttribute attr = attributes.OfType().FirstOrDefault(); - - object propertyValue = GetPropertyValue(p, element); - - // If it's the additional properties item - if (p.Name == nameof(IHaveXmlAdditionalProperties.AdditionalProperties) && element is IHaveXmlAdditionalProperties && p.PropertyType == typeof(IReadOnlyDictionary)) - { - continue; - } - - // If it's an attribute - else if (attr != null) - { - continue; - } - - // If it's a content attribute - else if (attributes.OfType().Any()) - { - continue; - } - else if (p.Name == nameof(IHaveXmlChildren.Children) && element is IHaveXmlChildren && p.PropertyType == typeof(IEnumerable)) - { - continue; - } - - // Otherwise it's an element or collection of elements - else - { - continue; - } - } - - content = (element as IHaveXmlText)?.Text; - - foreach (var property in (element as IHaveXmlAdditionalProperties)?.AdditionalProperties ?? Enumerable.Empty>()) - { - writer.WriteAttributeString(property.Key, property.Value); - } - + // Write all named properties foreach (var property in (element as IHaveXmlNamedProperties)?.EnumerateNamedProperties() ?? Enumerable.Empty>()) { if (property.Value is not null) @@ -84,123 +30,37 @@ public static void Write(System.Xml.XmlWriter writer, object element) } } - foreach (var child in (element as IHaveXmlChildren)?.Children ?? Enumerable.Empty()) + // Write all additional properties + foreach (var property in (element as IHaveXmlAdditionalProperties)?.AdditionalProperties ?? Enumerable.Empty>()) { - elements.Add(child); + writer.WriteAttributeString(property.Key, property.Value); } - // Then write children - foreach (object el in elements) + // Write the inner text, if any + if ((element as IHaveXmlText)?.Text is string { Length: > 0 } text) { - // Otherwise just write the single element - Write(writer, el); + writer.WriteString(text); } - // Then write any content if there is content - if (content != null) + // Write all children, if any + foreach (var child in (element as IHaveXmlChildren)?.Children ?? Enumerable.Empty()) { - string contentString = content.ToString(); - if (!string.IsNullOrWhiteSpace(contentString)) - { - writer.WriteString(contentString); - } + Write(writer, child); } writer.WriteEndElement(); } - private static object GetPropertyValue(PropertyInfo propertyInfo, object obj) - { -#if NETFX_CORE - return propertyInfo.GetValue(obj); -#else - return propertyInfo.GetValue(obj, null); -#endif - } - private static string PropertyValueToString(object propertyValue) { - Type type = propertyValue.GetType(); - - if (IsEnum(type)) - { - EnumStringAttribute enumStringAttr = GetEnumStringAttribute(propertyValue as Enum); - - if (enumStringAttr != null) - { - return enumStringAttr.String; - } - } - else if (propertyValue is bool) - { - if ((bool)propertyValue) - { - return "true"; - } - - return "false"; - } - else if (propertyValue is DateTimeOffset?) - { - DateTimeOffset? dateTime = propertyValue as DateTimeOffset?; - if (dateTime.HasValue) - { - // ISO 8601 format - return System.Xml.XmlConvert.ToString(dateTime.Value); - } - else - { - return null; - } - } - - return propertyValue.ToString(); - } - - private static EnumStringAttribute GetEnumStringAttribute(Enum enumValue) - { -#if NETFX_CORE - return enumValue.GetType().GetTypeInfo().GetDeclaredField(enumValue.ToString()).GetCustomAttribute(); -#else - MemberInfo[] memberInfo = enumValue.GetType().GetMember(enumValue.ToString()); - - if (memberInfo != null && memberInfo.Length > 0) + return propertyValue switch { - object[] attrs = memberInfo[0].GetCustomAttributes(typeof(EnumStringAttribute), false); - - if (attrs != null && attrs.Length > 0) - return attrs[0] as EnumStringAttribute; - } - - return null; -#endif - } - - private static bool IsEnum(Type type) - { -#if NETFX_CORE - return type.GetTypeInfo().IsEnum; -#else - return type.IsEnum; -#endif - } - - private static IEnumerable GetProperties(Type type) - { -#if NETFX_CORE - return type.GetTypeInfo().DeclaredProperties; -#else - return type.GetProperties(); -#endif - } - - private static IEnumerable GetCustomAttributes(PropertyInfo propertyInfo) - { -#if NETFX_CORE - return propertyInfo.GetCustomAttributes(); -#else - return propertyInfo.GetCustomAttributes(true).OfType(); -#endif + true => "true", + false => "false", + DateTimeOffset dateTime => XmlConvert.ToString(dateTime), // ISO 8601 format + { } value => value.ToString(), + _ => null + }; } /// From c298d6ebb18be29ada310fe8e2b263ff479b38f9 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 11 May 2022 04:46:19 +0200 Subject: [PATCH 08/10] Remove leftover attributes --- .../Adaptive/AdaptiveImageEnums.cs | 6 ---- .../Adaptive/AdaptiveSubgroupEnums.cs | 3 -- .../Adaptive/AdaptiveTextEnums.cs | 23 --------------- .../Elements/Element_AdaptiveImage.cs | 13 --------- .../Elements/Element_AdaptiveImageEnums.cs | 9 ------ .../Elements/Element_AdaptiveProgressBar.cs | 4 --- .../Elements/Element_AdaptiveSubgroup.cs | 2 -- .../Adaptive/Elements/Element_AdaptiveText.cs | 9 ------ .../Common/EnumStringAttribute.cs | 28 ------------------- .../NotificationXmlAttributeAttribute.cs | 24 ---------------- .../Common/NotificationXmlContentAttribute.cs | 18 ------------ .../Tiles/Elements/Element_TileBinding.cs | 13 --------- .../Tiles/Elements/Element_TileVisual.cs | 7 ----- .../Tiles/Elements/TileElementsCommon.cs | 10 ------- .../Tiles/TileBranding.cs | 4 --- .../Tiles/TileImages.cs | 4 --- .../Tiles/TileTextStacking.cs | 3 -- .../Toasts/Elements/Element_Toast.cs | 13 --------- .../Toasts/Elements/Element_ToastAction.cs | 14 ---------- .../Toasts/Elements/Element_ToastActions.cs | 1 - .../Toasts/Elements/Element_ToastAudio.cs | 3 -- .../Toasts/Elements/Element_ToastBinding.cs | 5 ---- .../Toasts/Elements/Element_ToastHeader.cs | 6 ---- .../Toasts/Elements/Element_ToastImage.cs | 10 ------- .../Toasts/Elements/Element_ToastInput.cs | 8 ------ .../Toasts/Elements/Element_ToastSelection.cs | 2 -- .../Toasts/Elements/Element_ToastText.cs | 5 ---- .../Toasts/Elements/Element_ToastVisual.cs | 4 --- .../Toasts/ToastCommon.cs | 3 -- .../Toasts/ToastGenericAppLogoEnums.cs | 2 -- 30 files changed, 256 deletions(-) delete mode 100644 Microsoft.Toolkit.Uwp.Notifications/Common/EnumStringAttribute.cs delete mode 100644 Microsoft.Toolkit.Uwp.Notifications/Common/NotificationXmlAttributeAttribute.cs delete mode 100644 Microsoft.Toolkit.Uwp.Notifications/Common/NotificationXmlContentAttribute.cs diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/AdaptiveImageEnums.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/AdaptiveImageEnums.cs index 8329b7be1b1..a3263a25b92 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/AdaptiveImageEnums.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/AdaptiveImageEnums.cs @@ -17,25 +17,21 @@ public enum AdaptiveImageAlign /// /// Image stretches to fill available width (and potentially available height too, depending on where the image is). /// - [EnumString("stretch")] Stretch, /// /// Align the image to the left, displaying the image at its native resolution. /// - [EnumString("left")] Left, /// /// Align the image in the center horizontally, displaying the image at its native resolution. /// - [EnumString("center")] Center, /// /// Align the image to the right, displaying the image at its native resolution. /// - [EnumString("right")] Right } @@ -52,13 +48,11 @@ public enum AdaptiveImageCrop /// /// Image is not cropped. /// - [EnumString("none")] None, /// /// Image is cropped to a circle shape. /// - [EnumString("circle")] Circle } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/AdaptiveSubgroupEnums.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/AdaptiveSubgroupEnums.cs index 037d6ecf370..53dc535177f 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/AdaptiveSubgroupEnums.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/AdaptiveSubgroupEnums.cs @@ -17,19 +17,16 @@ public enum AdaptiveSubgroupTextStacking /// /// Vertical align to the top. /// - [EnumString("top")] Top, /// /// Vertical align to the center. /// - [EnumString("center")] Center, /// /// Vertical align to the bottom. /// - [EnumString("bottom")] Bottom } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/AdaptiveTextEnums.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/AdaptiveTextEnums.cs index 371fc40c1a4..e64c5ca8422 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/AdaptiveTextEnums.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/AdaptiveTextEnums.cs @@ -17,103 +17,86 @@ public enum AdaptiveTextStyle /// /// Default value. Paragraph font size, normal weight and opacity. /// - [EnumString("caption")] Caption, /// /// Same as Caption but with subtle opacity. /// - [EnumString("captionSubtle")] CaptionSubtle, /// /// H5 font size. /// - [EnumString("body")] Body, /// /// Same as Body but with subtle opacity. /// - [EnumString("bodySubtle")] BodySubtle, /// /// H5 font size, bold weight. Essentially the bold version of Body. /// - [EnumString("base")] Base, /// /// Same as Base but with subtle opacity. /// - [EnumString("baseSubtle")] BaseSubtle, /// /// H4 font size. /// - [EnumString("subtitle")] Subtitle, /// /// Same as Subtitle but with subtle opacity. /// - [EnumString("subtitleSubtle")] SubtitleSubtle, /// /// H3 font size. /// - [EnumString("title")] Title, /// /// Same as Title but with subtle opacity. /// - [EnumString("titleSubtle")] TitleSubtle, /// /// Same as Title but with top/bottom padding removed. /// - [EnumString("titleNumeral")] TitleNumeral, /// /// H2 font size. /// - [EnumString("subheader")] Subheader, /// /// Same as Subheader but with subtle opacity. /// - [EnumString("subheaderSubtle")] SubheaderSubtle, /// /// Same as Subheader but with top/bottom padding removed. /// - [EnumString("subheaderNumeral")] SubheaderNumeral, /// /// H1 font size. /// - [EnumString("header")] Header, /// /// Same as Header but with subtle opacity. /// - [EnumString("headerSubtle")] HeaderSubtle, /// /// Same as Header but with top/bottom padding removed. /// - [EnumString("headerNumeral")] HeaderNumeral } @@ -130,25 +113,21 @@ public enum AdaptiveTextAlign /// /// The system automatically decides the alignment based on the language and culture. /// - [EnumString("auto")] Auto, /// /// Horizontally align the text to the left. /// - [EnumString("left")] Left, /// /// Horizontally align the text in the center. /// - [EnumString("center")] Center, /// /// Horizontally align the text to the right. /// - [EnumString("right")] Right } @@ -158,8 +137,6 @@ internal enum AdaptiveTextPlacement /// Default value /// Inline, - - [EnumString("attribution")] Attribution } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs index b8dabe7e99c..d9d1b1e7213 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs @@ -12,33 +12,24 @@ internal sealed class Element_AdaptiveImage : IElement_TileBindingChild, IElemen internal const AdaptiveImageCrop DEFAULT_CROP = AdaptiveImageCrop.Default; internal const AdaptiveImageAlign DEFAULT_ALIGN = AdaptiveImageAlign.Default; - [NotificationXmlAttribute("id")] public int? Id { get; set; } - [NotificationXmlAttribute("src")] public string Src { get; set; } - [NotificationXmlAttribute("alt")] public string Alt { get; set; } - [NotificationXmlAttribute("addImageQuery")] public bool? AddImageQuery { get; set; } - [NotificationXmlAttribute("placement", DEFAULT_PLACEMENT)] public AdaptiveImagePlacement Placement { get; set; } = DEFAULT_PLACEMENT; - [NotificationXmlAttribute("hint-align", DEFAULT_ALIGN)] public AdaptiveImageAlign Align { get; set; } = DEFAULT_ALIGN; - [NotificationXmlAttribute("hint-crop", DEFAULT_CROP)] public AdaptiveImageCrop Crop { get; set; } = DEFAULT_CROP; - [NotificationXmlAttribute("hint-removeMargin")] public bool? RemoveMargin { get; set; } private int? _overlay; - [NotificationXmlAttribute("hint-overlay")] public int? Overlay { get @@ -57,16 +48,12 @@ public int? Overlay } } - [NotificationXmlAttribute("spritesheet-src")] public string SpriteSheetSrc { get; set; } - [NotificationXmlAttribute("spritesheet-height")] public uint? SpriteSheetHeight { get; set; } - [NotificationXmlAttribute("spritesheet-fps")] public uint? SpriteSheetFps { get; set; } - [NotificationXmlAttribute("spritesheet-startingFrame")] public uint? SpriteSheetStartingFrame { get; set; } /// diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImageEnums.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImageEnums.cs index 1f5f3212ddb..41c55ebeb00 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImageEnums.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImageEnums.cs @@ -6,19 +6,10 @@ namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { internal enum AdaptiveImagePlacement { - [EnumString("inline")] Inline, - - [EnumString("background")] Background, - - [EnumString("peek")] Peek, - - [EnumString("hero")] Hero, - - [EnumString("appLogoOverride")] AppLogoOverride } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs index 7880c3f816f..65112b35a7d 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs @@ -8,16 +8,12 @@ namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { internal sealed class Element_AdaptiveProgressBar : IElement_ToastBindingChild, IHaveXmlName, IHaveXmlNamedProperties { - [NotificationXmlAttribute("value")] public string Value { get; set; } - [NotificationXmlAttribute("title")] public string Title { get; set; } - [NotificationXmlAttribute("valueStringOverride")] public string ValueStringOverride { get; set; } - [NotificationXmlAttribute("status")] public string Status { get; set; } /// diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs index 2943c1316a9..f8e3b629f28 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs @@ -11,12 +11,10 @@ internal sealed class Element_AdaptiveSubgroup : IElementWithDescendants, IHaveX { internal const AdaptiveSubgroupTextStacking DEFAULT_TEXT_STACKING = AdaptiveSubgroupTextStacking.Default; - [NotificationXmlAttribute("hint-textStacking", DEFAULT_TEXT_STACKING)] public AdaptiveSubgroupTextStacking TextStacking { get; set; } = DEFAULT_TEXT_STACKING; private int? _weight; - [NotificationXmlAttribute("hint-weight")] public int? Weight { get diff --git a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs index 2fbcd386a65..807d4a6ec4a 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs @@ -13,21 +13,16 @@ internal sealed class Element_AdaptiveText : IElement_TileBindingChild, IElement internal const AdaptiveTextAlign DEFAULT_ALIGN = AdaptiveTextAlign.Default; internal const AdaptiveTextPlacement DEFAULT_PLACEMENT = AdaptiveTextPlacement.Inline; - [NotificationXmlContent] public string Text { get; set; } - [NotificationXmlAttribute("id")] public int? Id { get; set; } - [NotificationXmlAttribute("lang")] public string Lang { get; set; } - [NotificationXmlAttribute("hint-align", DEFAULT_ALIGN)] public AdaptiveTextAlign Align { get; set; } = DEFAULT_ALIGN; private int? _maxLines; - [NotificationXmlAttribute("hint-maxLines")] public int? MaxLines { get @@ -56,7 +51,6 @@ internal static void CheckMaxLinesValue(int value) private int? _minLines; - [NotificationXmlAttribute("hint-minLines")] public int? MinLines { get @@ -83,13 +77,10 @@ internal static void CheckMinLinesValue(int value) } } - [NotificationXmlAttribute("hint-style", DEFAULT_STYLE)] public AdaptiveTextStyle Style { get; set; } = DEFAULT_STYLE; - [NotificationXmlAttribute("hint-wrap")] public bool? Wrap { get; set; } - [NotificationXmlAttribute("placement", DEFAULT_PLACEMENT)] public AdaptiveTextPlacement Placement { get; set; } = DEFAULT_PLACEMENT; /// diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/EnumStringAttribute.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/EnumStringAttribute.cs deleted file mode 100644 index 9dcaeb8ab64..00000000000 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/EnumStringAttribute.cs +++ /dev/null @@ -1,28 +0,0 @@ -// 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; - -namespace Microsoft.Toolkit.Uwp.Notifications -{ - internal sealed class EnumStringAttribute : Attribute - { - public string String { get; } - - public EnumStringAttribute(string s) - { - if (s == null) - { - throw new ArgumentNullException(nameof(s)); - } - - String = s; - } - - public override string ToString() - { - return String; - } - } -} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/NotificationXmlAttributeAttribute.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/NotificationXmlAttributeAttribute.cs deleted file mode 100644 index f126dbcd4a7..00000000000 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/NotificationXmlAttributeAttribute.cs +++ /dev/null @@ -1,24 +0,0 @@ -// 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; -#if WINDOWS_UWP - -#endif - -namespace Microsoft.Toolkit.Uwp.Notifications -{ - internal sealed class NotificationXmlAttributeAttribute : Attribute - { - public string Name { get; private set; } - - public object DefaultValue { get; private set; } - - public NotificationXmlAttributeAttribute(string name, object defaultValue = null) - { - Name = name; - DefaultValue = defaultValue; - } - } -} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/NotificationXmlContentAttribute.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/NotificationXmlContentAttribute.cs deleted file mode 100644 index 9e06c7c2a58..00000000000 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/NotificationXmlContentAttribute.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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; -#if WINDOWS_UWP - -#endif - -namespace Microsoft.Toolkit.Uwp.Notifications -{ - /// - /// This attribute should be specified at most one time on an Element class. The property's value will be written as a string in the element's body. - /// - internal sealed class NotificationXmlContentAttribute : Attribute - { - } -} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs index 7a663b7d132..b4b1c3bcdf0 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileBinding.cs @@ -18,7 +18,6 @@ public Element_TileBinding(TileTemplateNameV3 template) Template = template; } - [NotificationXmlAttribute("template")] public TileTemplateNameV3 Template { get; private set; } /// @@ -30,19 +29,16 @@ public Element_TileBinding(TileTemplateNameV3 template) /// /// "www.website.com/images/hello.png?ms-scale=100&ms-contrast=standard&ms-lang=en-us" /// - [NotificationXmlAttribute("addImageQuery")] public bool? AddImageQuery { get; set; } /// /// Gets or sets a default base URI that is combined with relative URIs in image source attributes. /// - [NotificationXmlAttribute("baseUri")] public Uri BaseUri { get; set; } /// /// Gets or sets the form that the Tile should use to display the app's brand. /// - [NotificationXmlAttribute("branding", DEFAULT_BRANDING)] public TileBranding Branding { get; set; } = DEFAULT_BRANDING; /// @@ -50,31 +46,24 @@ public Element_TileBinding(TileTemplateNameV3 template) /// /// Required: NO /// - [NotificationXmlAttribute("contentId")] public string ContentId { get; set; } /// /// Gets or sets an optional string to override the Tile's display name while showing this notification. /// - [NotificationXmlAttribute("displayName")] public string DisplayName { get; set; } /// /// Gets or sets the target locale of the XML payload, specified as a BCP-47 language tags such as "en-US" or "fr-FR". The locale specified here overrides that in visual, but can be overridden by that in text. If this value is a literal string, this attribute defaults to the user's UI language. If this value is a string reference, this attribute defaults to the locale chosen by Windows Runtime in resolving the string. See Remarks for when this value isn't specified. /// - [NotificationXmlAttribute("lang")] public string Language { get; set; } - [NotificationXmlAttribute("hint-lockDetailedStatus1")] public string LockDetailedStatus1 { get; set; } - [NotificationXmlAttribute("hint-lockDetailedStatus2")] public string LockDetailedStatus2 { get; set; } - [NotificationXmlAttribute("hint-lockDetailedStatus3")] public string LockDetailedStatus3 { get; set; } - [NotificationXmlAttribute("arguments")] public string Arguments { get; set; } /// @@ -89,10 +78,8 @@ internal static void CheckOverlayValue(int value) } } - [NotificationXmlAttribute("hint-presentation")] public TilePresentation? Presentation { get; set; } - [NotificationXmlAttribute("hint-textStacking", DEFAULT_TEXT_STACKING)] public TileTextStacking TextStacking { get; set; } = DEFAULT_TEXT_STACKING; public IList Children { get; private set; } = new List(); diff --git a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs index d3a0c54a1e3..581d4c0199b 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs @@ -12,25 +12,18 @@ internal sealed class Element_TileVisual : IHaveXmlName, IHaveXmlNamedProperties internal const TileBranding DEFAULT_BRANDING = TileBranding.Auto; internal const bool DEFAULT_ADD_IMAGE_QUERY = false; - [NotificationXmlAttribute("addImageQuery")] public bool? AddImageQuery { get; set; } - [NotificationXmlAttribute("baseUri")] public Uri BaseUri { get; set; } - [NotificationXmlAttribute("branding", DEFAULT_BRANDING)] public TileBranding Branding { get; set; } = DEFAULT_BRANDING; - [NotificationXmlAttribute("contentId")] public string ContentId { get; set; } - [NotificationXmlAttribute("displayName")] public string DisplayName { get; set; } - [NotificationXmlAttribute("lang")] public string Language { get; set; } - [NotificationXmlAttribute("arguments")] public string Arguments { get; set; } public IList Bindings { get; private set; } = new List(); diff --git a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/TileElementsCommon.cs b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/TileElementsCommon.cs index 2c76193cc55..ae70ee68217 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/TileElementsCommon.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/TileElementsCommon.cs @@ -6,25 +6,15 @@ namespace Microsoft.Toolkit.Uwp.Notifications { internal enum TilePresentation { - [EnumString("people")] People, - - [EnumString("photos")] Photos, - - [EnumString("contact")] Contact } internal enum TileImagePlacement { - [EnumString("inline")] Inline, - - [EnumString("background")] Background, - - [EnumString("peek")] Peek } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Tiles/TileBranding.cs b/Microsoft.Toolkit.Uwp.Notifications/Tiles/TileBranding.cs index 4f2b16e6f2b..23327dba04a 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/TileBranding.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/TileBranding.cs @@ -17,25 +17,21 @@ public enum TileBranding /// /// No branding will be displayed. /// - [EnumString("none")] None, /// /// The DisplayName will be shown. /// - [EnumString("name")] Name, /// /// Desktop-only. The Square44x44Logo will be shown. On Mobile, this will fallback to Name. /// - [EnumString("logo")] Logo, /// /// Desktop-only. Both the DisplayName and Square44x44Logo will be shown. On Mobile, this will fallback to Name. /// - [EnumString("nameAndLogo")] NameAndLogo } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Tiles/TileImages.cs b/Microsoft.Toolkit.Uwp.Notifications/Tiles/TileImages.cs index f0c72571900..d2c57038c80 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/TileImages.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/TileImages.cs @@ -17,13 +17,11 @@ public enum TileBackgroundImageCrop /// /// Default value. Image is not cropped. /// - [EnumString("none")] None, /// /// Image is cropped to a circle shape. /// - [EnumString("circle")] Circle } @@ -40,13 +38,11 @@ public enum TilePeekImageCrop /// /// Default value. Image is not cropped. /// - [EnumString("none")] None, /// /// Image is cropped to a circle shape. /// - [EnumString("circle")] Circle } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Tiles/TileTextStacking.cs b/Microsoft.Toolkit.Uwp.Notifications/Tiles/TileTextStacking.cs index ba657b3db1d..f7054e711ee 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/TileTextStacking.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/TileTextStacking.cs @@ -12,19 +12,16 @@ public enum TileTextStacking /// /// Vertical align to the top. /// - [EnumString("top")] Top, /// /// Vertical align to the center. /// - [EnumString("center")] Center, /// /// Vertical align to the bottom. /// - [EnumString("bottom")] Bottom } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs index c2ddb39a477..75608a38cd5 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs @@ -13,13 +13,10 @@ internal sealed class Element_Toast : BaseElement, IElement_ToastActivatable, IH internal const Element_ToastActivationType DEFAULT_ACTIVATION_TYPE = Element_ToastActivationType.Foreground; internal const ToastDuration DEFAULT_DURATION = ToastDuration.Short; - [NotificationXmlAttribute("activationType", DEFAULT_ACTIVATION_TYPE)] public Element_ToastActivationType ActivationType { get; set; } = DEFAULT_ACTIVATION_TYPE; - [NotificationXmlAttribute("protocolActivationTargetApplicationPfn")] public string ProtocolActivationTargetApplicationPfn { get; set; } - [NotificationXmlAttribute("afterActivationBehavior", ToastAfterActivationBehavior.Default)] public ToastAfterActivationBehavior AfterActivationBehavior { get @@ -36,16 +33,12 @@ public ToastAfterActivationBehavior AfterActivationBehavior } } - [NotificationXmlAttribute("duration", DEFAULT_DURATION)] public ToastDuration Duration { get; set; } = DEFAULT_DURATION; - [NotificationXmlAttribute("launch")] public string Launch { get; set; } - [NotificationXmlAttribute("scenario", DEFAULT_SCENARIO)] public ToastScenario Scenario { get; set; } = DEFAULT_SCENARIO; - [NotificationXmlAttribute("displayTimestamp")] public DateTimeOffset? DisplayTimestamp { get; set; } public Element_ToastVisual Visual { get; set; } @@ -56,10 +49,8 @@ public ToastAfterActivationBehavior AfterActivationBehavior public Element_ToastHeader Header { get; set; } - [NotificationXmlAttribute("hint-toastId")] public string HintToastId { get; set; } - [NotificationXmlAttribute("hint-people")] public string HintPeople { get; set; } public IReadOnlyDictionary AdditionalProperties { get; set; } @@ -134,7 +125,6 @@ public enum ToastDuration /// /// Toast stays on-screen for longer, and then goes into Action Center. /// - [EnumString("long")] Long } @@ -151,19 +141,16 @@ public enum ToastScenario /// /// Causes the Toast to stay on-screen and expanded until the user takes action. Also causes a looping alarm sound to be selected by default. /// - [EnumString("alarm")] Alarm, /// /// Causes the Toast to stay on-screen and expanded until the user takes action. /// - [EnumString("reminder")] Reminder, /// /// Causes the Toast to stay on-screen and expanded until the user takes action (on Mobile this expands to full screen). Also causes a looping incoming call sound to be selected by default. /// - [EnumString("incomingCall")] IncomingCall } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAction.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAction.cs index 2e4fff04740..00c5021a94a 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAction.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAction.cs @@ -15,40 +15,31 @@ internal sealed class Element_ToastAction : IElement_ToastActionsChild, IElement /// /// Gets or sets the text to be displayed on the button. /// - [NotificationXmlAttribute("content")] public string Content { get; set; } /// /// Gets or sets the arguments attribute describing the app-defined data that the app can later retrieve once it is activated from user taking this action. /// - [NotificationXmlAttribute("arguments")] public string Arguments { get; set; } - [NotificationXmlAttribute("activationType", DEFAULT_ACTIVATION_TYPE)] public Element_ToastActivationType ActivationType { get; set; } = DEFAULT_ACTIVATION_TYPE; - [NotificationXmlAttribute("protocolActivationTargetApplicationPfn")] public string ProtocolActivationTargetApplicationPfn { get; set; } - [NotificationXmlAttribute("afterActivationBehavior", DEFAULT_AFTER_ACTIVATION_BEHAVIOR)] public ToastAfterActivationBehavior AfterActivationBehavior { get; set; } = DEFAULT_AFTER_ACTIVATION_BEHAVIOR; /// /// Gets or sets optional value to provide an image icon for this action to display inside the button alone with the text content. /// - [NotificationXmlAttribute("imageUri")] public string ImageUri { get; set; } /// /// Gets or sets value used for the quick reply scenario. /// - [NotificationXmlAttribute("hint-inputId")] public string InputId { get; set; } - [NotificationXmlAttribute("placement", DEFAULT_PLACEMENT)] public Element_ToastActionPlacement Placement { get; set; } = DEFAULT_PLACEMENT; - [NotificationXmlAttribute("hint-actionId")] public string HintActionId { get; set; } /// @@ -87,8 +78,6 @@ IEnumerable> IHaveXmlNamedProperties.EnumerateNamed internal enum Element_ToastActionPlacement { Inline, - - [EnumString("contextMenu")] ContextMenu } @@ -102,19 +91,16 @@ internal enum Element_ToastActivationType /// /// Your corresponding background task (assuming you set everything up) is triggered, and you can execute code in the background (like sending the user's quick reply message) without interrupting the user. /// - [EnumString("background")] Background, /// /// Launch a different app using protocol activation. /// - [EnumString("protocol")] Protocol, /// /// System handles the activation. /// - [EnumString("system")] System } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs index 13a291ffc26..4e2e0642af2 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs @@ -10,7 +10,6 @@ internal sealed class Element_ToastActions : IHaveXmlName, IHaveXmlNamedProperti { internal const ToastSystemCommand DEFAULT_SYSTEM_COMMAND = ToastSystemCommand.None; - [NotificationXmlAttribute("hint-systemCommands", DEFAULT_SYSTEM_COMMAND)] public ToastSystemCommand SystemCommands { get; set; } = ToastSystemCommand.None; public IList Children { get; private set; } = new List(); diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAudio.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAudio.cs index b24c4bb2b6f..0cb8aea588c 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAudio.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAudio.cs @@ -15,16 +15,13 @@ internal sealed class Element_ToastAudio : IHaveXmlName, IHaveXmlNamedProperties /// /// Gets or sets the media file to play in place of the default sound. This can either be a ms-winsoundevent value, or a custom ms-appx:/// or ms-appdata:/// file, or null for the default sound. /// - [NotificationXmlAttribute("src")] public Uri Src { get; set; } - [NotificationXmlAttribute("loop", DEFAULT_LOOP)] public bool Loop { get; set; } = DEFAULT_LOOP; /// /// Gets or sets a value indicating whether the sound is muted; false to allow the Toast notification sound to play. /// - [NotificationXmlAttribute("silent", DEFAULT_SILENT)] public bool Silent { get; set; } = DEFAULT_SILENT; /// diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs index 40de2ba4281..a031371d0a7 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs @@ -14,7 +14,6 @@ public Element_ToastBinding(ToastTemplateType template) Template = template; } - [NotificationXmlAttribute("template")] public ToastTemplateType Template { get; private set; } /// @@ -26,22 +25,18 @@ public Element_ToastBinding(ToastTemplateType template) /// /// "www.website.com/images/hello.png?ms-scale=100&ms-contrast=standard&ms-lang=en-us" /// - [NotificationXmlAttribute("addImageQuery")] public bool? AddImageQuery { get; set; } /// /// Gets or sets a default base URI that is combined with relative URIs in image source attributes. /// - [NotificationXmlAttribute("baseUri")] public Uri BaseUri { get; set; } /// /// Gets or sets the target locale of the XML payload, specified as a BCP-47 language tags such as "en-US" or "fr-FR". The locale specified here overrides that in visual, but can be overridden by that in text. If this value is a literal string, this attribute defaults to the user's UI language. If this value is a string reference, this attribute defaults to the locale chosen by Windows Runtime in resolving the string. See Remarks for when this value isn't specified. /// - [NotificationXmlAttribute("lang")] public string Language { get; set; } - [NotificationXmlAttribute("experienceType")] public string ExperienceType { get; set; } public IList Children { get; private set; } = new List(); diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastHeader.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastHeader.cs index b7025e52ecd..51d7a1c4c50 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastHeader.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastHeader.cs @@ -9,22 +9,16 @@ namespace Microsoft.Toolkit.Uwp.Notifications { internal sealed class Element_ToastHeader : IElement_ToastActivatable, IHaveXmlName, IHaveXmlNamedProperties { - [NotificationXmlAttribute("id")] public string Id { get; set; } - [NotificationXmlAttribute("title")] public string Title { get; set; } - [NotificationXmlAttribute("arguments")] public string Arguments { get; set; } - [NotificationXmlAttribute("activationType", Element_ToastActivationType.Foreground)] public Element_ToastActivationType ActivationType { get; set; } = Element_ToastActivationType.Foreground; - [NotificationXmlAttribute("protocolActivationTargetApplicationPfn")] public string ProtocolActivationTargetApplicationPfn { get; set; } - [NotificationXmlAttribute("afterActivationBehavior", ToastAfterActivationBehavior.Default)] public ToastAfterActivationBehavior AfterActivationBehavior { get diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastImage.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastImage.cs index 7c26a8708e0..796f7c3004f 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastImage.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastImage.cs @@ -12,19 +12,14 @@ internal sealed class Element_ToastImage : IElement_ToastBindingChild, IHaveXmlN internal const bool DEFAULT_ADD_IMAGE_QUERY = false; internal const ToastImageCrop DEFAULT_CROP = ToastImageCrop.None; - [NotificationXmlAttribute("src")] public string Src { get; set; } - [NotificationXmlAttribute("alt")] public string Alt { get; set; } - [NotificationXmlAttribute("addImageQuery", DEFAULT_ADD_IMAGE_QUERY)] public bool AddImageQuery { get; set; } = DEFAULT_ADD_IMAGE_QUERY; - [NotificationXmlAttribute("placement", DEFAULT_PLACEMENT)] public ToastImagePlacement Placement { get; set; } = DEFAULT_PLACEMENT; - [NotificationXmlAttribute("hint-crop", DEFAULT_CROP)] public ToastImageCrop Crop { get; set; } = DEFAULT_CROP; /// @@ -66,18 +61,13 @@ public enum ToastImageCrop /// /// Image is cropped to a circle shape. /// - [EnumString("circle")] Circle } internal enum ToastImagePlacement { Inline, - - [EnumString("appLogoOverride")] AppLogoOverride, - - [EnumString("hero")] Hero } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs index 8d4d0ad6a57..f708f2444eb 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs @@ -11,28 +11,23 @@ internal sealed class Element_ToastInput : IElement_ToastActionsChild, IHaveXmlN /// /// Gets or sets the required attributes for developers to retrieve user inputs once the app is activated (in the foreground or background). /// - [NotificationXmlAttribute("id")] public string Id { get; set; } - [NotificationXmlAttribute("type")] public ToastInputType Type { get; set; } /// /// Gets or sets the optional title attribute and is for developers to specify a title for the input for shells to render when there is affordance. /// - [NotificationXmlAttribute("title")] public string Title { get; set; } /// /// Gets or sets the optional placeholderContent attribute and is the grey-out hint text for text input type. This attribute is ignored when the input type is not �text�. /// - [NotificationXmlAttribute("placeHolderContent")] public string PlaceholderContent { get; set; } /// /// Gets or sets the optional defaultInput attribute and it allows developer to provide a default input value. /// - [NotificationXmlAttribute("defaultInput")] public string DefaultInput { get; set; } public IList Children { get; private set; } = new List(); @@ -60,10 +55,7 @@ internal interface IElement_ToastInputChild internal enum ToastInputType { - [EnumString("text")] Text, - - [EnumString("selection")] Selection } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastSelection.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastSelection.cs index fa57d48ec00..64b19d12598 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastSelection.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastSelection.cs @@ -11,13 +11,11 @@ internal sealed class Element_ToastSelection : IElement_ToastInputChild, IHaveXm /// /// Gets or sets the id attribute for apps to retrieve back the user selected input after the app is activated. Required /// - [NotificationXmlAttribute("id")] public string Id { get; set; } /// /// Gets or sets the text to display for this selection element. /// - [NotificationXmlAttribute("content")] public string Content { get; set; } /// diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs index 5c900deccd1..e84b2bb9a64 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs @@ -10,13 +10,10 @@ internal sealed class Element_ToastText : IElement_ToastBindingChild, IHaveXmlNa { internal const ToastTextPlacement DEFAULT_PLACEMENT = ToastTextPlacement.Inline; - [NotificationXmlContent] public string Text { get; set; } - [NotificationXmlAttribute("lang")] public string Lang { get; set; } - [NotificationXmlAttribute("placement", DEFAULT_PLACEMENT)] public ToastTextPlacement Placement { get; set; } = DEFAULT_PLACEMENT; /// @@ -37,8 +34,6 @@ IEnumerable> IHaveXmlNamedProperties.EnumerateNamed internal enum ToastTextPlacement { Inline, - - [EnumString("attribution")] Attribution } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs index 8cc6343b58f..de99cea5f70 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs @@ -11,16 +11,12 @@ internal sealed class Element_ToastVisual : IHaveXmlName, IHaveXmlNamedPropertie { internal const bool DEFAULT_ADD_IMAGE_QUERY = false; - [NotificationXmlAttribute("addImageQuery")] public bool? AddImageQuery { get; set; } - [NotificationXmlAttribute("baseUri")] public Uri BaseUri { get; set; } - [NotificationXmlAttribute("lang")] public string Language { get; set; } - [NotificationXmlAttribute("version")] public int? Version { get; set; } public IList Bindings { get; private set; } = new List(); diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/ToastCommon.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/ToastCommon.cs index 7b0aa89c01d..a6f6c406c5c 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/ToastCommon.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/ToastCommon.cs @@ -17,13 +17,11 @@ public enum ToastActivationType /// /// Your corresponding background task (assuming you set everything up) is triggered, and you can execute code in the background (like sending the user's quick reply message) without interrupting the user. /// - [EnumString("background")] Background, /// /// Launch a different app using protocol activation. /// - [EnumString("protocol")] Protocol } @@ -40,7 +38,6 @@ public enum ToastAfterActivationBehavior /// /// After the user clicks a button on your toast, the notification will remain present, in a "pending update" visual state. You should immediately update your toast from a background task so that the user does not see this "pending update" visual state for too long. /// - [EnumString("pendingUpdate")] PendingUpdate } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Toasts/ToastGenericAppLogoEnums.cs b/Microsoft.Toolkit.Uwp.Notifications/Toasts/ToastGenericAppLogoEnums.cs index 0de0c24f9fc..e368f58aefa 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/ToastGenericAppLogoEnums.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/ToastGenericAppLogoEnums.cs @@ -17,13 +17,11 @@ public enum ToastGenericAppLogoCrop /// /// Image is not cropped. /// - [EnumString("none")] None, /// /// Image is cropped to a circle shape. /// - [EnumString("circle")] Circle } } \ No newline at end of file From ac3587556a64052cbca1e9c17c30bfa785c11717 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 11 May 2022 04:46:54 +0200 Subject: [PATCH 09/10] Remove .rd.xml file (as it's no longer needed) --- .../Microsoft.Toolkit.Uwp.Notifications.csproj | 3 --- .../Microsoft.Toolkit.Uwp.Notifications.rd.xml | 14 -------------- 2 files changed, 17 deletions(-) delete mode 100644 Microsoft.Toolkit.Uwp.Notifications/Properties/Microsoft.Toolkit.Uwp.Notifications.rd.xml diff --git a/Microsoft.Toolkit.Uwp.Notifications/Microsoft.Toolkit.Uwp.Notifications.csproj b/Microsoft.Toolkit.Uwp.Notifications/Microsoft.Toolkit.Uwp.Notifications.csproj index c53fc9b2dc1..c97dc653fff 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Microsoft.Toolkit.Uwp.Notifications.csproj +++ b/Microsoft.Toolkit.Uwp.Notifications/Microsoft.Toolkit.Uwp.Notifications.csproj @@ -43,9 +43,6 @@ - - - diff --git a/Microsoft.Toolkit.Uwp.Notifications/Properties/Microsoft.Toolkit.Uwp.Notifications.rd.xml b/Microsoft.Toolkit.Uwp.Notifications/Properties/Microsoft.Toolkit.Uwp.Notifications.rd.xml deleted file mode 100644 index aa05dabb3d9..00000000000 --- a/Microsoft.Toolkit.Uwp.Notifications/Properties/Microsoft.Toolkit.Uwp.Notifications.rd.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - \ No newline at end of file From ba85e32275ef15033616c2f1109b41209f93047c Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 11 May 2022 13:52:51 +0200 Subject: [PATCH 10/10] Remove file-scoped namespaces to fix CI issues Also fix a non matching filename --- .../Common/EnumFormatter.cs | 71 ++++++++++--------- .../IHaveXmlAdditionalProperties.cs | 19 ++--- .../Common/Serialization/IHaveXmlChildren.cs | 17 ++--- .../Common/Serialization/IHaveXmlContent.cs | 16 ----- .../Common/Serialization/IHaveXmlName.cs | 17 ++--- .../Serialization/IHaveXmlNamedProperties.cs | 21 +++--- .../Common/Serialization/IHaveXmlText.cs | 17 +++++ 7 files changed, 92 insertions(+), 86 deletions(-) delete mode 100644 Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlContent.cs create mode 100644 Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlText.cs diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/EnumFormatter.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/EnumFormatter.cs index 197b0c8ef46..d7271537450 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/EnumFormatter.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/EnumFormatter.cs @@ -6,51 +6,52 @@ #nullable enable -namespace Microsoft.Toolkit.Uwp.Notifications; - -/// -/// A helper class that can be used to format values. -/// -internal static class EnumFormatter +namespace Microsoft.Toolkit.Uwp.Notifications { /// - /// Returns a representation of an enum value with pascal casing. + /// A helper class that can be used to format values. /// - /// The type to format. - /// The value to format. - /// The pascal case representation of . - public static string? ToPascalCaseString(this T? value) - where T : unmanaged, Enum + internal static class EnumFormatter { - if (value is null) + /// + /// Returns a representation of an enum value with pascal casing. + /// + /// The type to format. + /// The value to format. + /// The pascal case representation of . + public static string? ToPascalCaseString(this T? value) + where T : unmanaged, Enum { - return null; + if (value is null) + { + return null; + } + + return ToPascalCaseString(value.Value); } - return ToPascalCaseString(value.Value); - } + /// + /// Returns a representation of an enum value with pascal casing. + /// + /// The type to format. + /// The value to format. + /// The pascal case representation of . + public static string? ToPascalCaseString(this T value) + where T : unmanaged, Enum + { + string? text = value.ToString(); - /// - /// Returns a representation of an enum value with pascal casing. - /// - /// The type to format. - /// The value to format. - /// The pascal case representation of . - public static string? ToPascalCaseString(this T value) - where T : unmanaged, Enum - { - string? text = value.ToString(); + if (text is null or { Length: 0 }) + { + return text; + } - if (text is null or { Length: 0 }) - { - return text; - } + if (text is { Length: 1 }) + { + return text.ToLowerInvariant(); + } - if (text is { Length: 1 }) - { - return text.ToLowerInvariant(); + return $"{char.ToLowerInvariant(text[0])}{text.Substring(1)}"; } - - return $"{char.ToLowerInvariant(text[0])}{text.Substring(1)}"; } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlAdditionalProperties.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlAdditionalProperties.cs index 6c5d85d3b38..cb11d04ca57 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlAdditionalProperties.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlAdditionalProperties.cs @@ -6,15 +6,16 @@ #nullable enable -namespace Microsoft.Toolkit.Uwp.Notifications; - -/// -/// An interface for a notification XML element with additional properties. -/// -internal interface IHaveXmlAdditionalProperties +namespace Microsoft.Toolkit.Uwp.Notifications { /// - /// Gets the mapping of additional properties. + /// An interface for a notification XML element with additional properties. /// - IReadOnlyDictionary AdditionalProperties { get; } -} \ No newline at end of file + internal interface IHaveXmlAdditionalProperties + { + /// + /// Gets the mapping of additional properties. + /// + IReadOnlyDictionary AdditionalProperties { get; } + } +} diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlChildren.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlChildren.cs index 9bc07e8a099..e97000d3b81 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlChildren.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlChildren.cs @@ -6,15 +6,16 @@ #nullable enable -namespace Microsoft.Toolkit.Uwp.Notifications; - -/// -/// An interface for a notification XML element with additional children. -/// -internal interface IHaveXmlChildren +namespace Microsoft.Toolkit.Uwp.Notifications { /// - /// Gets the children of the current element. + /// An interface for a notification XML element with additional children. /// - IEnumerable Children { get; } + internal interface IHaveXmlChildren + { + /// + /// Gets the children of the current element. + /// + IEnumerable Children { get; } + } } \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlContent.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlContent.cs deleted file mode 100644 index 1ffab08022c..00000000000 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlContent.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -namespace Microsoft.Toolkit.Uwp.Notifications; - -/// -/// An interface for a notification XML element with an explicit XML text content. -/// -internal interface IHaveXmlText -{ - /// - /// Gets the text content of the current element. - /// - string Text { get; } -} diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlName.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlName.cs index fc6b25e8490..82c8308e78d 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlName.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlName.cs @@ -2,15 +2,16 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Microsoft.Toolkit.Uwp.Notifications; - -/// -/// An interface for a notification XML element with a name. -/// -internal interface IHaveXmlName +namespace Microsoft.Toolkit.Uwp.Notifications { /// - /// Gets the name of the current element. + /// An interface for a notification XML element with a name. /// - string Name { get; } + internal interface IHaveXmlName + { + /// + /// Gets the name of the current element. + /// + string Name { get; } + } } diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlNamedProperties.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlNamedProperties.cs index 9322746075d..5dcc7549f4f 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlNamedProperties.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlNamedProperties.cs @@ -6,17 +6,18 @@ #nullable enable -namespace Microsoft.Toolkit.Uwp.Notifications; - -/// -/// An interface for a notification XML element with named properties. -/// -internal interface IHaveXmlNamedProperties +namespace Microsoft.Toolkit.Uwp.Notifications { /// - /// Enumerates the available named properties for the element. + /// An interface for a notification XML element with named properties. /// - /// A sequence of named properties for the element. - /// The returned values must be valid XML values when is called on them. - IEnumerable> EnumerateNamedProperties(); + internal interface IHaveXmlNamedProperties + { + /// + /// Enumerates the available named properties for the element. + /// + /// A sequence of named properties for the element. + /// The returned values must be valid XML values when is called on them. + IEnumerable> EnumerateNamedProperties(); + } } diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlText.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlText.cs new file mode 100644 index 00000000000..de7352073f2 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlText.cs @@ -0,0 +1,17 @@ +// 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. + +namespace Microsoft.Toolkit.Uwp.Notifications +{ + /// + /// An interface for a notification XML element with an explicit XML text content. + /// + internal interface IHaveXmlText + { + /// + /// Gets the text content of the current element. + /// + string Text { get; } + } +}