From 58ceab0e595671756b522013d06870b75c44051b Mon Sep 17 00:00:00 2001 From: h3xds1nz Date: Sat, 22 Aug 2026 17:13:05 +0800 Subject: [PATCH] Apply changes from https://github.com/dotnet/wpf/pull/10750 Source-PR: https://github.com/dotnet/wpf/pull/10750 Source-Head-SHA: 37491a8add50bb0238c7aef6fdd030bcf29aa397 --- .../System/Xaml/XamlMarkupExtensionWriter.cs | 9 +++--- .../System.Xaml/System/Xaml/XamlXmlWriter.cs | 31 ++++--------------- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMarkupExtensionWriter.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMarkupExtensionWriter.cs index b44a6c9a1..c2307a628 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMarkupExtensionWriter.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMarkupExtensionWriter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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. @@ -129,13 +129,12 @@ void CheckMemberForUniqueness(Node objectNode, XamlMember property) { if (objectNode.Members == null) { - objectNode.Members = new XamlPropertySet(); + objectNode.Members = new HashSet() { property }; } - else if (objectNode.Members.Contains(property)) + else if (!objectNode.Members.Add(property)) { throw new InvalidOperationException(SR.Format(SR.XamlMarkupExtensionWriterDuplicateMember, property.Name)); } - objectNode.Members.Add(property); } } @@ -188,7 +187,7 @@ public XamlMember XamlProperty get; set; } - public XamlPropertySet Members + public HashSet Members { get; set; diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs index 8d12e21be..cb059f989 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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. @@ -492,26 +492,23 @@ void CheckMemberForUniqueness(XamlMember property) { // Find the top most object frame. Frame objectFrame = namespaceScopes.Peek(); - if (objectFrame.AllocatingNodeType != XamlNodeType.StartObject && - objectFrame.AllocatingNodeType != XamlNodeType.GetObject) + if (objectFrame.AllocatingNodeType is not XamlNodeType.StartObject and not XamlNodeType.GetObject) { Frame temp = namespaceScopes.Pop(); objectFrame = namespaceScopes.Peek(); namespaceScopes.Push(temp); } - Debug.Assert(objectFrame.AllocatingNodeType == XamlNodeType.StartObject || - objectFrame.AllocatingNodeType == XamlNodeType.GetObject); + Debug.Assert(objectFrame.AllocatingNodeType is XamlNodeType.StartObject or XamlNodeType.GetObject); if (objectFrame.Members == null) { - objectFrame.Members = new XamlPropertySet(); + objectFrame.Members = new HashSet() { property }; } - else if (objectFrame.Members.Contains(property)) + else if (!objectFrame.Members.Add(property)) { throw new XamlXmlWriterException(SR.Format(SR.XamlXmlWriterDuplicateMember, property.Name)); } - objectFrame.Members.Add(property); } } @@ -684,7 +681,7 @@ public XamlMember Member set; } - public XamlPropertySet Members + public HashSet Members { get; set; @@ -2162,20 +2159,4 @@ public void Reset() } } - // need to implement our own Set class to alleviate ties to System.Core.dll - // HashSet lives in System.Core.dll - internal class XamlPropertySet - { - Dictionary dictionary = new Dictionary(); - - public bool Contains(XamlMember member) - { - return dictionary.ContainsKey(member); - } - - public void Add(XamlMember member) - { - dictionary.Add(member, true); - } - } }