diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ManipulationDevice.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ManipulationDevice.cs index c540572fbc9..69536b67c27 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ManipulationDevice.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ManipulationDevice.cs @@ -215,7 +215,7 @@ internal IEnumerable GetManipulatorsReadOnly() } else { - return new ReadOnlyCollection(new List(2)); + return ReadOnlyCollection.Empty; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ContainerParaClient.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ContainerParaClient.cs index 887466e66c6..14993f5f876 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ContainerParaClient.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ContainerParaClient.cs @@ -330,7 +330,7 @@ internal ReadOnlyCollection GetChildrenParagraphResults(out boo if (subtrackDetails.cParas == 0) { - return new ReadOnlyCollection(new List(0)); + return ReadOnlyCollection.Empty; } // Get list of paragraphs diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureParaClient.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureParaClient.cs index 70d4cf98425..0602417fb81 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureParaClient.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureParaClient.cs @@ -571,7 +571,7 @@ private ReadOnlyCollection GetChildrenParagraphResults(out bool if (trackDetails.cParas == 0) { - return new ReadOnlyCollection(new List(0)); + return ReadOnlyCollection.Empty; } // Get list of paragraphs @@ -597,7 +597,7 @@ private ReadOnlyCollection GetChildrenParagraphResults(out bool // cBasicColumns == 0, means that subpage content is empty if (subpageDetails.u.complex.cBasicColumns == 0) { - return new ReadOnlyCollection(new List(0)); + return ReadOnlyCollection.Empty; } // Retrieve description for each column. @@ -611,7 +611,7 @@ private ReadOnlyCollection GetChildrenParagraphResults(out bool if (trackDetails.cParas == 0) { - return new ReadOnlyCollection(new List(0)); + return ReadOnlyCollection.Empty; } // Get list of paragraphs @@ -738,7 +738,7 @@ internal Geometry GetTightBoundingGeometryFromTextPositions(ReadOnlyCollection paragraphs = (columns.Count > 0) ? columns[0].Paragraphs : new ReadOnlyCollection(new List(0)); + ReadOnlyCollection paragraphs = (columns.Count > 0) ? columns[0].Paragraphs : ReadOnlyCollection.Empty; if (paragraphs.Count > 0 || floatingElements.Count > 0) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FloaterParaClient.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FloaterParaClient.cs index 481b283c52f..28725c3c9be 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FloaterParaClient.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FloaterParaClient.cs @@ -580,7 +580,7 @@ private ReadOnlyCollection GetChildrenParagraphResults(out bool if (trackDetails.cParas == 0) { - return new ReadOnlyCollection(new List(0)); + return ReadOnlyCollection.Empty; } // Get list of paragraphs @@ -606,7 +606,7 @@ private ReadOnlyCollection GetChildrenParagraphResults(out bool // cBasicColumns == 0, means that subpage content is empty if (subpageDetails.u.complex.cBasicColumns == 0) { - return new ReadOnlyCollection(new List(0)); + return ReadOnlyCollection.Empty; } // Retrieve description for each column. @@ -620,7 +620,7 @@ private ReadOnlyCollection GetChildrenParagraphResults(out bool if (trackDetails.cParas == 0) { - return new ReadOnlyCollection(new List(0)); + return ReadOnlyCollection.Empty; } // Get list of paragraphs @@ -747,7 +747,7 @@ internal Geometry GetTightBoundingGeometryFromTextPositions(ReadOnlyCollection paragraphs = (columns.Count > 0) ? columns[0].Paragraphs : new ReadOnlyCollection(new List(0)); + ReadOnlyCollection paragraphs = (columns.Count > 0) ? columns[0].Paragraphs : ReadOnlyCollection.Empty; if (paragraphs.Count > 0 || floatingElements.Count > 0) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FlowDocumentPage.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FlowDocumentPage.cs index ffa0d791abc..bb9caf774a4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FlowDocumentPage.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FlowDocumentPage.cs @@ -367,7 +367,7 @@ internal IEnumerator HostedElementsCore else { // Return empty collection - return new HostedElements(new ReadOnlyCollection(new List(0))); + return new HostedElements(ReadOnlyCollection.Empty); } } } @@ -572,7 +572,7 @@ internal ReadOnlyCollection GetParagraphResultsFromColumn(IntPt if (trackDetails.cParas == 0) { - return new ReadOnlyCollection(new List(0)); + return ReadOnlyCollection.Empty; } PTS.FSPARADESCRIPTION[] arrayParaDesc; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PageVisual.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PageVisual.cs index 0e6a737141f..2937f79cc60 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PageVisual.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PageVisual.cs @@ -125,7 +125,7 @@ ReadOnlyCollection IContentHost.GetRectangles(ContentElement child) { return host.GetRectangles(child); } - return new ReadOnlyCollection(new List(0)); + return ReadOnlyCollection.Empty; } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/TextParaClient.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/TextParaClient.cs index a1615d47bae..11db8f338e9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/TextParaClient.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/TextParaClient.cs @@ -339,7 +339,7 @@ internal ReadOnlyCollection GetLineResults() #if TEXTPANELLAYOUTDEBUG TextPanelDebug.IncrementCounter("TextPara.GetLines", TextPanelDebug.Category.TextView); #endif - ReadOnlyCollection lines = new ReadOnlyCollection(new List(0)); + ReadOnlyCollection lines = ReadOnlyCollection.Empty; // Query paragraph details PTS.FSTEXTDETAILS textDetails; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentPageTextView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentPageTextView.cs index 94d9bd81548..ae7f6e8bd0d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentPageTextView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/DocumentPageTextView.cs @@ -313,7 +313,7 @@ internal override ReadOnlyCollection GetGlyphRuns(ITextPointer start, } if (IsPageMissing) { - return new ReadOnlyCollection(new List()); + return ReadOnlyCollection.Empty; } return _pageTextView.GetGlyphRuns(start, end); } @@ -528,7 +528,7 @@ internal override ReadOnlyCollection TextSegments { if (!IsValid || IsPageMissing) { - return new ReadOnlyCollection(new List()); + return ReadOnlyCollection.Empty; } return _pageTextView.TextSegments; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs index 2757d3cb501..035a6c98a60 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs @@ -589,7 +589,7 @@ internal override ReadOnlyCollection TextSegments // Verify that layout information is valid. Cannot continue if not valid. if (!IsValid) { - return new ReadOnlyCollection(new List()); + return ReadOnlyCollection.Empty; } return this.TextSegmentsCore; } @@ -3559,7 +3559,7 @@ private Rect GetRectangleFromContentEdge(ParagraphResult paragraphResult, ITextP /// /// Cached collection of ColumnResults. /// - private static ReadOnlyCollection _emptyParagraphCollection = new ReadOnlyCollection(new List(0)); + private static ReadOnlyCollection _emptyParagraphCollection = ReadOnlyCollection.Empty; /// /// Cached collection of TextSegments. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextViewBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextViewBase.cs index 5f322c4379b..f9a00b94958 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextViewBase.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextViewBase.cs @@ -109,7 +109,7 @@ internal virtual ReadOnlyCollection GetGlyphRuns(ITextPointer start, I { throw new InvalidOperationException(SR.TextViewInvalidLayout); } - return new ReadOnlyCollection(new List()); + return ReadOnlyCollection.Empty; } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/UIElementIsland.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/UIElementIsland.cs index de658488c9a..19eff63a5b2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/UIElementIsland.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/UIElementIsland.cs @@ -195,7 +195,7 @@ IInputElement IContentHost.InputHitTest(Point point) /// ReadOnlyCollection IContentHost.GetRectangles(ContentElement child) { - return new ReadOnlyCollection(new List()); + return ReadOnlyCollection.Empty; } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationDocumentPaginator.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationDocumentPaginator.cs index c8fa3aba558..4dac43117dc 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationDocumentPaginator.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/AnnotationDocumentPaginator.cs @@ -447,7 +447,7 @@ public IEnumerator HostedElements } else { - return new HostedElements(new ReadOnlyCollection(new List(0))); + return new HostedElements(ReadOnlyCollection.Empty); } } } @@ -463,7 +463,7 @@ public ReadOnlyCollection GetRectangles(ContentElement child) } else { - return new ReadOnlyCollection(new List(0)); + return ReadOnlyCollection.Empty; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs index 5d88bd25b9a..3b333e331f3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DocumentViewer.cs @@ -1231,7 +1231,7 @@ protected override ReadOnlyCollection GetPageViewsCollection(o else { //Return an empty collection (null is not valid). - pageViews = new ReadOnlyCollection(new List(0)); + pageViews = ReadOnlyCollection.Empty; } return pageViews; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentViewerBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentViewerBase.cs index 92b1d0a1f8b..77bb788edc4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentViewerBase.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DocumentViewerBase.cs @@ -70,7 +70,7 @@ static DocumentViewerBase() protected DocumentViewerBase() : base() { - _pageViews = new ReadOnlyCollection(new List()); + _pageViews = ReadOnlyCollection.Empty; // By default text selection is enabled. SetFlags(true, Flags.IsSelectionEnabled); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextChangedEventArgs.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextChangedEventArgs.cs index b52b0457014..2bc7cfff2e7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextChangedEventArgs.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextChangedEventArgs.cs @@ -86,7 +86,7 @@ public TextChangedEventArgs(RoutedEvent id, UndoAction action, ICollectionevent id /// UndoAction public TextChangedEventArgs(RoutedEvent id, UndoAction action) - : this(id, action, new ReadOnlyCollection(new List())) + : this(id, action, ReadOnlyCollection.Empty) { } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextFlow.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextFlow.cs index a7777fce3e7..663a7cc611b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextFlow.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextFlow.cs @@ -989,7 +989,7 @@ protected virtual ReadOnlyCollection GetRectanglesCore(ContentElement chil throw new ArgumentNullException("child"); } - ReadOnlyCollection rectangles = new ReadOnlyCollection(new List(0)); + ReadOnlyCollection rectangles = ReadOnlyCollection.Empty; if (IsLayoutDataValid) { // Here we must call the internal function on document page that tells it whether or not @@ -1019,7 +1019,7 @@ protected virtual IEnumerator HostedElementsCore else { // Return empty collection - hostedElements = new HostedElements(new ReadOnlyCollection(new List(0))); + hostedElements = new HostedElements(ReadOnlyCollection.Empty); } return hostedElements; } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/MemberReflector.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/MemberReflector.cs index e01db3a94d8..1b4a4aef0c0 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/MemberReflector.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/MemberReflector.cs @@ -4,6 +4,7 @@ #nullable disable +using System.Collections.ObjectModel; using System.ComponentModel; using System.Reflection; using System.Windows.Markup; @@ -91,7 +92,7 @@ internal static MemberReflector UnknownReflector s_UnknownReflector._typeConverter.Value = null; s_UnknownReflector._valueSerializer.Value = null; - s_UnknownReflector.DependsOn = XamlType.EmptyList.Value; + s_UnknownReflector.DependsOn = ReadOnlyCollection.Empty; s_UnknownReflector.Invoker = XamlMemberInvoker.UnknownInvoker; s_UnknownReflector.Type = XamlLanguage.Object; } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMember.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMember.cs index 5ccc5841932..927dfea1248 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMember.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlMember.cs @@ -4,6 +4,7 @@ #nullable disable +using System.Collections.ObjectModel; using System.ComponentModel; using System.Reflection; using System.Threading; @@ -346,7 +347,7 @@ public IList DependsOn EnsureReflector(); if (_reflector.DependsOn is null) { - _reflector.DependsOn = LookupDependsOn() ?? XamlType.EmptyList.Value; + _reflector.DependsOn = LookupDependsOn() ?? ReadOnlyCollection.Empty; } return _reflector.DependsOn; } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs index 006c234d299..b66798fe26c 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs @@ -233,7 +233,7 @@ public IList AllowedContentTypes if (_reflector.AllowedContentTypes is null) { _reflector.AllowedContentTypes = LookupAllowedContentTypes() ?? - EmptyList.Value; + ReadOnlyCollection.Empty; } return _reflector.AllowedContentTypes; } @@ -251,7 +251,7 @@ public IList ContentWrappers if (_reflector.ContentWrappers is null) { _reflector.ContentWrappers = LookupContentWrappers() ?? - EmptyList.Value; + ReadOnlyCollection.Empty; } return _reflector.ContentWrappers; } @@ -598,7 +598,7 @@ internal ICollection GetAllExcludedReadOnlyMembers() EnsureReflector(); if (_reflector.ExcludedReadOnlyMembers is null) { - _reflector.ExcludedReadOnlyMembers = LookupAllExcludedReadOnlyMembers() ?? EmptyList.Value; + _reflector.ExcludedReadOnlyMembers = LookupAllExcludedReadOnlyMembers() ?? ReadOnlyCollection.Empty; } return _reflector.ExcludedReadOnlyMembers; } @@ -609,7 +609,7 @@ internal IEnumerable GetConstructors() { if (UnderlyingType is null) { - return EmptyList.Value; + return ReadOnlyCollection.Empty; } if (IsPublic) { @@ -680,7 +680,7 @@ protected virtual XamlMember LookupAliasedProperty(XamlDirective directive) protected virtual IList LookupAllowedContentTypes() { - IList contentWrappers = ContentWrappers ?? EmptyList.Value; + IList contentWrappers = ContentWrappers ?? ReadOnlyCollection.Empty; List result = new List(contentWrappers.Count + 1); result.Add(ItemType); @@ -1461,7 +1461,7 @@ internal static ReadOnlyCollection GetReadOnly(IList list) { return new ReadOnlyCollection(list); } - return EmptyList.Value; + return ReadOnlyCollection.Empty; } private static ReadOnlyCollection GetTypeArguments(IList typeArguments) @@ -1823,11 +1823,5 @@ private static bool TypeArgumentsAreEqual(XamlType xamlType1, XamlType xamlType2 } #endregion - - internal static class EmptyList - { - public static readonly ReadOnlyCollection Value = - new ReadOnlyCollection(Array.Empty()); - } } }