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_AdaptiveGroup.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveGroup.cs index dbb0d52753e..819bfef43bc 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, IHaveXmlName, IHaveXmlChildren { public IList Children { get; private set; } = new List(); @@ -25,5 +24,11 @@ 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_AdaptiveImage.cs b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs index 8cf0b92b62b..d9d1b1e7213 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveImage.cs @@ -2,42 +2,34 @@ // 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 { - [NotificationXmlElement("image")] - internal sealed class Element_AdaptiveImage : IElement_TileBindingChild, IElement_ToastBindingChild, IElement_AdaptiveSubgroupChild + 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; 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 @@ -56,16 +48,46 @@ 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; } + + /// + 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_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 17fd0001ab6..65112b35a7d 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveProgressBar.cs @@ -2,21 +2,30 @@ // 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 { - [NotificationXmlElement("progress")] - internal sealed class Element_AdaptiveProgressBar : IElement_ToastBindingChild + 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; } + + /// + 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 acfd9eedb3b..f8e3b629f28 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveSubgroup.cs @@ -7,17 +7,14 @@ namespace Microsoft.Toolkit.Uwp.Notifications.Adaptive.Elements { - [NotificationXmlElement("subgroup")] - internal sealed class Element_AdaptiveSubgroup : IElementWithDescendants + internal sealed class Element_AdaptiveSubgroup : IElementWithDescendants, IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlChildren { 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 @@ -51,6 +48,23 @@ public IEnumerable Descendants() yield return child; } } + + /// + string IHaveXmlName.Name => "subgroup"; + + /// + IEnumerable IHaveXmlChildren.Children => Children; + + /// + 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 7641d962838..807d4a6ec4a 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Adaptive/Elements/Element_AdaptiveText.cs @@ -3,31 +3,26 @@ // See the LICENSE file in the project root for more information. using System; +using System.Collections.Generic; 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, IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlText { internal const AdaptiveTextStyle DEFAULT_STYLE = AdaptiveTextStyle.Default; 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,40 @@ 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; + + /// + 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..d7271537450 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/EnumFormatter.cs @@ -0,0 +1,57 @@ +// 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/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/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/IHaveXmlAdditionalProperties.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlAdditionalProperties.cs new file mode 100644 index 00000000000..cb11d04ca57 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlAdditionalProperties.cs @@ -0,0 +1,21 @@ +// 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 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 new file mode 100644 index 00000000000..e97000d3b81 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlChildren.cs @@ -0,0 +1,21 @@ +// 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/NotificationXmlContentAttribute.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlName.cs similarity index 53% rename from Microsoft.Toolkit.Uwp.Notifications/Common/NotificationXmlContentAttribute.cs rename to Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlName.cs index 9e06c7c2a58..82c8308e78d 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/NotificationXmlContentAttribute.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlName.cs @@ -2,17 +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. -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. + /// An interface for a notification XML element with a name. /// - internal sealed class NotificationXmlContentAttribute : Attribute + internal interface IHaveXmlName { + /// + /// Gets the name of the current element. + /// + string Name { get; } } -} \ 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..5dcc7549f4f --- /dev/null +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/Serialization/IHaveXmlNamedProperties.cs @@ -0,0 +1,23 @@ +// 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/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; } + } +} diff --git a/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs b/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs index 2318b4d819e..9350b5e12d4 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Common/XmlWriterHelper.cs @@ -3,222 +3,64 @@ // 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) { - 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 IHaveXmlName xmlElement) { return; } - writer.WriteStartElement(elAttr.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(IElement_AdditionalProperties.AdditionalProperties) && element is IElement_AdditionalProperties && p.PropertyType == typeof(IDictionary)) - { - if (propertyValue != null) - { - foreach (var additionalProp in propertyValue as IDictionary) - { - writer.WriteAttributeString(additionalProp.Key, additionalProp.Value); - } - } - } - - // 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)); - } - } - - // If it's a content attribute - else if (attributes.OfType().Any()) - { - content = propertyValue; - } + writer.WriteStartElement(xmlElement.Name); - // Otherwise it's an element or collection of elements - else - { - if (propertyValue != null) - { - elements.Add(propertyValue); - } - } - } - - // Then write children - foreach (object el in elements) + // Write all named properties + foreach (var property in (element as IHaveXmlNamedProperties)?.EnumerateNamedProperties() ?? Enumerable.Empty>()) { - // If it's a collection of children - if (el is IEnumerable) + if (property.Value is not null) { - foreach (object child in el as IEnumerable) - { - Write(writer, child); - } - - continue; + writer.WriteAttributeString(property.Key, PropertyValueToString(property.Value)); } - - // Otherwise just write the single element - Write(writer, el); } - // Then write any content if there is content - if (content != null) + // Write all additional properties + foreach (var property in (element as IHaveXmlAdditionalProperties)?.AdditionalProperties ?? Enumerable.Empty>()) { - string contentString = content.ToString(); - if (!string.IsNullOrWhiteSpace(contentString)) - { - writer.WriteString(contentString); - } + writer.WriteAttributeString(property.Key, property.Value); } - 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)) + // Write the inner text, if any + if ((element as IHaveXmlText)?.Text is string { Length: > 0 } text) { - EnumStringAttribute enumStringAttr = GetEnumStringAttribute(propertyValue as Enum); - - if (enumStringAttr != null) - { - return enumStringAttr.String; - } + writer.WriteString(text); } - else if (propertyValue is bool) - { - if ((bool)propertyValue) - { - return "true"; - } - return "false"; - } - else if (propertyValue is DateTimeOffset?) + // Write all children, if any + foreach (var child in (element as IHaveXmlChildren)?.Children ?? Enumerable.Empty()) { - DateTimeOffset? dateTime = propertyValue as DateTimeOffset?; - if (dateTime.HasValue) - { - // ISO 8601 format - return System.Xml.XmlConvert.ToString(dateTime.Value); - } - else - { - return null; - } + Write(writer, child); } - return propertyValue.ToString(); + writer.WriteEndElement(); } - private static EnumStringAttribute GetEnumStringAttribute(Enum enumValue) + private static string PropertyValueToString(object propertyValue) { -#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 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 - 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 + }; } /// 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 diff --git a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_Tile.cs b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_Tile.cs index 636c4369279..402268f8361 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_Tile.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_Tile.cs @@ -2,11 +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 { - [NotificationXmlElement("tile")] - internal sealed class Element_Tile : BaseElement + 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 8dfe545f273..b4b1c3bcdf0 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, IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlChildren { internal const TileBranding DEFAULT_BRANDING = TileBranding.Auto; internal const TileTextStacking DEFAULT_TEXT_STACKING = TileTextStacking.Top; @@ -19,7 +18,6 @@ public Element_TileBinding(TileTemplateNameV3 template) Template = template; } - [NotificationXmlAttribute("template")] public TileTemplateNameV3 Template { get; private set; } /// @@ -31,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; /// @@ -51,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; } /// @@ -90,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(); @@ -119,6 +105,39 @@ public IEnumerable Descendants() } } } + + /// + string IHaveXmlName.Name => "binding"; + + /// + IEnumerable IHaveXmlChildren.Children => Children; + + /// + 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 1d22c1cc5a1..581d4c0199b 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Tiles/Elements/Element_TileVisual.cs @@ -7,33 +7,48 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("visual")] - internal sealed class Element_TileVisual + internal sealed class Element_TileVisual : IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlChildren { 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(); + + /// + string IHaveXmlName.Name => "visual"; + + /// + IEnumerable IHaveXmlChildren.Children => Bindings; + + /// + 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/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 3db2c757839..75608a38cd5 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs @@ -7,20 +7,16 @@ 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, IHaveXmlAdditionalProperties, IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlChildren { internal const ToastScenario DEFAULT_SCENARIO = ToastScenario.Default; 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 @@ -37,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; } @@ -57,13 +49,11 @@ 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 IDictionary AdditionalProperties { get; set; } + public IReadOnlyDictionary AdditionalProperties { get; set; } public static Element_ToastActivationType ConvertActivationType(ToastActivationType publicType) { @@ -82,6 +72,44 @@ public static Element_ToastActivationType ConvertActivationType(ToastActivationT throw new NotImplementedException(); } } + + /// + string IHaveXmlName.Name => "toast"; + + /// + IEnumerable IHaveXmlChildren.Children => new object[] { Visual, Audio, Actions, Header }; + + /// + 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); + } } /// @@ -97,7 +125,6 @@ public enum ToastDuration /// /// Toast stays on-screen for longer, and then goes into Action Center. /// - [EnumString("long")] Long } @@ -114,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 cd31e550866..00c5021a94a 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAction.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAction.cs @@ -2,10 +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 { - [NotificationXmlElement("action")] - internal sealed class Element_ToastAction : IElement_ToastActionsChild, IElement_ToastActivatable + 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; @@ -14,48 +15,69 @@ 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; } + + /// + 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 { Inline, - - [EnumString("contextMenu")] ContextMenu } @@ -69,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 fd8e1e77771..4e2e0642af2 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastActions.cs @@ -6,15 +6,28 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("actions")] - internal sealed class Element_ToastActions + internal sealed class Element_ToastActions : IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlChildren { 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(); + + /// + string IHaveXmlName.Name => "actions"; + + /// + IEnumerable IHaveXmlChildren.Children => Children; + + /// + 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 88adb5317c8..0cb8aea588c 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAudio.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastAudio.cs @@ -3,11 +3,11 @@ // See the LICENSE file in the project root for more information. using System; +using System.Collections.Generic; namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("audio")] - internal sealed class Element_ToastAudio + internal sealed class Element_ToastAudio : IHaveXmlName, IHaveXmlNamedProperties { internal const bool DEFAULT_LOOP = false; internal const bool DEFAULT_SILENT = false; @@ -15,16 +15,32 @@ internal sealed class Element_ToastAudio /// /// 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; + + /// + 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 b4dd8d784b9..a031371d0a7 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastBinding.cs @@ -7,15 +7,13 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("binding")] - internal sealed class Element_ToastBinding + internal sealed class Element_ToastBinding : IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlChildren { public Element_ToastBinding(ToastTemplateType template) { Template = template; } - [NotificationXmlAttribute("template")] public ToastTemplateType Template { get; private set; } /// @@ -27,25 +25,37 @@ 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(); + + /// + string IHaveXmlName.Name => "binding"; + + /// + IEnumerable IHaveXmlChildren.Children => Children; + + /// + 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 a5ebd37240c..51d7a1c4c50 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastHeader.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastHeader.cs @@ -3,28 +3,22 @@ // See the LICENSE file in the project root for more information. using System; +using System.Collections.Generic; namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("header")] - internal sealed class Element_ToastHeader : IElement_ToastActivatable + 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 @@ -40,5 +34,28 @@ 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 7df0eb94692..796f7c3004f 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastImage.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastImage.cs @@ -2,29 +2,50 @@ // 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 { - [NotificationXmlElement("image")] - internal sealed class Element_ToastImage : IElement_ToastBindingChild + internal sealed class Element_ToastImage : IElement_ToastBindingChild, IHaveXmlName, IHaveXmlNamedProperties { internal const ToastImagePlacement DEFAULT_PLACEMENT = ToastImagePlacement.Inline; 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; + + /// + 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()); + } + } } /// @@ -40,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 6b4c9527d34..f708f2444eb 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastInput.cs @@ -6,37 +6,47 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("input")] - internal sealed class Element_ToastInput : IElement_ToastActionsChild + 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). /// - [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(); + + /// + string IHaveXmlName.Name => "input"; + + /// + IEnumerable IHaveXmlChildren.Children => Children; + + /// + 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 @@ -45,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 2b67b41194e..64b19d12598 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastSelection.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastSelection.cs @@ -2,21 +2,30 @@ // 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 { - [NotificationXmlElement("selection")] - internal sealed class Element_ToastSelection : IElement_ToastInputChild + 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 /// - [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; } + + /// + 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 22754eaf0bf..e84b2bb9a64 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastText.cs @@ -2,28 +2,38 @@ // 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 { - [NotificationXmlElement("text")] - internal sealed class Element_ToastText : IElement_ToastBindingChild + internal sealed class Element_ToastText : IElement_ToastBindingChild, IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlText { 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; + + /// + 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 { 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 736f2d7ac22..de99cea5f70 100644 --- a/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs +++ b/Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_ToastVisual.cs @@ -7,23 +7,33 @@ namespace Microsoft.Toolkit.Uwp.Notifications { - [NotificationXmlElement("visual")] - internal sealed class Element_ToastVisual + internal sealed class Element_ToastVisual : IHaveXmlName, IHaveXmlNamedProperties, IHaveXmlChildren { 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(); + + /// + string IHaveXmlName.Name => "visual"; + + /// + IEnumerable IHaveXmlChildren.Children => Bindings; + + /// + 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 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/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/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); 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