@@ -293,6 +293,7 @@ internal static ArraySegment<T> Slice<T>(this T[] array, int offset)
293
293
return new ArraySegment < T > ( array , offset , array . Length - offset ) ;
294
294
}
295
295
296
+ #if NETSTANDARD2_0
296
297
internal static ArraySegment < T > Slice < T > ( this ArraySegment < T > array , int offset )
297
298
{
298
299
return new ArraySegment < T > ( array . Array , array . Offset + offset , array . Count - offset ) ;
@@ -302,6 +303,7 @@ internal static ArraySegment<T> Slice<T>(this ArraySegment<T> array, int offset,
302
303
{
303
304
return new ArraySegment < T > ( array . Array , array . Offset + offset , count ) ;
304
305
}
306
+ #endif
305
307
306
308
internal static T [ ] CloneArray < T > ( this T [ ] srcArray )
307
309
{
@@ -438,6 +440,70 @@ public static void SanitizeTangents(this IList<Vector4> tangents)
438
440
}
439
441
}
440
442
443
+ public static IReadOnlyList < TResult > SelectList < TSource , TResult > ( this IReadOnlyList < TSource > collection , Func < TSource , TResult > selector )
444
+ {
445
+ return new _ListSelect < TSource , TResult > ( collection , selector ) ;
446
+ }
447
+
448
+ public static IReadOnlyCollection < TResult > SelectCollection < TSource , TResult > ( this IReadOnlyCollection < TSource > collection , Func < TSource , TResult > selector )
449
+ {
450
+ return new _CollectionSelect < TSource , TResult > ( collection , selector ) ;
451
+ }
452
+
453
+ private readonly struct _ListSelect < TSource , TResult > : IReadOnlyList < TResult >
454
+ {
455
+ public _ListSelect ( IReadOnlyList < TSource > list , Func < TSource , TResult > selector )
456
+ {
457
+ _List = list ;
458
+ _Selector = selector ;
459
+ }
460
+
461
+ [ System . Diagnostics . DebuggerBrowsable ( System . Diagnostics . DebuggerBrowsableState . RootHidden ) ]
462
+ private readonly IReadOnlyList < TSource > _List ;
463
+ [ System . Diagnostics . DebuggerBrowsable ( System . Diagnostics . DebuggerBrowsableState . Never ) ]
464
+ private readonly Func < TSource , TResult > _Selector ;
465
+
466
+ public TResult this [ int index ] => _Selector ( _List [ index ] ) ;
467
+
468
+ public int Count => _List . Count ;
469
+
470
+ public IEnumerator < TResult > GetEnumerator ( )
471
+ {
472
+ foreach ( var item in _List ) yield return _Selector ( item ) ;
473
+ }
474
+
475
+ System . Collections . IEnumerator System . Collections . IEnumerable . GetEnumerator ( )
476
+ {
477
+ foreach ( var item in _List ) yield return _Selector ( item ) ;
478
+ }
479
+ }
480
+
481
+ private readonly struct _CollectionSelect < TSource , TResult > : IReadOnlyCollection < TResult >
482
+ {
483
+ public _CollectionSelect ( IReadOnlyCollection < TSource > list , Func < TSource , TResult > selector )
484
+ {
485
+ _List = list ;
486
+ _Selector = selector ;
487
+ }
488
+
489
+ [ System . Diagnostics . DebuggerBrowsable ( System . Diagnostics . DebuggerBrowsableState . RootHidden ) ]
490
+ private readonly IReadOnlyCollection < TSource > _List ;
491
+ [ System . Diagnostics . DebuggerBrowsable ( System . Diagnostics . DebuggerBrowsableState . Never ) ]
492
+ private readonly Func < TSource , TResult > _Selector ;
493
+
494
+ public int Count => _List . Count ;
495
+
496
+ public IEnumerator < TResult > GetEnumerator ( )
497
+ {
498
+ foreach ( var item in _List ) yield return _Selector ( item ) ;
499
+ }
500
+
501
+ System . Collections . IEnumerator System . Collections . IEnumerable . GetEnumerator ( )
502
+ {
503
+ foreach ( var item in _List ) yield return _Selector ( item ) ;
504
+ }
505
+ }
506
+
441
507
#endregion
442
508
443
509
#region vertex & index accessors
@@ -777,12 +843,12 @@ private static Byte[] _TryParseBase64Unchecked(string uri, string prefix)
777
843
public static string _EscapeStringInternal ( this string uri )
778
844
{
779
845
// https://stackoverflow.com/questions/4396598/whats-the-difference-between-escapeuristring-and-escapedatastring
780
- #pragma warning disable SYSLIB0013 // Type or member is obsolete
846
+ #pragma warning disable SYSLIB0013 // Type or member is obsolete
781
847
return Uri . EscapeUriString ( uri ) ;
782
- #pragma warning restore SYSLIB0013 // Type or member is obsolete
848
+ #pragma warning restore SYSLIB0013 // Type or member is obsolete
783
849
}
784
850
785
- #if NET6_0
851
+ #if NET6_0
786
852
787
853
/// <summary>
788
854
/// Creates a new instance of the <see cref="JsonNode"/>.
@@ -794,11 +860,11 @@ public static string _EscapeStringInternal(this string uri)
794
860
/// </remarks>
795
861
/// <param name="node">The node to clone.</param>
796
862
/// <returns>A clone of <paramref name="node"/>.</returns>
797
- #if NET6_0_OR_GREATER
863
+ #if NET6_0_OR_GREATER
798
864
[ System . Diagnostics . CodeAnalysis . DynamicDependency ( System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . All , typeof ( System . Text . Json . Nodes . JsonValue ) ) ]
799
865
[ System . Diagnostics . CodeAnalysis . DynamicDependency ( System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . All , typeof ( System . Text . Json . Nodes . JsonArray ) ) ]
800
866
[ System . Diagnostics . CodeAnalysis . DynamicDependency ( System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . All , typeof ( System . Text . Json . Nodes . JsonObject ) ) ]
801
- #endif
867
+ #endif
802
868
public static System . Text . Json . Nodes . JsonNode DeepClone ( this System . Text . Json . Nodes . JsonNode node )
803
869
{
804
870
// issue tracking both DeepClone and DeepEquals: https://github.com/dotnet/runtime/issues/56592
@@ -807,14 +873,14 @@ public static System.Text.Json.Nodes.JsonNode DeepClone(this System.Text.Json.No
807
873
808
874
System . Text . Json . Nodes . JsonNode clone = null ;
809
875
810
- #pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
876
+ #pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
811
877
switch ( node )
812
878
{
813
879
case System . Text . Json . Nodes . JsonValue asValue : clone = System . Text . Json . JsonSerializer . Deserialize < System . Text . Json . Nodes . JsonValue > ( asValue ) ; break ;
814
880
case System . Text . Json . Nodes . JsonArray asArray : clone = System . Text . Json . JsonSerializer . Deserialize < System . Text . Json . Nodes . JsonArray > ( asArray ) ; break ;
815
881
case System . Text . Json . Nodes . JsonObject asObject : clone = System . Text . Json . JsonSerializer . Deserialize < System . Text . Json . Nodes . JsonObject > ( asObject ) ; break ;
816
882
}
817
- #pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
883
+ #pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
818
884
819
885
if ( clone == null ) throw new NotImplementedException ( ) ;
820
886
@@ -823,15 +889,15 @@ public static System.Text.Json.Nodes.JsonNode DeepClone(this System.Text.Json.No
823
889
return clone ;
824
890
}
825
891
826
- #endif
892
+ #endif
827
893
828
894
public static bool DeepEquals ( this System . Text . Json . Nodes . JsonNode x , System . Text . Json . Nodes . JsonNode y , double precission )
829
895
{
830
- #if ! NET6_0
896
+ #if ! NET6_0
831
897
832
898
return System . Text . Json . Nodes . JsonNode . DeepEquals ( x , y ) ;
833
899
834
- #else
900
+ #else
835
901
836
902
if ( x == y ) return true ;
837
903
if ( x == null ) return false ;
@@ -888,7 +954,7 @@ public static bool DeepEquals(this System.Text.Json.Nodes.JsonNode x, System.Tex
888
954
889
955
return false ;
890
956
891
- #endif
957
+ #endif
892
958
}
893
959
894
960
#endregion
0 commit comments