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 f3ff4703aac..974a4962437 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 @@ -572,7 +572,7 @@ private ReadOnlyCollection GetChildrenParagraphResults(out bool if (trackDetails.cParas == 0) { - return new ReadOnlyCollection(new List(0)); + return ReadOnlyCollection.Empty; } // Get list of paragraphs @@ -598,7 +598,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. @@ -612,7 +612,7 @@ private ReadOnlyCollection GetChildrenParagraphResults(out bool if (trackDetails.cParas == 0) { - return new ReadOnlyCollection(new List(0)); + return ReadOnlyCollection.Empty; } // Get list of paragraphs @@ -739,7 +739,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 934c03b2de4..01b751d9178 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 @@ -581,7 +581,7 @@ private ReadOnlyCollection GetChildrenParagraphResults(out bool if (trackDetails.cParas == 0) { - return new ReadOnlyCollection(new List(0)); + return ReadOnlyCollection.Empty; } // Get list of paragraphs @@ -607,7 +607,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. @@ -621,7 +621,7 @@ private ReadOnlyCollection GetChildrenParagraphResults(out bool if (trackDetails.cParas == 0) { - return new ReadOnlyCollection(new List(0)); + return ReadOnlyCollection.Empty; } // Get list of paragraphs @@ -748,7 +748,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 ae8dead2c0d..70bcb9b4a67 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 502bdbada89..a7bf05a3bc0 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 @@ -588,7 +588,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; } @@ -3524,7 +3524,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 6a3dce73073..8e3fecf2cd3 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 @@ -451,7 +451,7 @@ public IEnumerator HostedElements } else { - return new HostedElements(new ReadOnlyCollection(new List(0))); + return new HostedElements(ReadOnlyCollection.Empty); } } } @@ -467,7 +467,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 55cf0579fdd..4fe86841567 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 d53b56254eb..f5919fec380 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 @@ -59,7 +59,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 85cb7186abc..39177bc5535 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; @@ -94,7 +95,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 5f6a1a38d9b..98d8a04aeda 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; @@ -358,7 +359,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 d769f96d4d4..af42da7d39e 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 @@ -243,7 +243,7 @@ public IList AllowedContentTypes if (_reflector.AllowedContentTypes is null) { _reflector.AllowedContentTypes = LookupAllowedContentTypes() ?? - EmptyList.Value; + ReadOnlyCollection.Empty; } return _reflector.AllowedContentTypes; @@ -263,7 +263,7 @@ public IList ContentWrappers if (_reflector.ContentWrappers is null) { _reflector.ContentWrappers = LookupContentWrappers() ?? - EmptyList.Value; + ReadOnlyCollection.Empty; } return _reflector.ContentWrappers; @@ -635,7 +635,7 @@ internal ICollection GetAllExcludedReadOnlyMembers() EnsureReflector(); if (_reflector.ExcludedReadOnlyMembers is null) { - _reflector.ExcludedReadOnlyMembers = LookupAllExcludedReadOnlyMembers() ?? EmptyList.Value; + _reflector.ExcludedReadOnlyMembers = LookupAllExcludedReadOnlyMembers() ?? ReadOnlyCollection.Empty; } return _reflector.ExcludedReadOnlyMembers; @@ -647,7 +647,7 @@ internal IEnumerable GetConstructors() { if (UnderlyingType is null) { - return EmptyList.Value; + return ReadOnlyCollection.Empty; } if (IsPublic) @@ -725,7 +725,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); @@ -1571,7 +1571,7 @@ internal static ReadOnlyCollection GetReadOnly(IList list) return new ReadOnlyCollection(list); } - return EmptyList.Value; + return ReadOnlyCollection.Empty; } private static ReadOnlyCollection GetTypeArguments(IList typeArguments) @@ -1957,11 +1957,5 @@ private static bool TypeArgumentsAreEqual(XamlType xamlType1, XamlType xamlType2 } #endregion - - internal static class EmptyList - { - public static readonly ReadOnlyCollection Value = - new ReadOnlyCollection(Array.Empty()); - } } }