Skip to content

Commit 3a3e2a3

Browse files
Replace PartialList with ReadOnlyCollection (#9890)
* Replace PartialList with ReadOnlyCollection * PR feedback
1 parent e8455dc commit 3a3e2a3

File tree

3 files changed

+5
-31
lines changed

3 files changed

+5
-31
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapPalette.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using MS.Internal;
66
using MS.Win32.PresentationCore;
7+
using System.Collections.ObjectModel;
78
using System.Windows.Threading;
89
using System.Runtime.InteropServices;
910

@@ -44,7 +45,7 @@ public BitmapPalette(IList<Color> colors)
4445
colorArray[i] = colors[i];
4546
}
4647

47-
_colors = new PartialList<Color>(colorArray);
48+
_colors = new ReadOnlyCollection<Color>(colorArray);
4849

4950
_palette = CreateInternalPalette();
5051

@@ -330,7 +331,7 @@ private void UpdateManaged()
330331
}
331332
}
332333

333-
_colors = new PartialList<Color>(colors);
334+
_colors = new ReadOnlyCollection<Color>(colors);
334335
}
335336

336337
#endregion // Private Methods
@@ -365,7 +366,7 @@ private struct ImagePaletteColor
365366
// the behavior that we want.
366367
private SafeMILHandle _palette = null; // IWICPalette*
367368

368-
private IList<Color> _colors = new PartialList<Color>(new List<Color>());
369+
private IList<Color> _colors = ReadOnlyCollection<Color>.Empty;
369370
}
370371
}
371372

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/PixelFormat.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public IList<byte> Mask
6363
{
6464
get
6565
{
66-
return _mask != null ? new PartialList<byte>((byte[])_mask.Clone()) : null;
66+
return _mask != null ? new ReadOnlyCollection<byte>((byte[])_mask.Clone()) : null;
6767
}
6868
}
6969

src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/PartialList.cs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,6 @@ internal class PartialList<T> : IList<T>
3030
private int _initialIndex;
3131
private int _count;
3232

33-
/// <summary>
34-
/// Convenience constructor for taking in an entire list. Useful for creating a read-only
35-
/// version of the list.
36-
/// </summary>
37-
public PartialList(IList<T> list)
38-
{
39-
_list = list;
40-
_initialIndex = 0;
41-
_count = list.Count;
42-
}
43-
4433
public PartialList(IList<T> list, int initialIndex, int count)
4534
{
4635
// make sure early that the caller didn't miscalculate index and count
@@ -51,22 +40,6 @@ public PartialList(IList<T> list, int initialIndex, int count)
5140
_count = count;
5241
}
5342

54-
#if !PRESENTATION_CORE
55-
/// <summary>
56-
/// Creates new PartialList object only for true partial ranges.
57-
/// Otherwise, returns the original list.
58-
/// </summary>
59-
public static IList<T> Create(IList<T> list, int initialIndex, int count)
60-
{
61-
if (list == null)
62-
return null;
63-
64-
if (initialIndex == 0 && count == list.Count)
65-
return list;
66-
67-
return new PartialList<T>(list, initialIndex, count);
68-
}
69-
#endif
7043
#region IList<T> Members
7144

7245
public void RemoveAt(int index)

0 commit comments

Comments
 (0)