Skip to content

Commit 72bef01

Browse files
authored
Polyfill static readonly properties from System.Collections.ObjectModel (#349)
1 parent 42ea325 commit 72bef01

4 files changed

Lines changed: 3 additions & 37 deletions

File tree

src/core/Microsoft.Dynamic/Microsoft.Dynamic.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
99
<EmitCompilerGeneratedFiles>True</EmitCompilerGeneratedFiles>
1010
<MeziantouPolyfill_IncludedPolyfills>
11-
None
11+
P:System.Collections.ObjectModel.ReadOnlyCollection`1.Empty;
12+
P:System.Collections.ObjectModel.ReadOnlyDictionary`2.Empty;
1213
</MeziantouPolyfill_IncludedPolyfills>
1314
</PropertyGroup>
1415

src/core/Microsoft.Dynamic/Utils/CollectionExtensions.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -127,27 +127,6 @@ internal static T[] RotateRight<T>(this T[] array, int count) {
127127
Array.Copy(array, sizeOfShiftedArray, result, 0, count);
128128
return result;
129129
}
130-
131-
#if !NET8_0_OR_GREATER
132-
// Emulates ReadOnlyCollection<T>.Empty form .NET 8.0+ with what is available in .NET Framework et al.
133-
// See also polyfill in Microsoft.Scripting.Utils.CollectionExtensions
134-
extension<T>(ReadOnlyCollection<T>) {
135-
internal static ReadOnlyCollection<T> Empty => EmptyReadOnlyCollection<T>.Instance;
136-
}
137-
138-
private static class EmptyReadOnlyCollection<T> {
139-
internal static readonly ReadOnlyCollection<T> Instance = new(Array.Empty<T>());
140-
}
141-
142-
// Emulates ReadOnlyDictionary<TKey,TValue>.Empty from .NET 8.0+ with what is available in .NET Framework et al.
143-
extension<TKey, TValue>(ReadOnlyDictionary<TKey, TValue>) {
144-
internal static ReadOnlyDictionary<TKey, TValue> Empty => EmptyReadOnlyDictionary<TKey, TValue>.Instance;
145-
}
146-
147-
private static class EmptyReadOnlyDictionary<TKey, TValue> {
148-
internal static readonly ReadOnlyDictionary<TKey, TValue> Instance = new(new Dictionary<TKey, TValue>());
149-
}
150-
#endif
151130
}
152131

153132
internal static class EmptyArray<T> {

src/core/Microsoft.Scripting/Microsoft.Scripting.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<GenerateDocumentationFile>true</GenerateDocumentationFile>
77
<EmitCompilerGeneratedFiles>True</EmitCompilerGeneratedFiles>
88
<MeziantouPolyfill_IncludedPolyfills>
9-
None
9+
P:System.Collections.ObjectModel.ReadOnlyCollection`1.Empty;
1010
</MeziantouPolyfill_IncludedPolyfills>
1111
</PropertyGroup>
1212

src/core/Microsoft.Scripting/Utils/CollectionExtensions.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,5 @@ internal static ReadOnlyCollection<T> ToReadOnlyCollection<T>(this IEnumerable<T
3232
},
3333
};
3434
}
35-
36-
37-
#if !NET8_0_OR_GREATER
38-
// Emulates ReadOnlyCollection<T>.Empty form .NET 8.0+ with what is available in .NET Framework et al.
39-
extension<T>(ReadOnlyCollection<T>) {
40-
internal static ReadOnlyCollection<T> Empty => EmptyReadOnlyCollection<T>.Instance;
41-
}
42-
43-
// CS9282: Extension declarations can include only methods or properties
44-
// so a readonly field must be in a separate static class.
45-
private static class EmptyReadOnlyCollection<T> {
46-
internal static readonly ReadOnlyCollection<T> Instance = new(Array.Empty<T>());
47-
}
48-
#endif
4935
}
5036
}

0 commit comments

Comments
 (0)