Skip to content

Commit 1302d39

Browse files
committed
Rename IElement_AdditionalProperties to IHaveAdditionalProperties
Fix
1 parent 63fa2e6 commit 1302d39

File tree

5 files changed

+30
-24
lines changed

5 files changed

+30
-24
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Collections.Generic;
6+
7+
#nullable enable
8+
9+
namespace Microsoft.Toolkit.Uwp.Notifications;
10+
11+
/// <summary>
12+
/// An interface for a notification XML element with additional properties.
13+
/// </summary>
14+
internal interface IHaveAdditionalProperties
15+
{
16+
/// <summary>
17+
/// Gets the mapping of additional properties.
18+
/// </summary>
19+
IReadOnlyDictionary<string, string> AdditionalProperties { get; }
20+
}

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,9 @@ public static void Write(System.Xml.XmlWriter writer, object element)
4141
object propertyValue = GetPropertyValue(p, element);
4242

4343
// If it's the additional properties item
44-
if (p.Name == nameof(IElement_AdditionalProperties.AdditionalProperties) && element is IElement_AdditionalProperties && p.PropertyType == typeof(IDictionary<string, string>))
44+
if (p.Name == nameof(IHaveXmlAdditionalProperties.AdditionalProperties) && element is IHaveXmlAdditionalProperties && p.PropertyType == typeof(IReadOnlyDictionary<string, string>))
4545
{
46-
if (propertyValue != null)
47-
{
48-
foreach (var additionalProp in propertyValue as IDictionary<string, string>)
49-
{
50-
writer.WriteAttributeString(additionalProp.Key, additionalProp.Value);
51-
}
52-
}
46+
continue;
5347
}
5448

5549
// If it's an attribute
@@ -74,6 +68,11 @@ public static void Write(System.Xml.XmlWriter writer, object element)
7468
}
7569
}
7670

71+
foreach (var property in (element as IHaveAdditionalProperties)?.AdditionalProperties ?? Enumerable.Empty<KeyValuePair<string, string>>())
72+
{
73+
writer.WriteAttributeString(property.Key, property.Value);
74+
}
75+
7776
foreach (var property in (element as IHaveXmlNamedProperties)?.EnumerateNamedProperties() ?? Enumerable.Empty<KeyValuePair<string, object>>())
7877
{
7978
if (property.Value is not null)

Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/Element_Toast.cs

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

88
namespace Microsoft.Toolkit.Uwp.Notifications
99
{
10-
internal sealed class Element_Toast : BaseElement, IElement_ToastActivatable, IElement_AdditionalProperties, IHaveXmlName, IHaveXmlNamedProperties
10+
internal sealed class Element_Toast : BaseElement, IElement_ToastActivatable, IHaveAdditionalProperties, IHaveXmlName, IHaveXmlNamedProperties
1111
{
1212
internal const ToastScenario DEFAULT_SCENARIO = ToastScenario.Default;
1313
internal const Element_ToastActivationType DEFAULT_ACTIVATION_TYPE = Element_ToastActivationType.Foreground;
@@ -62,7 +62,7 @@ public ToastAfterActivationBehavior AfterActivationBehavior
6262
[NotificationXmlAttribute("hint-people")]
6363
public string HintPeople { get; set; }
6464

65-
public IDictionary<string, string> AdditionalProperties { get; set; }
65+
public IReadOnlyDictionary<string, string> AdditionalProperties { get; set; }
6666

6767
public static Element_ToastActivationType ConvertActivationType(ToastActivationType publicType)
6868
{

Microsoft.Toolkit.Uwp.Notifications/Toasts/Elements/IElement_AdditionalProperties.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

Microsoft.Toolkit.Uwp.Notifications/Toasts/ToastContent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ internal Element_Toast ConvertToElement()
144144
Scenario = Scenario,
145145
DisplayTimestamp = strippedDisplayTimestamp,
146146
HintToastId = HintToastId,
147-
AdditionalProperties = AdditionalProperties
147+
AdditionalProperties = (Dictionary<string, string>)AdditionalProperties
148148
};
149149

150150
ActivationOptions?.PopulateElement(toast);

0 commit comments

Comments
 (0)