From ed34b103c41c8a3f678ad59fe889048966fc89d5 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Wed, 7 Jul 2021 22:25:27 +0100 Subject: [PATCH] Refactor the source generator to be public --- .editorconfig | 21 +- .github/workflows/dotnetcore.yml | 5 +- .../NetFabric.Hyperlinq.Benchmarks.csproj | 2 + .../NetFabric.Hyperlinq.Immutable.csproj | 55 --- .../CollectExtensionMethodsTests.cs | 49 --- .../GenerateSourceTests.cs | 300 ++++--------- ...Hyperlinq.SourceGenerator.UnitTests.csproj | 8 +- ...e.TestEnumerableWithValueTypeEnumerator.cs | 42 ++ .../AsValueEnumerable.IReadOnlyList.cs | 103 +++++ .../Results/AsValueEnumerable.Repeat.cs | 17 + .../AsValueEnumerable.TestCollection.cs | 68 +++ ...erableWithInterfacelessPublicEnumerator.cs | 57 +++ ...umerable.TestEnumerableWithNoInterfaces.cs | 55 +++ ...erfacesButEnumeratorWithResetAndDispose.cs | 56 +++ ...stEnumerableWithReferenceTypeEnumerator.cs | 37 ++ ...e.TestEnumerableWithValueTypeEnumerator.cs | 37 ++ .../Results/AsValueEnumerable.TestList.cs | 85 ++++ ...umerable.TestListWithExplicitInterfaces.cs | 85 ++++ ...sValueEnumerable.TestReadOnlyCollection.cs | 74 ++++ .../AsValueEnumerable.TestReadOnlyList.cs | 103 +++++ .../AsValueEnumerable.TestValueEnumerable.cs | 17 + .../TestData/Results/Count.Array.cs | 17 + .../TestData/Results/Count.Span.cs | 16 + .../TestData/Results/Dictionary.Select.cs | 30 -- .../TestData/Results/Dictionary.Where.cs | 30 -- .../Results/Distinct.ValueEnumerable.Where.cs | 36 -- .../TestData/Results/Empty.cs | 13 + .../TestData/Results/Range.Count.cs | 20 - .../TestData/Results/Range.Select.cs | 30 -- .../TestData/Results/Range.Where.cs | 30 -- .../TestData/Results/Repeat.Count.cs | 20 - .../Results/Select.ArraySegment.Any.cs | 30 -- .../Results/Select.ValueEnumerable.Any.cs | 36 -- .../Results/Select.ValueEnumerable.First.cs | 23 - .../Results/Select.ValueEnumerable.Where.cs | 30 -- .../Results/Where.ArraySegment.Count.cs | 23 - .../Results/Where.ValueEnumerable.Count.cs | 23 - .../Results/Where.ValueEnumerable.Distinct.cs | 23 - .../Results/Where.ValueEnumerable.First.cs | 23 - .../Results/Where.ValueEnumerable.Select.cs | 30 -- .../TestData/Source/Any.ArraySegment.cs | 20 - .../TestData/Source/Any.ValueEnumerable.cs | 26 -- .../Source/Any.ValueReadOnlyCollection.cs | 30 -- .../TestData/Source/Any.ValueReadOnlyList.cs | 28 -- ...e.TestEnumerableWithValueTypeEnumerator.cs | 13 + .../Source/AsValueEnumerable.Empty.cs | 28 ++ .../Source/AsValueEnumerable.Empty2.cs | 27 ++ .../Source/AsValueEnumerable.IReadOnlyList.cs | 17 + .../Source/AsValueEnumerable.Repeat.cs | 13 + .../AsValueEnumerable.TestCollection.cs | 15 + ...erableWithInterfacelessPublicEnumerator.cs | 20 + ...umerable.TestEnumerableWithNoInterfaces.cs | 17 + ...erfacesButEnumeratorWithResetAndDispose.cs | 20 + ...stEnumerableWithReferenceTypeEnumerator.cs | 19 + ...e.TestEnumerableWithValueTypeEnumerator.cs | 19 + .../Source/AsValueEnumerable.TestList.cs | 15 + ...umerable.TestListWithExplicitInterfaces.cs | 15 + ...sValueEnumerable.TestReadOnlyCollection.cs | 15 + .../AsValueEnumerable.TestReadOnlyList.cs | 15 + .../AsValueEnumerable.TestValueEnumerable.cs | 15 + .../TestData/Source/Common/Enumerables.cs | 327 ++++++++++++++ .../TestData/Source/Common/IFunction.cs | 7 - .../Source/Common/IFunctionWrapper.cs | 16 - .../Source/Common/IValueEnumerable.cs | 31 -- .../TestData/Source/Common/ItemTypes.cs | 7 + .../TestData/Source/Common/Option.cs | 8 - .../Source/Common/PredicateCombination.cs | 17 - .../Source/Common/SelectorCombination.cs | 17 - .../Source/Common/ValueEnumerables.cs | 45 ++ .../Source/Contains.ValueEnumerable.cs | 18 - .../TestData/Source/Count.Array.cs | 13 + .../TestData/Source/Count.Span.cs | 16 + .../TestData/Source/Count.ValueEnumerable.cs | 12 - .../TestData/Source/Dictionary.Bindings.cs | 57 --- .../TestData/Source/Distinct.ArraySegment.cs | 56 --- .../Source/Distinct.ValueEnumerable.cs | 60 --- .../TestData/Source/ExtensionMethods.cs | 21 - .../TestData/Source/First.ValueEnumerable.cs | 15 - .../TestData/Source/NoExtensionMethods.cs | 41 -- .../TestData/Source/Range.cs | 88 ---- .../TestData/Source/Repeat.cs | 139 ------ .../TestData/Source/Select.ArraySegment.cs | 115 ----- .../TestData/Source/Select.ValueEnumerable.cs | 79 ---- .../Source/ToDictionary.ArraySegment.cs | 46 -- .../TestData/Source/Where.ArraySegment.cs | 80 ---- .../TestData/Source/Where.ValueEnumerable.cs | 86 ---- .../Verifier.cs | 25 +- .../CompilationContext.cs | 1 + .../Generator.AsValueEnumerable.cs | 403 +++++++++++++++++ .../Generator.cs | 234 ++++++++++ .../MethodSignature.cs | 37 ++ ...NetFabric.Hyperlinq.SourceGenerator.csproj | 58 ++- .../OverloadsGenerator.cs | 409 ------------------ .../SyntaxReceiver.cs | 33 ++ .../TypeSymbolsCache.cs | 50 +++ .../Utils/CodeBuilder.cs | 29 +- .../ValueEnumerableType.cs | 6 + .../NetFabric.Hyperlinq.UnitTests.csproj | 1 + .../Utils/Wrappers/Wrap.AsAsyncEnumerable.cs | 6 +- .../Wrappers/Wrap.AsAsyncValueEnumerable.cs | 4 - .../Utils/Wrappers/Wrap.AsEnumerable.cs | 4 - .../Utils/Wrappers/Wrap.AsValueEnumerable.cs | 4 - NetFabric.Hyperlinq.sln | 10 +- .../Aggregation/Count/Count.ReadOnlySpan.cs | 4 +- .../Aggregation/Sum/Sum.Range.cs | 1 - .../Aggregation/Sum/Sum.ReadOnlySpan.cs | 16 +- .../Aggregation/Sum/Sum.ValueEnumerable.cs | 12 +- .../Sum/Sum.ValueReadOnlyCollection.cs | 12 +- .../Sum/SumAsync.AsyncValueEnumerable.cs | 12 +- ...cValueEnumerable'1.AsyncValueEnumerable.cs | 1 - ...sAsyncValueEnumerable'6.AsyncEnumerable.cs | 10 +- ...cValueEnumerable'6.AsyncValueEnumerable.cs | 9 +- .../AsValueEnumerable'1.Enumerable.cs | 101 ----- .../AsValueEnumerable'1.ReadOnlyCollection.cs | 187 -------- .../AsValueEnumerable'1.ReadOnlyList.cs | 277 ------------ .../AsValueEnumerable'1.ValueEnumerable.cs | 120 ----- ...lueEnumerable'1.ValueReadOnlyCollection.cs | 195 --------- .../AsValueEnumerable'6.Enumerable.cs | 209 --------- .../AsValueEnumerable'6.ReadOnlyCollection.cs | 308 ------------- .../AsValueEnumerable'6.ValueEnumerable.cs | 212 --------- ...lueEnumerable'6.ValueReadOnlyCollection.cs | 317 -------------- .../AsValueEnumerable'6.ValueReadOnlyList.cs | 384 ---------------- .../AsValueEnumerable.Array.cs | 1 - .../AsValueEnumerable.ArraySegment.cs | 227 +--------- ...cs => AsValueEnumerable.ImmutableArray.cs} | 0 ...xtensions.cs => AsValueEnumerable.List.cs} | 0 .../AsValueEnumerable.Memory.cs | 3 +- .../AsValueEnumerable.ReadOnlyMemory.cs | 3 +- .../AsValueEnumerable.ReadOnlySpan.cs | 115 +---- .../AsValueEnumerable.Span.cs | 4 +- .../Generic/DictionaryExtensions.cs | 47 -- .../Collections/Generic/HashSetExtensions.cs | 24 - .../Generic/LinkedListExtensions.cs | 24 - .../Generic/PriorityQueueExtensions.cs | 29 -- .../Collections/Generic/QueueExtensions.cs | 24 - .../Generic/SortedDictionaryExtensions.cs | 47 -- .../Generic/SortedSetExtensions.cs | 24 - .../Collections/Generic/StackExtensions.cs | 24 - .../ImmutableDictionaryExtensions.cs | 27 -- .../Immutable/ImmutableHashSetExtensions.cs | 24 - .../Immutable/ImmutableListExtensions.cs | 24 - .../Immutable/ImmutableQueueExtensions.cs | 36 -- .../ImmutableSortedDictionaryExtensions.cs | 27 -- .../Immutable/ImmutableStackExtensions.cs | 36 -- .../ToArray/ToArray.ReadOnlySpan.cs | 24 +- .../ToArray/ToArray.ValueEnumerable.cs | 20 +- .../ToArray.ValueReadOnlyCollection.cs | 20 +- .../ToArrayAsync.AsyncValueEnumerable.cs | 20 +- .../ToDictionary/ToDictionary.ReadOnlySpan.cs | 12 +- .../ToDictionary.ValueEnumerable.cs | 12 +- .../ToDictionary.ValueReadOnlyCollection.cs | 12 +- .../ToDictionaryAsync.AsyncValueEnumerable.cs | 12 +- .../Conversion/ToList/ToList.ReadOnlySpan.cs | 12 +- .../ToList/ToList.ValueEnumerable.cs | 10 +- .../ToList/ToList.ValueReadOnlyCollection.cs | 10 +- .../ToListAsync.AsyncValueEnumerable.cs | 10 +- .../ElementAt/ElementAt.ReadOnlyList.cs | 6 +- .../ElementAt/ElementAt.ReadOnlySpan.cs | 10 +- .../ElementAt/ElementAt.ValueEnumerable.cs | 10 +- .../ElementAt.ValueReadOnlyCollection.cs | 10 +- .../ElementAtAsync.AsyncValueEnumerable.cs | 10 +- .../Element/First/First.ReadOnlyList.cs | 6 +- .../Element/First/First.ReadOnlySpan.cs | 10 +- .../Element/First/First.ValueEnumerable.cs | 10 +- .../First/First.ValueReadOnlyCollection.cs | 10 +- .../First/FirstAsync.AsyncValueEnumerable.cs | 10 +- .../Element/Single/Single.ReadOnlyList.cs | 6 +- .../Element/Single/Single.ReadOnlySpan.cs | 6 +- .../Element/Single/Single.ValueEnumerable.cs | 16 +- .../Single/Single.ValueReadOnlyCollection.cs | 10 +- .../SingleAsync.AsyncValueEnumerable.cs | 16 +- .../SequenceEqual.ReadOnlySpan.cs | 2 +- .../Where/Where/Where.ArraySegment.cs | 64 +-- .../Where/Where/Where.AsyncValueEnumerable.cs | 1 - .../Where/Where/Where.ReadOnlyMemory.cs | 2 +- .../Where/Where/Where.ReadOnlySpan.cs | 1 - .../Where/Where/Where.ValueEnumerable.cs | 1 - .../Where/Where.ValueReadOnlyCollection.cs | 1 - .../Where/WhereAt/WhereAt.ArraySegment.cs | 63 ++- .../WhereAt/WhereAt.AsyncValueEnumerable.cs | 1 - .../Where/WhereAt/WhereAt.ReadOnlyMemory.cs | 1 - .../Where/WhereAt/WhereAt.ReadOnlySpan.cs | 1 - .../Where/WhereAt/WhereAt.ValueEnumerable.cs | 1 - .../WhereAt.ValueReadOnlyCollection.cs | 1 - .../WhereSelect/WhereSelect.ArraySegment.cs | 53 ++- .../WhereSelect.AsyncValueEnumerable.cs | 3 +- .../WhereSelect/WhereSelect.ReadOnlyMemory.cs | 3 +- .../WhereSelect/WhereSelect.ReadOnlySpan.cs | 3 +- .../WhereSelect.ValueEnumerable.cs | 3 +- .../WhereSelect.ValueReadOnlyCollection.cs | 3 +- .../Generation/AsyncValueEnumerable/Range.cs | 1 - .../Generation/ValueEnumerable/Range.cs | 29 +- .../NetFabric.Hyperlinq.csproj | 19 +- NetFabric.Hyperlinq/Option/Option.cs | 1 - .../Partitioning/Skip/Skip.ReadOnlyList.cs | 2 +- .../Partitioning/Take/Take.ReadOnlyList.cs | 2 +- .../Select/Select/Select.ArraySegment.cs | 44 +- .../Select/Select.AsyncValueEnumerable.cs | 2 - .../Select/Select/Select.ReadOnlyMemory.cs | 2 - .../Select/Select/Select.ReadOnlySpan.cs | 2 - .../Select/Select/Select.ValueEnumerable.cs | 2 - .../Select/Select.ValueReadOnlyCollection.cs | 2 - .../Select/Select/Select.ValueReadOnlyList.cs | 2 - .../Select/SelectAt/SelectAt.ArraySegment.cs | 17 +- .../SelectAt/SelectAt.AsyncValueEnumerable.cs | 2 - .../SelectAt/SelectAt.ReadOnlyMemory.cs | 2 - .../Select/SelectAt/SelectAt.ReadOnlySpan.cs | 2 - .../SelectAt/SelectAt.ValueEnumerable.cs | 2 - .../SelectAt.ValueReadOnlyCollection.cs | 2 - .../SelectAt/SelectAt.ValueReadOnlyList.cs | 2 - .../Select/SelectVector/SelectVector.Range.cs | 2 +- .../SelectVector/SelectVector.ReadOnlySpan.cs | 2 - .../SelectMany/SelectMany.ArraySegment.cs | 3 +- .../SelectMany/SelectMany.ReadOnlyMemory.cs | 3 +- .../SelectMany/SelectMany.ReadOnlySpan.cs | 3 +- .../SelectMany/SelectMany.ValueEnumerable.cs | 3 +- .../Contains/Contains.Enumerable.cs | 4 +- .../Contains/Contains.ReadOnlySpan.cs | 4 +- .../Contains/Contains.ValueEnumerable.cs | 4 +- .../Contains.ValueReadOnlyCollection.cs | 4 +- .../ContainsVector.ReadOnlySpan.cs | 2 +- .../ContainsVector/ContainsVector.Span.cs | 2 +- .../ToArrayBuilder.ReadOnlyList.cs | 6 +- .../ToArrayBuilder.ReadOnlySpan.cs | 6 +- .../ToArrayBuilder.ValueEnumerable.cs | 12 +- ...oArrayBuilderAsync.AsyncValueEnumerable.cs | 12 +- NetFabric.Hyperlinq/Utils/ArrayExtensions.cs | 16 + .../Utils/ArraySegmentExtensions.cs | 5 +- NetFabric.Hyperlinq/Utils/MemoryExtensions.cs | 12 + NetFabric.Hyperlinq/Utils/SpanExtensions.cs | 12 + README.md | 2 + 231 files changed, 2993 insertions(+), 5827 deletions(-) delete mode 100644 NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/CollectExtensionMethodsTests.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Count.Array.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Count.Span.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Select.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Where.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Distinct.ValueEnumerable.Where.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Empty.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Count.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Select.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Where.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Repeat.Count.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Any.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.First.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Where.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ArraySegment.Count.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Count.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Distinct.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.First.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Select.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueReadOnlyCollection.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.Empty.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.Empty2.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.IReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.Repeat.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestCollection.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestList.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestListWithExplicitInterfaces.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestReadOnlyCollection.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestReadOnlyList.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestValueEnumerable.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/Enumerables.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IFunction.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IFunctionWrapper.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IValueEnumerable.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/ItemTypes.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/Option.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/PredicateCombination.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/SelectorCombination.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/ValueEnumerables.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Contains.ValueEnumerable.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Count.Array.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Count.Span.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Count.ValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Dictionary.Bindings.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ExtensionMethods.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/First.ValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/NoExtensionMethods.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Range.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Repeat.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ToDictionary.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ValueEnumerable.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator/Generator.AsValueEnumerable.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator/Generator.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator/MethodSignature.cs delete mode 100644 NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator/SyntaxReceiver.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator/TypeSymbolsCache.cs create mode 100644 NetFabric.Hyperlinq.SourceGenerator/ValueEnumerableType.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs rename NetFabric.Hyperlinq/Conversion/AsValueEnumerable/{Bindings/System/Collections/Immutable/ImmutableArrayExtensions.cs => AsValueEnumerable.ImmutableArray.cs} (100%) rename NetFabric.Hyperlinq/Conversion/AsValueEnumerable/{Bindings/System/Collections/Generic/ListExtensions.cs => AsValueEnumerable.List.cs} (100%) delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/DictionaryExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSetExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedListExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueueExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/QueueExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionaryExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSetExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/StackExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionaryExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSetExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableListExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueueExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionaryExtensions.cs delete mode 100644 NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStackExtensions.cs create mode 100644 NetFabric.Hyperlinq/Utils/ArrayExtensions.cs create mode 100644 NetFabric.Hyperlinq/Utils/MemoryExtensions.cs create mode 100644 NetFabric.Hyperlinq/Utils/SpanExtensions.cs diff --git a/.editorconfig b/.editorconfig index 4cead120d..b4a841bef 100755 --- a/.editorconfig +++ b/.editorconfig @@ -68,14 +68,14 @@ csharp_style_var_for_built_in_types = true:error csharp_style_var_when_type_is_apparent = true:error # Expression-bodied members -csharp_style_expression_bodied_accessors = true:error -csharp_style_expression_bodied_constructors = true:error -csharp_style_expression_bodied_indexers = true:error -csharp_style_expression_bodied_lambdas = true:error -csharp_style_expression_bodied_local_functions = true:error -csharp_style_expression_bodied_methods = true:error -csharp_style_expression_bodied_operators = true:error -csharp_style_expression_bodied_properties = true:error +csharp_style_expression_bodied_accessors =true:warning +csharp_style_expression_bodied_constructors =true:warning +csharp_style_expression_bodied_indexers =true:warning +csharp_style_expression_bodied_lambdas =true:warning +csharp_style_expression_bodied_local_functions =true:warning +csharp_style_expression_bodied_methods =true:warning +csharp_style_expression_bodied_operators =true:warning +csharp_style_expression_bodied_properties =true:warning # Pattern matching preferences csharp_style_pattern_matching_over_as_with_null_check = true:error @@ -101,7 +101,7 @@ csharp_style_pattern_local_over_anonymous_function = true:error csharp_style_prefer_index_operator = true:warning csharp_style_prefer_range_operator = true:warning csharp_style_throw_expression = true:error -csharp_style_unused_value_assignment_preference = discard_variable:error +csharp_style_unused_value_assignment_preference =discard_variable:warning csharp_style_unused_value_expression_statement_preference = discard_variable:error # 'using' directive preferences @@ -216,3 +216,6 @@ dotnet_naming_style.camel_case.required_prefix = dotnet_naming_style.camel_case.required_suffix = dotnet_naming_style.camel_case.word_separator = dotnet_naming_style.camel_case.capitalization = camel_case + +[*.{cs,vb}] +dotnet_code_quality_unused_parameters=all:warning \ No newline at end of file diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index a6013e986..f8ebf0884 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -10,9 +10,10 @@ jobs: - name: Check out repository uses: actions/checkout@v2 - name: Setup .NET Core - uses: actions/setup-dotnet@v1.7.2 + uses: actions/setup-dotnet@v1 with: - dotnet-version: '6.0.100-preview.2.21155.3' + dotnet-version: '6.0.x' + include-prerelease: true - name: Test source generator run: dotnet test ./NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj - name: Build solution diff --git a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj index 794ee51ce..fabfaa4fb 100644 --- a/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj +++ b/NetFabric.Hyperlinq.Benchmarks/NetFabric.Hyperlinq.Benchmarks.csproj @@ -4,6 +4,7 @@ net6.0 false true + true @@ -15,6 +16,7 @@ + diff --git a/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj b/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj deleted file mode 100644 index f433a0dbc..000000000 --- a/NetFabric.Hyperlinq.Immutable/NetFabric.Hyperlinq.Immutable.csproj +++ /dev/null @@ -1,55 +0,0 @@ - - - - netstandard2.0 - NetFabric.Hyperlinq.Immutable - NetFabric.Hyperlinq.Immutable - High performance LINQ implementation with minimal heap allocations. Supports all collections in System.Collections.Immutable. - 1.0.0-beta01 - Icon.png - LICENSE - netfabric, hyperlinq, linq, enumeration, extensions, performance - true - - - - - - - - - - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers - - - all - runtime; build; native; contentfiles; analyzers - - - all - runtime; build; native; contentfiles; analyzers - - - - - - - - - - - - - - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/CollectExtensionMethodsTests.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/CollectExtensionMethodsTests.cs deleted file mode 100644 index 1bf2b271d..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/CollectExtensionMethodsTests.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Microsoft.CodeAnalysis; -using NetFabric.Assertive; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Xunit; - -namespace NetFabric.Hyperlinq.SourceGenerator.UnitTests -{ - public class CollectExtensionMethodsTests - { - public static TheoryData ExtensionMethods - => new() - { - { new[] { "TestData/Source/NoExtensionMethods.cs" }, 0 }, - { new[] { "TestData/Source/ExtensionMethods.cs" }, 3 }, - - { new[] { "TestData/Source/Distinct.ArraySegment.cs" }, 1}, - { new[] { "TestData/Source/Count.ValueEnumerable.cs" }, 1 }, - { new[] { "TestData/Source/Distinct.ValueEnumerable.cs" }, 1 }, - - { new[] { "TestData/Source/Where.ArraySegment.cs" }, 2 }, - { new[] { "TestData/Source/Select.ArraySegment.cs" }, 2 }, - { new[] { "TestData/Source/Where.ValueEnumerable.cs" }, 2 }, - { new[] { "TestData/Source/Select.ValueEnumerable.cs" }, 2 }, - }; - - [Theory] - [MemberData(nameof(ExtensionMethods))] - public async Task ShouldCollectExpectedNumberOfExtensionMethods(string[] paths, int expected) - { - // Arrange - var generator = new OverloadsGenerator(); - var project = Verifier.CreateProject( - paths - .Concat(Directory.EnumerateFiles("TestData/Source/Common", "*.cs", SearchOption.AllDirectories)) - .Concat(Directory.EnumerateFiles("../../../../NetFabric.Hyperlinq.SourceGenerator/Attributes/", "*.cs", SearchOption.AllDirectories)) - .Select(path => File.ReadAllText(path))); - var context = new CompilationContext(await project.GetCompilationAsync().ConfigureAwait(false) ?? throw new System.Exception("Error getting compilation!")); - - // Act - var result = generator.CollectExtensionMethods(context); - - // Assert - _ = result.Count.Must() - .BeEqualTo(expected); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/GenerateSourceTests.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/GenerateSourceTests.cs index 44078968f..6f5207d5f 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/GenerateSourceTests.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/GenerateSourceTests.cs @@ -1,7 +1,8 @@ -using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; using NetFabric.Assertive; using System.IO; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Xunit; @@ -9,233 +10,114 @@ namespace NetFabric.Hyperlinq.SourceGenerator.UnitTests { public class GenerateSourceTests { - public static TheoryData ClassesWithOverloads + public static TheoryData GeneratorSources => new() { - new[] { - "TestData/Source/Count.ValueEnumerable.cs", + { + new[] { "TestData/Source/AsValueEnumerable.Empty.cs" }, + "TestData/Results/Empty.cs" }, - new[] { - "TestData/Source/Where.ValueEnumerable.cs", + { + new[] { "TestData/Source/AsValueEnumerable.Empty2.cs" }, + "TestData/Results/Empty.cs" }, - new[] { - "TestData/Source/Select.ValueEnumerable.cs", + { + new[] { "TestData/Source/AsValueEnumerable.Repeat.cs" }, + "TestData/Results/AsValueEnumerable.Repeat.cs" }, - }; - - [Theory] - [MemberData(nameof(ClassesWithOverloads))] - public async Task ClassesWithOverloadsShouldNotGenerate(string[] paths) - { - // Arrange - var generator = new OverloadsGenerator(); - var project = Verifier.CreateProject( - paths - .Concat(Directory.EnumerateFiles("TestData/Source/Common", "*.cs", SearchOption.AllDirectories)) - .Concat(Directory.EnumerateFiles("../../../../NetFabric.Hyperlinq.SourceGenerator/Attributes/", "*.cs", SearchOption.AllDirectories)) - .Select(path => File.ReadAllText(path))); - var context = new CompilationContext(await project.GetCompilationAsync().ConfigureAwait(false) ?? throw new System.Exception("Error getting compilation!")); - // Act - var extensionMethods = generator.CollectExtensionMethods(context); - var result = generator.GenerateSource(extensionMethods, context); - - // Assert - _ = result.Must() - .BeEnumerableOf<(INamedTypeSymbol, INamedTypeSymbol, string)>() - .BeEmpty(); - } - - // ----------------------------------------------------- - - public static TheoryData GeneratorSources - => new() - { { - new[] { - "TestData/Source/Range.cs", - "TestData/Source/Contains.ValueEnumerable.cs", - }, - new string[] { - } - }, - { - new[] { - "TestData/Source/Select.ArraySegment.cs", - "TestData/Source/Contains.ValueEnumerable.cs", - }, - new string[] { - } - }, - { - new[] { - "TestData/Source/Range.cs", - "TestData/Source/Count.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Range.Count.cs", - } - }, - { - new[] { - "TestData/Source/Repeat.cs", - "TestData/Source/Count.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Repeat.Count.cs", - } - }, - { - new[] { - "TestData/Source/Range.cs", - "TestData/Source/Where.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Range.Where.cs", - } - }, - { - new[] { - "TestData/Source/Range.cs", - "TestData/Source/Select.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Range.Select.cs", - } - }, - { - new[] { - "TestData/Source/Count.ValueEnumerable.cs", - "TestData/Source/Where.ArraySegment.cs", - }, - new[] { - "TestData/Results/Where.ArraySegment.Count.cs", - } - }, - { - new[] { - "TestData/Source/Any.ArraySegment.cs", - "TestData/Source/Any.ValueReadOnlyList.cs", - "TestData/Source/Any.ValueEnumerable.cs", - "TestData/Source/Any.ValueReadOnlyCollection.cs", - "TestData/Source/Where.ValueEnumerable.cs", - }, - new string[] { - } - }, - { - new[] { - "TestData/Source/Any.ArraySegment.cs", - "TestData/Source/Any.ValueReadOnlyList.cs", - "TestData/Source/Any.ValueEnumerable.cs", - "TestData/Source/Any.ValueReadOnlyCollection.cs", - "TestData/Source/Select.ArraySegment.cs", - }, - new[] { - "TestData/Results/Select.ArraySegment.Any.cs", - } - }, - { - new[] { - "TestData/Source/Any.ArraySegment.cs", - "TestData/Source/Any.ValueReadOnlyList.cs", - "TestData/Source/Any.ValueEnumerable.cs", - "TestData/Source/Any.ValueReadOnlyCollection.cs", - "TestData/Source/Select.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Select.ValueEnumerable.Any.cs", - } - }, - { - new[] { - "TestData/Source/Count.ValueEnumerable.cs", - "TestData/Source/Where.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Where.ValueEnumerable.Count.cs", - } - }, - { - new[] { - "TestData/Source/First.ValueEnumerable.cs", - "TestData/Source/Where.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Where.ValueEnumerable.First.cs", - } - }, - { - new[] { - "TestData/Source/First.ValueEnumerable.cs", - "TestData/Source/Select.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Select.ValueEnumerable.First.cs", - } - }, - { - new[] { - "TestData/Source/Where.ValueEnumerable.cs", - "TestData/Source/Distinct.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Where.ValueEnumerable.Distinct.cs", - "TestData/Results/Distinct.ValueEnumerable.Where.cs", - } - }, - { - new[] { - "TestData/Source/Where.ValueEnumerable.cs", - "TestData/Source/Select.ValueEnumerable.cs", - }, - new[] { - "TestData/Results/Where.ValueEnumerable.Select.cs", - "TestData/Results/Select.ValueEnumerable.Where.cs", - } - }, - { - new[] { - "TestData/Source/Where.ValueEnumerable.cs", - "TestData/Source/Dictionary.Bindings.cs", - }, - new[] { - "TestData/Results/Dictionary.Where.cs", - } - }, - { - new[] { - "TestData/Source/Select.ValueEnumerable.cs", - "TestData/Source/Dictionary.Bindings.cs", - }, - new[] { - "TestData/Results/Dictionary.Select.cs", - } + new[] { "TestData/Source/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs" }, + "TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs" }, + "TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs" }, + "TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs" }, + "TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs" }, + "TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestCollection.cs" }, + "TestData/Results/AsValueEnumerable.TestCollection.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestReadOnlyCollection.cs" }, + "TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestList.cs" }, + "TestData/Results/AsValueEnumerable.TestList.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.IReadOnlyList.cs" }, + "TestData/Results/AsValueEnumerable.IReadOnlyList.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestListWithExplicitInterfaces.cs" }, + "TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestReadOnlyList.cs" }, + "TestData/Results/AsValueEnumerable.TestReadOnlyList.cs" + }, + { + new[] { "TestData/Source/AsValueEnumerable.TestValueEnumerable.cs" }, + "TestData/Results/AsValueEnumerable.TestValueEnumerable.cs" + }, + { + new[] { "TestData/Source/Count.Array.cs" }, + "TestData/Results/Count.Array.cs" + }, + //{ + // new[] { "TestData/Source/Count.Span.cs" }, + // "TestData/Results/Count.Span.cs" + //}, + { + new[] { "TestData/Source/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs" }, + "TestData/Results/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs" }, }; [Theory] [MemberData(nameof(GeneratorSources))] - public async Task GenerateSourceShouldGenerate(string[] paths, string[] expected) + public async Task GenerateSourceShouldGenerate(string[] paths, string expected) { // Arrange - var generator = new OverloadsGenerator(); - var project = Verifier.CreateProject( - paths + var sources = paths .Concat(Directory.EnumerateFiles("TestData/Source/Common", "*.cs", SearchOption.AllDirectories)) - .Concat(Directory.EnumerateFiles("../../../../NetFabric.Hyperlinq.SourceGenerator/Attributes/", "*.cs", SearchOption.AllDirectories)) - .Select(path => File.ReadAllText(path))); - var context = new CompilationContext(await project.GetCompilationAsync().ConfigureAwait(false) ?? throw new System.Exception("Error getting compilation!")); + .Select(path => File.ReadAllText(path)); + var project = Verifier.CreateProject(sources); + var compilation = await project.GetCompilationAsync().ConfigureAwait(false) + ?? throw new System.Exception("Error getting compilation!"); + //var errors = compilation + // .GetDiagnostics() + // .Where(diagnostic => diagnostic.Severity == DiagnosticSeverity.Error) + // .ToArray(); + //_ = errors.Must().BeEqualTo(Array.Empty()); + var typeSymbolsCache = new TypeSymbolsCache(compilation); + var memberAccessExpressions = compilation.SyntaxTrees + .SelectMany(tree => tree.GetRoot().DescendantNodes().OfType()) + .Where(memberAccess => Generator.methods.Contains(memberAccess.Name.Identifier.ValueText)) + .ToList(); // Act - var extensionMethods = generator.CollectExtensionMethods(context); - var result = generator.GenerateSource(extensionMethods, context); + var builder = new CodeBuilder(); + Generator.GenerateSource(compilation, typeSymbolsCache, memberAccessExpressions, builder, CancellationToken.None, true); + var result = builder.ToString(); // Assert - _ = result.Select(item => item.Source) - .ToArray() - .Must() - .BeEqualTo(expected.Select(path => File.ReadAllText(path))); + _ = result.Must() + .BeEqualTo(File.ReadAllText(expected)); } } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj index 6e60efb64..b273ec87a 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/NetFabric.Hyperlinq.SourceGenerator.UnitTests.csproj @@ -6,10 +6,16 @@ false + + NOT_TESTING + + + - + + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs new file mode 100644 index 000000000..2e6a8339a --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs @@ -0,0 +1,42 @@ +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + //[MethodImpl(MethodImplOptions.AggressiveInlining)] + //public static AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithValueTypeEnumerator source) + // => new(source, source); + + //public readonly struct AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_ + // : IValueEnumerable.Enumerator> + // where TEnumerable : IEnumerable + //{ + // readonly TestEnumerableWithValueTypeEnumerator source; + // readonly TEnumerable source2; + + // internal AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_(TestEnumerableWithValueTypeEnumerator source, TEnumerable source2) + // => (this.source, this.source2) = (source, source2); + + // // Implement IValueEnumerable.Enumerator> + + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public TestEnumerableWithValueTypeEnumerator.Enumerator GetEnumerator() => source.GetEnumerator(); + + // IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + // IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + //} + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int AsEnumerable(this GeneratedExtensionMethods.AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> source) + => source.AsEnumerable(); + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs new file mode 100644 index 000000000..aa330df50 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.IReadOnlyList.cs @@ -0,0 +1,103 @@ +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_System_Collections_Generic_IReadOnlyList_TestValueType_> AsValueEnumerable(this System.Collections.Generic.IReadOnlyList source) + => new(source, source); + + public readonly struct AsValueEnumerable_System_Collections_Generic_IReadOnlyList_TestValueType_ + : IValueReadOnlyList>, IList + where TEnumerable : IReadOnlyList + { + readonly System.Collections.Generic.IReadOnlyList source; + readonly TEnumerable source2; + + internal AsValueEnumerable_System_Collections_Generic_IReadOnlyList_TestValueType_(System.Collections.Generic.IReadOnlyList source, TEnumerable source2) + => (this.source, this.source2) = (source, source2); + + // Implement IValueEnumerable> + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueEnumerator GetEnumerator() => new(source2.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + // Implement ICollection + + public int Count => source2.Count; + + public bool IsReadOnly => true; + + void ICollection.Add(TestValueType item) => throw new NotSupportedException(); + + bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); + + void ICollection.Clear() => throw new NotSupportedException(); + + public void CopyTo(Span span) + { + if (Count is 0) return; + if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); + + var index = 0; + foreach (var current in this) + { + span[index] = current; + checked { index++; } + } + } + + public bool Contains(TestValueType item) + { + foreach (var current in this) + { + if (EqualityComparer.Default.Equals(current, item)) return true; + } + return true; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TestValueType[] array, int arrayIndex) => CopyTo(array.AsSpan(arrayIndex)); + + // Implement IList + + public TestValueType this[int index] => source2[index]; + + TestValueType IList.this[int index] + { + get => source2[index]; + set => throw new NotSupportedException(); + } + + void IList.Insert(int index, TestValueType item) => throw new NotSupportedException(); + + void IList.RemoveAt(int index) => throw new NotSupportedException(); + + public int IndexOf(TestValueType item) + { + if (Count is not 0) + { + var index = 0; + foreach (var current in this) + { + if (EqualityComparer.Default.Equals(current, item)) return index; + + checked { index++; } + } + } + return -1; + } + } + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs new file mode 100644 index 000000000..5715be1c1 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.Repeat.cs @@ -0,0 +1,17 @@ +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static NetFabric.Hyperlinq.ValueEnumerable.RepeatEnumerable AsValueEnumerable(this NetFabric.Hyperlinq.ValueEnumerable.RepeatEnumerable source) + => source; + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs new file mode 100644 index 000000000..9e5b1cdd3 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestCollection.cs @@ -0,0 +1,68 @@ +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestCollection_TestValueType_> AsValueEnumerable(this TestCollection source) + => new(source, source); + + public readonly struct AsValueEnumerable_TestCollection_TestValueType_ + : IValueReadOnlyCollection.Enumerator>, ICollection + where TEnumerable : ICollection + { + readonly TestCollection source; + readonly TEnumerable source2; + + internal AsValueEnumerable_TestCollection_TestValueType_(TestCollection source, TEnumerable source2) + => (this.source, this.source2) = (source, source2); + + // Implement IValueEnumerable.Enumerator> + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TestCollection.Enumerator GetEnumerator() => source.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + // Implement ICollection + + public int Count => source2.Count; + + public bool IsReadOnly => true; + + void ICollection.Add(TestValueType item) => throw new NotSupportedException(); + + bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); + + void ICollection.Clear() => throw new NotSupportedException(); + + public void CopyTo(Span span) + { + if (Count is 0) return; + if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); + + var index = 0; + foreach (var current in this) + { + span[index] = current; + checked { index++; } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Contains(TestValueType item) => source2.Contains(item); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TestValueType[] array, int arrayIndex) => source2.CopyTo(array, arrayIndex); + } + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs new file mode 100644 index 000000000..dfc22c790 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs @@ -0,0 +1,57 @@ +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestEnumerableWithInterfacelessPublicEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithInterfacelessPublicEnumerator source) + => new(source, source); + + public readonly struct AsValueEnumerable_TestEnumerableWithInterfacelessPublicEnumerator_TestValueType_ + : IValueEnumerable.Enumerator> + where TEnumerable : IEnumerable + { + readonly TestEnumerableWithInterfacelessPublicEnumerator source; + readonly TEnumerable source2; + + internal AsValueEnumerable_TestEnumerableWithInterfacelessPublicEnumerator_TestValueType_(TestEnumerableWithInterfacelessPublicEnumerator source, TEnumerable source2) + => (this.source, this.source2) = (source, source2); + + // Implement IValueEnumerable.Enumerator> + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator GetEnumerator() => new(source.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator()); + + public struct Enumerator : IEnumerator + { + readonly TestEnumerableWithInterfacelessPublicEnumerator.Enumerator source; + + internal Enumerator(TestEnumerableWithInterfacelessPublicEnumerator.Enumerator source) + => this.source = source; + + public TestValueType Current => source.Current; + + object? IEnumerator.Current => source.Current; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() => source.MoveNext(); + + public void Reset() => throw new NotSupportedException(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Dispose() { } + } + } + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs new file mode 100644 index 000000000..93e0ca3d3 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs @@ -0,0 +1,55 @@ +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestEnumerableWithNoInterfaces_TestValueType_ AsValueEnumerable(this TestEnumerableWithNoInterfaces source) + => new(source); + + public readonly struct AsValueEnumerable_TestEnumerableWithNoInterfaces_TestValueType_ + : IValueEnumerable + { + readonly TestEnumerableWithNoInterfaces source; + + internal AsValueEnumerable_TestEnumerableWithNoInterfaces_TestValueType_(TestEnumerableWithNoInterfaces source) + => this.source = source; + + // Implement IValueEnumerable + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator GetEnumerator() => new(source.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator()); + + public struct Enumerator : IEnumerator + { + readonly TestEnumerableWithNoInterfaces.Enumerator source; + + internal Enumerator(TestEnumerableWithNoInterfaces.Enumerator source) + => this.source = source; + + public TestValueType Current => source.Current; + + object? IEnumerator.Current => source.Current; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() => source.MoveNext(); + + public void Reset() => throw new NotSupportedException(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Dispose() { } + } + } + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs new file mode 100644 index 000000000..3149f501a --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs @@ -0,0 +1,56 @@ +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose_TestValueType_ AsValueEnumerable(this TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose source) + => new(source); + + public readonly struct AsValueEnumerable_TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose_TestValueType_ + : IValueEnumerable + { + readonly TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose source; + + internal AsValueEnumerable_TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose_TestValueType_(TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose source) + => this.source = source; + + // Implement IValueEnumerable + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Enumerator GetEnumerator() => new(source.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator()); + + public struct Enumerator : IEnumerator + { + readonly TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.Enumerator source; + + internal Enumerator(TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.Enumerator source) + => this.source = source; + + public TestValueType Current => source.Current; + + object? IEnumerator.Current => source.Current; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool MoveNext() => source.MoveNext(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Reset() => source.Reset(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Dispose() => source.Dispose(); + } + } + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs new file mode 100644 index 000000000..67d2d4b3a --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs @@ -0,0 +1,37 @@ +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestEnumerableWithReferenceTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithReferenceTypeEnumerator source) + => new(source, source); + + public readonly struct AsValueEnumerable_TestEnumerableWithReferenceTypeEnumerator_TestValueType_ + : IValueEnumerable> + where TEnumerable : IEnumerable + { + readonly TestEnumerableWithReferenceTypeEnumerator source; + readonly TEnumerable source2; + + internal AsValueEnumerable_TestEnumerableWithReferenceTypeEnumerator_TestValueType_(TestEnumerableWithReferenceTypeEnumerator source, TEnumerable source2) + => (this.source, this.source2) = (source, source2); + + // Implement IValueEnumerable> + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueEnumerator GetEnumerator() => new(source.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + } + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs new file mode 100644 index 000000000..c649a6fbd --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs @@ -0,0 +1,37 @@ +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_> AsValueEnumerable(this TestEnumerableWithValueTypeEnumerator source) + => new(source, source); + + public readonly struct AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_ + : IValueEnumerable.Enumerator> + where TEnumerable : IEnumerable + { + readonly TestEnumerableWithValueTypeEnumerator source; + readonly TEnumerable source2; + + internal AsValueEnumerable_TestEnumerableWithValueTypeEnumerator_TestValueType_(TestEnumerableWithValueTypeEnumerator source, TEnumerable source2) + => (this.source, this.source2) = (source, source2); + + // Implement IValueEnumerable.Enumerator> + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TestEnumerableWithValueTypeEnumerator.Enumerator GetEnumerator() => source.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + } + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs new file mode 100644 index 000000000..a7a48d428 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestList.cs @@ -0,0 +1,85 @@ +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestList_TestValueType_> AsValueEnumerable(this TestList source) + => new(source, source); + + public readonly struct AsValueEnumerable_TestList_TestValueType_ + : IValueReadOnlyList.Enumerator>, IList + where TEnumerable : IList + { + readonly TestList source; + readonly TEnumerable source2; + + internal AsValueEnumerable_TestList_TestValueType_(TestList source, TEnumerable source2) + => (this.source, this.source2) = (source, source2); + + // Implement IValueEnumerable.Enumerator> + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TestList.Enumerator GetEnumerator() => source.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + // Implement ICollection + + public int Count => source2.Count; + + public bool IsReadOnly => true; + + void ICollection.Add(TestValueType item) => throw new NotSupportedException(); + + bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); + + void ICollection.Clear() => throw new NotSupportedException(); + + public void CopyTo(Span span) + { + if (Count is 0) return; + if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); + + var index = 0; + foreach (var current in this) + { + span[index] = current; + checked { index++; } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Contains(TestValueType item) => source2.Contains(item); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TestValueType[] array, int arrayIndex) => source2.CopyTo(array, arrayIndex); + + // Implement IList + + public TestValueType this[int index] => source2[index]; + + TestValueType IList.this[int index] + { + get => source2[index]; + set => throw new NotSupportedException(); + } + + void IList.Insert(int index, TestValueType item) => throw new NotSupportedException(); + + void IList.RemoveAt(int index) => throw new NotSupportedException(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int IndexOf(TestValueType item) => source2.IndexOf(item); + } + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs new file mode 100644 index 000000000..0e5d7e3c4 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestListWithExplicitInterfaces.cs @@ -0,0 +1,85 @@ +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestListWithExplicitInterfaces_TestValueType_> AsValueEnumerable(this TestListWithExplicitInterfaces source) + => new(source, source); + + public readonly struct AsValueEnumerable_TestListWithExplicitInterfaces_TestValueType_ + : IValueReadOnlyList>, IList + where TEnumerable : IList + { + readonly TestListWithExplicitInterfaces source; + readonly TEnumerable source2; + + internal AsValueEnumerable_TestListWithExplicitInterfaces_TestValueType_(TestListWithExplicitInterfaces source, TEnumerable source2) + => (this.source, this.source2) = (source, source2); + + // Implement IValueEnumerable> + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ValueEnumerator GetEnumerator() => new(source2.GetEnumerator()); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + // Implement ICollection + + public int Count => source2.Count; + + public bool IsReadOnly => true; + + void ICollection.Add(TestValueType item) => throw new NotSupportedException(); + + bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); + + void ICollection.Clear() => throw new NotSupportedException(); + + public void CopyTo(Span span) + { + if (Count is 0) return; + if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); + + var index = 0; + foreach (var current in this) + { + span[index] = current; + checked { index++; } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Contains(TestValueType item) => source2.Contains(item); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TestValueType[] array, int arrayIndex) => source2.CopyTo(array, arrayIndex); + + // Implement IList + + public TestValueType this[int index] => source2[index]; + + TestValueType IList.this[int index] + { + get => source2[index]; + set => throw new NotSupportedException(); + } + + void IList.Insert(int index, TestValueType item) => throw new NotSupportedException(); + + void IList.RemoveAt(int index) => throw new NotSupportedException(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int IndexOf(TestValueType item) => source2.IndexOf(item); + } + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs new file mode 100644 index 000000000..bc6400e33 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyCollection.cs @@ -0,0 +1,74 @@ +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestReadOnlyCollection_TestValueType_> AsValueEnumerable(this TestReadOnlyCollection source) + => new(source, source); + + public readonly struct AsValueEnumerable_TestReadOnlyCollection_TestValueType_ + : IValueReadOnlyCollection.Enumerator>, ICollection + where TEnumerable : IReadOnlyCollection + { + readonly TestReadOnlyCollection source; + readonly TEnumerable source2; + + internal AsValueEnumerable_TestReadOnlyCollection_TestValueType_(TestReadOnlyCollection source, TEnumerable source2) + => (this.source, this.source2) = (source, source2); + + // Implement IValueEnumerable.Enumerator> + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TestReadOnlyCollection.Enumerator GetEnumerator() => source.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + // Implement ICollection + + public int Count => source2.Count; + + public bool IsReadOnly => true; + + void ICollection.Add(TestValueType item) => throw new NotSupportedException(); + + bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); + + void ICollection.Clear() => throw new NotSupportedException(); + + public void CopyTo(Span span) + { + if (Count is 0) return; + if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); + + var index = 0; + foreach (var current in this) + { + span[index] = current; + checked { index++; } + } + } + + public bool Contains(TestValueType item) + { + foreach (var current in this) + { + if (EqualityComparer.Default.Equals(current, item)) return true; + } + return true; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TestValueType[] array, int arrayIndex) => CopyTo(array.AsSpan(arrayIndex)); + } + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs new file mode 100644 index 000000000..d81f91ed2 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestReadOnlyList.cs @@ -0,0 +1,103 @@ +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static AsValueEnumerable_TestReadOnlyList_TestValueType_> AsValueEnumerable(this TestReadOnlyList source) + => new(source, source); + + public readonly struct AsValueEnumerable_TestReadOnlyList_TestValueType_ + : IValueReadOnlyList.Enumerator>, IList + where TEnumerable : IReadOnlyList + { + readonly TestReadOnlyList source; + readonly TEnumerable source2; + + internal AsValueEnumerable_TestReadOnlyList_TestValueType_(TestReadOnlyList source, TEnumerable source2) + => (this.source, this.source2) = (source, source2); + + // Implement IValueEnumerable.Enumerator> + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public TestReadOnlyList.Enumerator GetEnumerator() => source.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator(); + + // Implement ICollection + + public int Count => source2.Count; + + public bool IsReadOnly => true; + + void ICollection.Add(TestValueType item) => throw new NotSupportedException(); + + bool ICollection.Remove(TestValueType item) => throw new NotSupportedException(); + + void ICollection.Clear() => throw new NotSupportedException(); + + public void CopyTo(Span span) + { + if (Count is 0) return; + if (span.Length < Count) throw new ArgumentException("Destination span was not long enough.", nameof(span)); + + var index = 0; + foreach (var current in this) + { + span[index] = current; + checked { index++; } + } + } + + public bool Contains(TestValueType item) + { + foreach (var current in this) + { + if (EqualityComparer.Default.Equals(current, item)) return true; + } + return true; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void CopyTo(TestValueType[] array, int arrayIndex) => CopyTo(array.AsSpan(arrayIndex)); + + // Implement IList + + public TestValueType this[int index] => source2[index]; + + TestValueType IList.this[int index] + { + get => source2[index]; + set => throw new NotSupportedException(); + } + + void IList.Insert(int index, TestValueType item) => throw new NotSupportedException(); + + void IList.RemoveAt(int index) => throw new NotSupportedException(); + + public int IndexOf(TestValueType item) + { + if (Count is not 0) + { + var index = 0; + foreach (var current in this) + { + if (EqualityComparer.Default.Equals(current, item)) return index; + + checked { index++; } + } + } + return -1; + } + } + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs new file mode 100644 index 000000000..d6e075c07 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/AsValueEnumerable.TestValueEnumerable.cs @@ -0,0 +1,17 @@ +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static TestValueEnumerable AsValueEnumerable(this TestValueEnumerable source) + => source; + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Count.Array.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Count.Array.cs new file mode 100644 index 000000000..18e6af8cd --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Count.Array.cs @@ -0,0 +1,17 @@ +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentValueEnumerable source, System.Func predicate) + => source.Count(predicate); + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Count.Span.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Count.Span.cs new file mode 100644 index 000000000..1a3426670 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Count.Span.cs @@ -0,0 +1,16 @@ +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Count(this NetFabric.Hyperlinq.ArrayExtensions.SpanValueEnumerable source, Func predicate) => ArrayExtensions.Count(source.Span, predicate); + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Select.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Select.cs deleted file mode 100644 index 00caa8d8c..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Select.cs +++ /dev/null @@ -1,30 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class DictionaryBindings - { - public partial struct ValueWrapper - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, TResult, NetFabric.Hyperlinq.FunctionWrapper, TResult>> Select(System.Func, TResult> selector) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, TResult>(this, selector); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, TResult, TSelector> Select(TSelector selector = default) - where TSelector : struct, NetFabric.Hyperlinq.IFunction, TResult> - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, TResult, TSelector>(this, selector); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Where.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Where.cs deleted file mode 100644 index 1e44137c6..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Dictionary.Where.cs +++ /dev/null @@ -1,30 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class DictionaryBindings - { - public partial struct ValueWrapper - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, NetFabric.Hyperlinq.FunctionWrapper, bool>> Where(System.Func, bool> predicate) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair>(this, predicate); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, TPredicate> Where(TPredicate predicate = default) - where TPredicate : struct, NetFabric.Hyperlinq.IFunction, bool> - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where, System.Collections.Generic.Dictionary.Enumerator, System.Collections.Generic.KeyValuePair, TPredicate>(this, predicate); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Distinct.ValueEnumerable.Where.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Distinct.ValueEnumerable.Where.cs deleted file mode 100644 index 85119f091..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Distinct.ValueEnumerable.Where.cs +++ /dev/null @@ -1,36 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public partial struct DistinctEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable.DisposableEnumerator, TSource, NetFabric.Hyperlinq.FunctionWrapper> Where(System.Func predicate) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where, NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable.DisposableEnumerator, TSource>(this, predicate); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable.DisposableEnumerator, TSource, TPredicate> Where(TPredicate predicate = default) - where TPredicate : struct, NetFabric.Hyperlinq.IFunction - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where, NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable.DisposableEnumerator, TSource, TPredicate>(this, predicate); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable.DisposableEnumerator, TSource> Distinct() - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Distinct, NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable.DisposableEnumerator, TSource>(this); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Empty.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Empty.cs new file mode 100644 index 000000000..0ee1fb9b0 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Empty.cs @@ -0,0 +1,13 @@ +#nullable enable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static partial class GeneratedExtensionMethods + { + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Count.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Count.cs deleted file mode 100644 index cad14e728..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Count.cs +++ /dev/null @@ -1,20 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerable - { - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this NetFabric.Hyperlinq.ValueEnumerable.RangeEnumerable source) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Count(source); - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Select.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Select.cs deleted file mode 100644 index 87cf749f7..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Select.cs +++ /dev/null @@ -1,30 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerable - { - public partial struct RangeEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable> Select(System.Func selector) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select(this, selector); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable Select(TSelector selector = default) - where TSelector : struct, NetFabric.Hyperlinq.IFunction - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select(this, selector); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Where.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Where.cs deleted file mode 100644 index 14219e17f..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Range.Where.cs +++ /dev/null @@ -1,30 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerable - { - public partial struct RangeEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable> Where(System.Func predicate) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where(this, predicate); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable Where(TPredicate predicate = default) - where TPredicate : struct, NetFabric.Hyperlinq.IFunction - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where(this, predicate); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Repeat.Count.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Repeat.Count.cs deleted file mode 100644 index 41ac35b3f..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Repeat.Count.cs +++ /dev/null @@ -1,20 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerable - { - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this NetFabric.Hyperlinq.ValueEnumerable.RepeatEnumerable source) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Count, NetFabric.Hyperlinq.ValueEnumerable.RepeatEnumerable.DisposableEnumerator, TSource>(source); - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs deleted file mode 100644 index f44a33abe..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ArraySegment.Any.cs +++ /dev/null @@ -1,30 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - public partial struct ArraySegmentSelectEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Any(System.Func predicate) - => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Any, TResult>(this, predicate); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Any(TPredicate predicate = default) - where TPredicate : struct, NetFabric.Hyperlinq.IFunction - => NetFabric.Hyperlinq.ValueReadOnlyListExtensions.Any, TResult, TPredicate>(this, predicate); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Any.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Any.cs deleted file mode 100644 index 76ba1132a..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Any.cs +++ /dev/null @@ -1,36 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public partial struct SelectEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Any() - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Any, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult>(this); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Any(System.Func predicate) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Any, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult>(this, predicate); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Any(TPredicate predicate = default) - where TPredicate : struct, NetFabric.Hyperlinq.IFunction - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Any, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult, TPredicate>(this, predicate); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.First.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.First.cs deleted file mode 100644 index 77c913be7..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.First.cs +++ /dev/null @@ -1,23 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public partial struct SelectEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.Option First() - => NetFabric.Hyperlinq.ValueEnumerableExtensions.First, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult>(this); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Where.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Where.cs deleted file mode 100644 index 6c9ed4726..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Select.ValueEnumerable.Where.cs +++ /dev/null @@ -1,30 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public partial struct SelectEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult, NetFabric.Hyperlinq.FunctionWrapper> Where(System.Func predicate) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult>(this, predicate); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult, TPredicate> Where(TPredicate predicate = default) - where TPredicate : struct, NetFabric.Hyperlinq.IFunction - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Where, NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable.DisposableEnumerator, TResult, TPredicate>(this, predicate); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ArraySegment.Count.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ArraySegment.Count.cs deleted file mode 100644 index 444845022..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ArraySegment.Count.cs +++ /dev/null @@ -1,23 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - public partial struct ArraySegmentWhereEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly int Count() - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Count, NetFabric.Hyperlinq.ArrayExtensions.ArraySegmentWhereEnumerable.DisposableEnumerator, TSource>(this); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Count.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Count.cs deleted file mode 100644 index a68c8d6da..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Count.cs +++ /dev/null @@ -1,23 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public partial struct WhereEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly int Count() - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Count, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource>(this); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Distinct.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Distinct.cs deleted file mode 100644 index 6f5f15c16..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Distinct.cs +++ /dev/null @@ -1,23 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public partial struct WhereEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.DistinctEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource> Distinct() - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Distinct, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource>(this); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.First.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.First.cs deleted file mode 100644 index 8b13b25f7..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.First.cs +++ /dev/null @@ -1,23 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public partial struct WhereEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.Option First() - => NetFabric.Hyperlinq.ValueEnumerableExtensions.First, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource>(this); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Select.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Select.cs deleted file mode 100644 index c9b3e7b9b..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Results/Where.ValueEnumerable.Select.cs +++ /dev/null @@ -1,30 +0,0 @@ -#nullable enable - -using System; -using System.CodeDom.Compiler; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public partial struct WhereEnumerable - { - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource, TResult, NetFabric.Hyperlinq.FunctionWrapper> Select(System.Func selector) - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource, TResult>(this, selector); - - [GeneratedCode("NetFabric.Hyperlinq.SourceGenerator", "1.0.0")] - [DebuggerNonUserCode] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly NetFabric.Hyperlinq.ValueEnumerableExtensions.SelectEnumerable, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource, TResult, TSelector> Select(TSelector selector = default) - where TSelector : struct, NetFabric.Hyperlinq.IFunction - => NetFabric.Hyperlinq.ValueEnumerableExtensions.Select, NetFabric.Hyperlinq.ValueEnumerableExtensions.WhereEnumerable.DisposableEnumerator, TSource, TResult, TSelector>(this, selector); - - } - - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ArraySegment.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ArraySegment.cs deleted file mode 100644 index fb6d8bcbb..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ArraySegment.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - - public static bool Any(this in ArraySegment source) - => source.Count != 0; - - public static bool Any(this in ArraySegment source, Func predicate) - => source.Any(new FunctionWrapper(predicate)); - - public static bool Any(this in ArraySegment source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => default; - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueEnumerable.cs deleted file mode 100644 index 2c79e1b31..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueEnumerable.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - - public static bool Any(this TEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => default; - - public static bool Any(this TEnumerable source, Func predicate) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => source.Any>(new FunctionWrapper(predicate)); - - public static bool Any(this TEnumerable source, TPredicate predicate = default) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunction - => default; - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueReadOnlyCollection.cs deleted file mode 100644 index 49d4c1145..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueReadOnlyCollection.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyCollectionExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => source.Count is not 0; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => Any>(source, new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TEnumerable source, TPredicate predicate = default) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunction - => source.Count is not 0 && ValueEnumerableExtensions.Any(source, predicate); - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueReadOnlyList.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueReadOnlyList.cs deleted file mode 100644 index 085c79a11..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Any.ValueReadOnlyList.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TList source) - where TList : struct, IReadOnlyList - => source.Count is not 0; - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TList source, Func predicate) - where TList : struct, IReadOnlyList - => source.Any>(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool Any(this TList source, TPredicate predicate = default) - where TList : struct, IReadOnlyList - where TPredicate : struct, IFunction - => default; - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs new file mode 100644 index 000000000..c95d5f829 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsEnumerable.TestEnumerableWithValueTypeEnumerator.cs @@ -0,0 +1,13 @@ +using System; +using System.Linq; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void Count_TestEnumerableWithValueTypeEnumerator() + { + _ = new TestEnumerableWithValueTypeEnumerator() + .AsValueEnumerable() + .AsEnumerable(); + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.Empty.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.Empty.cs new file mode 100644 index 000000000..0b0b74e93 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.Empty.cs @@ -0,0 +1,28 @@ +using System; +//using NetFabric.Hyperlinq; => DO NOT UNCOMMENT + +partial class TestsSource +{ + static void AsValueEnumerable_Empty() + { + // test calling AsValueEnumerable() for types that don't need source generation + // with NetFabric.Hyperlinq namespace NOT in a using clause + +#if !NOT_TESTING + var array = Array.Empty(); + + _ = array.AsValueEnumerable(); + _ = new ArraySegment(array).AsValueEnumerable(); + + _ = array.AsMemory().AsValueEnumerable(); + _ = ((ReadOnlyMemory)array.AsMemory()).AsValueEnumerable(); + + _ = array.AsSpan().AsValueEnumerable(); + _ = ((ReadOnlySpan)array.AsSpan()).AsValueEnumerable(); + + var list = new List(); + _ = list.AsValueEnumerable(); +#endif + } +} + diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.Empty2.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.Empty2.cs new file mode 100644 index 000000000..6c0371f60 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.Empty2.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using NetFabric.Hyperlinq; // namespace is known at compile time + +partial class TestsSource +{ + static void AsValueEnumerable_Empty2() + { + // test calling AsValueEnumerable() for types that don't need source generation + + var array = Array.Empty(); + + _ = array.AsValueEnumerable(); + _ = ArrayExtensions.AsValueEnumerable(array); + _ = new ArraySegment(array).AsValueEnumerable(); + + _ = array.AsMemory().AsValueEnumerable(); + _ = ((ReadOnlyMemory)array.AsMemory()).AsValueEnumerable(); + + _ = array.AsSpan().AsValueEnumerable(); + _ = ((ReadOnlySpan)array.AsSpan()).AsValueEnumerable(); + + var list = new List(); + _ = list.AsValueEnumerable(); + } +} + diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.IReadOnlyList.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.IReadOnlyList.cs new file mode 100644 index 000000000..33b500a91 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.IReadOnlyList.cs @@ -0,0 +1,17 @@ +using NetFabric.Hyperlinq; +using System.Collections.Generic; + +partial class TestsSource +{ + static void AsValueEnumerable_IReadOnlyList() + { + // test calling AsValueEnumerable() on an IReadOnlyList<> + IReadOnlyList list = new TestReadOnlyList(); + _ = list.AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.Repeat.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.Repeat.cs new file mode 100644 index 000000000..834978c04 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.Repeat.cs @@ -0,0 +1,13 @@ +using System; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_Repeat() + { + // test calling AsValueEnumerable() for types that implement IValueEnumerable<,> + + _ = ValueEnumerable.Repeat(0, 100).AsValueEnumerable(); + } +} + diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestCollection.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestCollection.cs new file mode 100644 index 000000000..c66f27f10 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestCollection.cs @@ -0,0 +1,15 @@ +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_Collection() + { + // test calling AsValueEnumerable() on an implementation of ICollection<> + _ = new TestCollection().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs new file mode 100644 index 000000000..d9734c3b4 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithInterfacelessPublicEnumerator.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_TestEnumerableWithInterfacelessPublicEnumerator() + { + // test calling AsValueEnumerable() for types that implement IEnumerable<> + // but the public GetEnumerator() returns a type that doesn't implement IEnumerator<> + + _ = new TestEnumerableWithInterfacelessPublicEnumerator().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs new file mode 100644 index 000000000..12071aee1 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfaces.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_TestEnumerableWithNoInterfaces() + { + // test calling AsValueEnumerable() for types that do not implement IEnumerable<> + // but the public GetEnumerator() returns a type that doesn't implement IEnumerator<> + + _ = new TestEnumerableWithNoInterfaces().AsValueEnumerable(); + } +} + + diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs new file mode 100644 index 000000000..7554e76fe --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose() + { + // test calling AsValueEnumerable() for types that do not implement IEnumerable<> + // and the public GetEnumerator() returns a type that implement IDisposable and has a Reset() method + + _ = new TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs new file mode 100644 index 000000000..304df9a9d --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithReferenceTypeEnumerator.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_TestEnumerableWithReferenceTypeEnumerator() + { + // test calling AsValueEnumerable() for types that implement IEnumerable<> and the enumerator is not a value type + + _ = new TestEnumerableWithReferenceTypeEnumerator().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs new file mode 100644 index 000000000..1ff2412ec --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestEnumerableWithValueTypeEnumerator.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_EnumerableWithValueTypeEnumerator() + { + // test calling AsValueEnumerable() for types that implement IEnumerable<> and the enumerator is a value type + + _ = new TestEnumerableWithValueTypeEnumerator().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestList.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestList.cs new file mode 100644 index 000000000..f1421d0ab --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestList.cs @@ -0,0 +1,15 @@ +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_List() + { + // test calling AsValueEnumerable() on an implementation of IList<> + _ = new TestList().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestListWithExplicitInterfaces.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestListWithExplicitInterfaces.cs new file mode 100644 index 000000000..72d84d63f --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestListWithExplicitInterfaces.cs @@ -0,0 +1,15 @@ +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_ReadOnlyListWithExplicitInterfaces() + { + // test calling AsValueEnumerable() on an IValueEnumerable + _ = new TestListWithExplicitInterfaces().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestReadOnlyCollection.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestReadOnlyCollection.cs new file mode 100644 index 000000000..15c9cce44 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestReadOnlyCollection.cs @@ -0,0 +1,15 @@ +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_ReadOnlyCollection() + { + // test calling AsValueEnumerable() on an IValueEnumerable + _ = new TestReadOnlyCollection().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestReadOnlyList.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestReadOnlyList.cs new file mode 100644 index 000000000..cb02ca0d8 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestReadOnlyList.cs @@ -0,0 +1,15 @@ +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_ReadOnlyList() + { + // test calling AsValueEnumerable() on an IValueEnumerable + _ = new TestReadOnlyList().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestValueEnumerable.cs new file mode 100644 index 000000000..fbb432ef8 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/AsValueEnumerable.TestValueEnumerable.cs @@ -0,0 +1,15 @@ +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void AsValueEnumerable_ValueEnumerable() + { + // test calling AsValueEnumerable() on an IValueEnumerable + _ = new TestValueEnumerable().AsValueEnumerable(); + } +} + + + + + diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/Enumerables.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/Enumerables.cs new file mode 100644 index 000000000..283f0f9df --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/Enumerables.cs @@ -0,0 +1,327 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +public class TestEnumerableWithNoInterfaces +{ + public Enumerator GetEnumerator() + => new(); + + public readonly struct Enumerator + { + public T Current + => default!; + + public bool MoveNext() + => false; + } +} + +public class TestEnumerableWithNoInterfacesButEnumeratorWithResetAndDispose +{ + public Enumerator GetEnumerator() + => new(); + + public readonly struct Enumerator + : IDisposable + { + public T Current + => default!; + + public bool MoveNext() + => false; + + public void Reset() + { } + + public void Dispose() + { } + } +} + +public readonly struct TestEnumerableWithInterfacelessPublicEnumerator + : IEnumerable +{ + public Enumerator GetEnumerator() + => new(); + IEnumerator IEnumerable.GetEnumerator() + => new DisposableEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + => new DisposableEnumerator(); + + public struct Enumerator + { + public T Current + => default!; + + public bool MoveNext() + => false; + } + + class DisposableEnumerator + : IEnumerator + { + public T Current + => default!; + object? IEnumerator.Current + => default; + + public bool MoveNext() + => false; + + public void Reset() + { } + public void Dispose() + { } + } +} + +public readonly struct TestEnumerableWithValueTypeEnumerator + : IEnumerable +{ + public Enumerator GetEnumerator() + => new(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + + public readonly struct Enumerator + : IEnumerator + { + public T Current + => default!; + object? IEnumerator.Current + => default; + + public bool MoveNext() + => false; + + public void Reset() + { } + public void Dispose() + { } + } +} + + +public readonly struct TestEnumerableWithReferenceTypeEnumerator + : IEnumerable +{ + public IEnumerator GetEnumerator() + => new Enumerator(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + + class Enumerator + : IEnumerator + { + public T Current + => default!; + object? IEnumerator.Current + => default; + + public bool MoveNext() + => false; + + public void Reset() + { } + public void Dispose() + { } + } +} + +public readonly struct TestReadOnlyCollection + : IReadOnlyCollection +{ + public int Count => default; + + public Enumerator GetEnumerator() + => new(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + + public readonly struct Enumerator + : IEnumerator + { + public T Current + => default!; + object? IEnumerator.Current + => default; + + public bool MoveNext() + => false; + + public void Reset() + { } + public void Dispose() + { } + } +} + +public readonly struct TestCollection + : ICollection +{ + public int Count => default; + + public bool IsReadOnly => true; + public bool Contains(T item) => default; + public void CopyTo(T[] array, int arrayIndex) { } + void ICollection.Add(T item) => throw new NotSupportedException(); + bool ICollection.Remove(T item) => throw new NotSupportedException(); + void ICollection.Clear() => throw new NotSupportedException(); + + public Enumerator GetEnumerator() + => new(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + + public readonly struct Enumerator + : IEnumerator + { + public T Current + => default!; + object? IEnumerator.Current + => default; + + public bool MoveNext() + => false; + + public void Reset() + { } + public void Dispose() + { } + } +} + +public readonly struct TestReadOnlyList + : IReadOnlyList +{ + public int Count => default; + + public T this[int index] => default!; + + public Enumerator GetEnumerator() + => new(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + + public readonly struct Enumerator + : IEnumerator + { + public T Current + => default!; + object? IEnumerator.Current + => default; + + public bool MoveNext() + => false; + + public void Reset() + { } + public void Dispose() + { } + } +} + +public readonly struct TestList + : IList +{ + public int Count => default; + + public bool IsReadOnly => true; + + public T this[int index] + { + get => default!; + set => throw new NotSupportedException(); + } + + public bool Contains(T item) => default; + public void CopyTo(T[] array, int arrayIndex) { } + void ICollection.Add(T item) => throw new NotSupportedException(); + bool ICollection.Remove(T item) => throw new NotSupportedException(); + void ICollection.Clear() => throw new NotSupportedException(); + + public int IndexOf(T item) => -1; + void IList.Insert(int index, T item) => throw new NotSupportedException(); + void IList.RemoveAt(int index) => throw new NotSupportedException(); + + public Enumerator GetEnumerator() + => new(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + + public readonly struct Enumerator + : IEnumerator + { + public T Current + => default!; + object? IEnumerator.Current + => default; + + public bool MoveNext() + => false; + + public void Reset() + { } + public void Dispose() + { } + } +} + + +public readonly struct TestListWithExplicitInterfaces + : IList +{ + int ICollection.Count => default; + + bool ICollection.IsReadOnly => true; + + T IList.this[int index] + { + get => default!; + set => throw new NotSupportedException(); + } + + bool ICollection.Contains(T item) => default; + void ICollection.CopyTo(T[] array, int arrayIndex) { } + void ICollection.Add(T item) => throw new NotSupportedException(); + bool ICollection.Remove(T item) => throw new NotSupportedException(); + void ICollection.Clear() => throw new NotSupportedException(); + + int IList.IndexOf(T item) => -1; + void IList.Insert(int index, T item) => throw new NotSupportedException(); + void IList.RemoveAt(int index) => throw new NotSupportedException(); + + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + IEnumerator IEnumerable.GetEnumerator() + => new Enumerator(); + + class Enumerator + : IEnumerator + { + T IEnumerator.Current + => default!; + object? IEnumerator.Current + => default; + + bool IEnumerator.MoveNext() + => false; + + void IEnumerator.Reset() + { } + void IDisposable.Dispose() + { } + } +} + diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IFunction.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IFunction.cs deleted file mode 100644 index 719dbb63a..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IFunction.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace NetFabric.Hyperlinq -{ - public interface IFunction - { - TResult Invoke(T arg); - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IFunctionWrapper.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IFunctionWrapper.cs deleted file mode 100644 index ce38a1db7..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IFunctionWrapper.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; - -namespace NetFabric.Hyperlinq -{ - public readonly struct FunctionWrapper - : IFunction - { - readonly Func function; - - public FunctionWrapper(Func function) - => this.function = function; - - public TResult Invoke(T arg) - => function(arg); - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IValueEnumerable.cs deleted file mode 100644 index d4efc695c..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/IValueEnumerable.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public interface IValueEnumerable - : IEnumerable - where TEnumerator - : struct - , IEnumerator - { - new TEnumerator GetEnumerator(); - } - - public interface IValueReadOnlyCollection - : IReadOnlyCollection - , IValueEnumerable - where TEnumerator - : struct - , IEnumerator - { - } - - public interface IValueReadOnlyList - : IReadOnlyList - , IValueReadOnlyCollection - where TEnumerator - : struct - , IEnumerator - { - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/ItemTypes.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/ItemTypes.cs new file mode 100644 index 000000000..1249d551d --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/ItemTypes.cs @@ -0,0 +1,7 @@ +public struct TestValueType +{ +} + +public class TestReferenceType +{ +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/Option.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/Option.cs deleted file mode 100644 index 4c68b37b2..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/Option.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public readonly struct Option - { - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/PredicateCombination.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/PredicateCombination.cs deleted file mode 100644 index 27b56347f..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/PredicateCombination.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace NetFabric.Hyperlinq -{ - public struct PredicateCombination - : IFunction - where TPredicate1 : struct, IFunction - where TPredicate2 : struct, IFunction - { - TPredicate1 first; - TPredicate2 second; - - public PredicateCombination(TPredicate1 first, TPredicate2 second) - => (this.first, this.second) = (first, second); - - public bool Invoke(TSource item) - => first.Invoke(item) && second.Invoke(item); - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/SelectorCombination.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/SelectorCombination.cs deleted file mode 100644 index f7dfe9134..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/SelectorCombination.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace NetFabric.Hyperlinq -{ - public readonly struct SelectorCombination - : IFunction - where TSelector1 : struct, IFunction - where TSelector2 : struct, IFunction - { - readonly TSelector1 first; - readonly TSelector2 second; - - public SelectorCombination(TSelector1 first, TSelector2 second) - => (this.first, this.second) = (first, second); - - public TResult Invoke(TSource item) - => second.Invoke(first.Invoke(item)); - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/ValueEnumerables.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/ValueEnumerables.cs new file mode 100644 index 000000000..0819feb46 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Common/ValueEnumerables.cs @@ -0,0 +1,45 @@ +using NetFabric.Hyperlinq; +using System.Collections; +using System.Collections.Generic; + +public class TestValueEnumerable + : IValueEnumerable.DisposableEnumerator> +{ + public Enumerator GetEnumerator() + => new(); + + DisposableEnumerator IValueEnumerable.GetEnumerator() + => new(); + + IEnumerator IEnumerable.GetEnumerator() + => new DisposableEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() + => new DisposableEnumerator(); + + public readonly struct Enumerator + { + public T Current + => default!; + + public bool MoveNext() + => false; + } + + public readonly struct DisposableEnumerator + : IEnumerator + { + public T Current + => default!; + object? IEnumerator.Current + => default; + + public bool MoveNext() + => false; + + public void Reset() + { } + public void Dispose() + { } + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Contains.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Contains.ValueEnumerable.cs deleted file mode 100644 index 7de29c2c4..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Contains.ValueEnumerable.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public static bool Contains(this TEnumerable source, TSource value) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => default; - - public static bool Contains(this TEnumerable source, TSource value, IEqualityComparer? comparer) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => default; - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Count.Array.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Count.Array.cs new file mode 100644 index 000000000..391246454 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Count.Array.cs @@ -0,0 +1,13 @@ +using System; +using System.Linq; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void Count_ArraySegmentValueEnumerable() + { + var array = Array.Empty(); + + _ = array.AsValueEnumerable().Count(_ => true); + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Count.Span.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Count.Span.cs new file mode 100644 index 000000000..13ac4dfda --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Count.Span.cs @@ -0,0 +1,16 @@ +using System; +using NetFabric.Hyperlinq; + +partial class TestsSource +{ + static void Count_SpanValueEnumerable() + { + var span = Array.Empty().AsSpan(); + +#if !NOT_TESTING + _ = span.AsValueEnumerable().Count(_ => true); +#endif + } +} + + diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Count.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Count.ValueEnumerable.cs deleted file mode 100644 index 897fe92b1..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Count.ValueEnumerable.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public static int Count(this TEnumerable _) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => 0; - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Dictionary.Bindings.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Dictionary.Bindings.cs deleted file mode 100644 index 68137e488..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Dictionary.Bindings.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class DictionaryBindings - { - [GeneratorMapping("TSource", "System.Collections.Generic.KeyValuePair", true)] - public readonly partial struct ValueWrapper - : IValueReadOnlyCollection, Dictionary.Enumerator> - , ICollection> - where TKey : notnull - { - readonly Dictionary source; - - public ValueWrapper(Dictionary source) - => this.source = source; - - public int Count - => source.Count; - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary.Enumerator GetEnumerator() - => source.GetEnumerator(); - - IEnumerator> IEnumerable>.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => GetEnumerator(); - - bool ICollection>.IsReadOnly - => true; - - void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) - => ((ICollection>)source).CopyTo(array, arrayIndex); - - void ICollection>.Add(KeyValuePair item) - => throw new NotSupportedException(); - void ICollection>.Clear() - => throw new NotSupportedException(); - bool ICollection>.Contains(KeyValuePair item) - => throw new NotSupportedException(); - bool ICollection>.Remove(KeyValuePair item) - => throw new NotSupportedException(); - } - - public static int Count(this ValueWrapper source) - where TKey : notnull - => source.Count; - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ArraySegment.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ArraySegment.cs deleted file mode 100644 index a950046e1..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ArraySegment.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - public static ArraySegmentDistinctEnumerable Distinct(this in ArraySegment source) - => new(source); - - public readonly partial struct ArraySegmentDistinctEnumerable - : IValueEnumerable.DisposableEnumerator> - { - readonly ArraySegment source; - - internal ArraySegmentDistinctEnumerable(in ArraySegment source) - => this.source = source; - - public Enumerator GetEnumerator() - => new(); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - public struct Enumerator - { - } - - public struct DisposableEnumerator - : IEnumerator - { - public readonly TSource Current => default!; - readonly TSource IEnumerator.Current => default!; - readonly object IEnumerator.Current => default!; - - public bool MoveNext() - => false; - - public readonly void Reset() - => throw new NotSupportedException(); - - public void Dispose() { } - } - } - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ValueEnumerable.cs deleted file mode 100644 index 493f1a6f3..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Distinct.ValueEnumerable.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - public static DistinctEnumerable Distinct(this TEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => new(source); - - public readonly partial struct DistinctEnumerable - : IValueEnumerable.DisposableEnumerator> - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - { - readonly TEnumerable source; - - internal DistinctEnumerable(TEnumerable source) - => this.source = source; - - public Enumerator GetEnumerator() - => new(); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - public struct Enumerator - { - } - - public struct DisposableEnumerator - : IEnumerator - { - public readonly TSource Current => default!; - readonly TSource IEnumerator.Current => default!; - readonly object? IEnumerator.Current => default; - - public bool MoveNext() - => false; - - public readonly void Reset() - => throw new NotSupportedException(); - - public void Dispose() { } - } - } - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ExtensionMethods.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ExtensionMethods.cs deleted file mode 100644 index 629a8d4f2..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ExtensionMethods.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static class ExtensionMethods - { - public static void NotConstrainedExtensionMethod(this ArraySegment _) { } - - static void NotIgnoredExtensionMethod(this TEnumerable _) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - { } - - public static void PublicExtensionMethod(this TEnumerable _) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - { } - } - -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/First.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/First.ValueEnumerable.cs deleted file mode 100644 index 967f11668..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/First.ValueEnumerable.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - - public static Option First(this TEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => default; - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/NoExtensionMethods.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/NoExtensionMethods.cs deleted file mode 100644 index 9b7e6861a..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/NoExtensionMethods.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - //public class NotStaticClass - //{ - // public void Method(TEnumerable _) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // { } - //} - - //static class NotPublicStaticClass - //{ - // public static void ExtensionMethod(this TEnumerable _) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - // { } - //} - - public static class NoExtensionMethods - { - //public static void NotExtensionMethod(TEnumerable _) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - //{ } - - //static void NotPublicExtensionMethod(this TEnumerable _) - // where TEnumerable : IValueEnumerable - // where TEnumerator : struct, IEnumerator - //{ } - - [GeneratorIgnore] - public static void IgnoredExtensionMethod(this TEnumerable _) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - { } - } - -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Range.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Range.cs deleted file mode 100644 index c2659d429..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Range.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerable - { - public static RangeEnumerable Range(int start, int count) - => new(start, count); - - [GeneratorMapping("TSource", "int", true)] - public readonly partial struct RangeEnumerable - : IValueReadOnlyCollection - , ICollection - { - readonly int start; - readonly int end; - - internal RangeEnumerable(int start, int count) - { - this.start = start; - Count = count; - end = checked(start + count); - } - - public int Count { get; } - - - public Enumerator GetEnumerator() - => new(); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(int[] array, int arrayIndex) - { - } - - public bool Contains(int value) - => value >= start && value < end; - - void ICollection.Add(int item) - => throw new NotSupportedException(); - void ICollection.Clear() - => throw new NotSupportedException(); - bool ICollection.Remove(int item) - => throw new NotSupportedException(); - - public struct Enumerator - { - } - - public struct DisposableEnumerator - : IEnumerator - { - public readonly int Current => 0; - readonly int IEnumerator.Current => 0; - readonly object IEnumerator.Current => 0; - - public bool MoveNext() - => false; - - public readonly void Reset() - => throw new NotSupportedException(); - - public void Dispose() { } - } - - public bool Contains(int value, IEqualityComparer? comparer) - => default; - - public RangeEnumerable Skip(int count) - => default; - } - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Repeat.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Repeat.cs deleted file mode 100644 index 4a343102c..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Repeat.cs +++ /dev/null @@ -1,139 +0,0 @@ -using System; -using System.Buffers; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerable - { - - public static RepeatEnumerable Repeat(TSource value, int count) - { - if (count < 0) throw new ArgumentOutOfRangeException(nameof(count)); - - return new RepeatEnumerable(value, count); - } - - [StructLayout(LayoutKind.Auto)] - public readonly partial struct RepeatEnumerable - : IValueReadOnlyCollection.DisposableEnumerator> - , ICollection - { - readonly TSource value; - readonly int count; - - internal RepeatEnumerable(TSource value, int count) - { - this.value = value; - this.count = count; - } - - public int Count - => count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Enumerator GetEnumerator() - => new(in this); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(in this); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(in this); - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(Span span) - { - - } - - public void CopyTo(TSource[] array, int arrayIndex) - { - - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource item) - => count is not 0 && EqualityComparer.Default.Equals(value, item); - - public int IndexOf(TSource item) - => count is not 0 && EqualityComparer.Default.Equals(value, item) - ? 0 - : -1; - - [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) - => throw new NotSupportedException(); - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => throw new NotSupportedException(); - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) - => throw new NotSupportedException(); - - [StructLayout(LayoutKind.Sequential)] - public struct Enumerator - { - int counter; - readonly int end; - - internal Enumerator(in RepeatEnumerable enumerable) - { - Current = enumerable.value; - counter = -1; - end = counter + enumerable.Count; - } - - public TSource Current { get; } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++counter <= end; - } - - [StructLayout(LayoutKind.Sequential)] - public struct DisposableEnumerator - : IEnumerator - { - int counter; - readonly int end; - - internal DisposableEnumerator(in RepeatEnumerable enumerable) - { - Current = enumerable.value; - counter = -1; - end = counter + enumerable.Count; - } - - public TSource Current { get; } - readonly TSource IEnumerator.Current - => Current; - readonly object? IEnumerator.Current - // ReSharper disable once HeapView.PossibleBoxingAllocation - => Current; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool MoveNext() - => ++counter <= end; - - [ExcludeFromCodeCoverage] - public readonly void Reset() - => throw new NotSupportedException(); - - public readonly void Dispose() { } - } - } - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ArraySegment.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ArraySegment.cs deleted file mode 100644 index b943fa420..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ArraySegment.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] - static ArraySegmentSelectEnumerable> Select(this in ArraySegment source, Func selector) - => Select>(source, new FunctionWrapper(selector)); - - static ArraySegmentSelectEnumerable Select(this in ArraySegment source, TSelector selector = default) - where TSelector : struct, IFunction - => new(source, selector); - - [GeneratorMapping("TSource", "TResult")] - public readonly partial struct ArraySegmentSelectEnumerable - : IValueReadOnlyList.DisposableEnumerator> - , IList - where TSelector : struct, IFunction - { - readonly ArraySegment source; - readonly TSelector selector; - - internal ArraySegmentSelectEnumerable(in ArraySegment source, TSelector selector) - => (this.source, this.selector) = (source, selector); - - public int Count - => 0; - - bool ICollection.IsReadOnly - => true; - - void ICollection.CopyTo(TResult[] array, int arrayIndex) - { } - void ICollection.Add(TResult item) - => throw new NotSupportedException(); - void ICollection.Clear() - => throw new NotSupportedException(); - public bool Contains(TResult item) - => default; - bool ICollection.Remove(TResult item) - => throw new NotSupportedException(); - int IList.IndexOf(TResult item) - => default; - void IList.Insert(int index, TResult item) - => throw new NotSupportedException(); - void IList.RemoveAt(int index) - => throw new NotSupportedException(); - - public TResult this[int index] - => default!; - TResult IReadOnlyList.this[int index] - => this[index]; - TResult IList.this[int index] - { - get => this[index]!; - set => throw new NotSupportedException(); - } - - public Enumerator GetEnumerator() - => new(); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - public struct Enumerator - { - } - - public struct DisposableEnumerator - : IEnumerator - { - public readonly TResult Current => default!; - readonly object IEnumerator.Current => default!; - - public bool MoveNext() - => false; - - public readonly void Reset() - => throw new NotSupportedException(); - - public void Dispose() { } - } - - public bool Any() - => source.Count is not 0; - - public bool Contains(TResult value, IEqualityComparer? comparer = default) - => default; - - public ArraySegmentSelectEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => Select, TResult2>(new FunctionWrapper(selector)); - - public ArraySegmentSelectEnumerable> Select(TSelector2 selector = default) - where TSelector2 : struct, IFunction - => Select>(source, new SelectorCombination(this.selector, selector)); - } - - public static int Count(this ArraySegmentSelectEnumerable source) - where TSelector : struct, IFunction - => 0; - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ValueEnumerable.cs deleted file mode 100644 index 022d483f3..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Select.ValueEnumerable.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] - public static SelectEnumerable> Select(this TEnumerable source, Func selector) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => Select>(source, new FunctionWrapper(selector)); - - public static SelectEnumerable Select(this TEnumerable source, TSelector selector = default) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => new(source, selector); - - [GeneratorMapping("TSource", "TResult")] - public readonly partial struct SelectEnumerable - : IValueEnumerable.DisposableEnumerator> - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - { - readonly TEnumerable source; - readonly TSelector selector; - - internal SelectEnumerable(TEnumerable source, TSelector selector) - => (this.source, this.selector) = (source, selector); - - public Enumerator GetEnumerator() - => new(); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - public struct Enumerator - { - } - - public struct DisposableEnumerator - : IEnumerator - { - public readonly TResult Current => default!; - readonly object IEnumerator.Current => default!; - - public bool MoveNext() - => false; - - public readonly void Reset() - => throw new NotSupportedException(); - - public void Dispose() { } - } - - public int Count() - => source.Count(); - - public SelectEnumerable, TSource, TResult, TResult2>> Select(Func selector) - => Select, TResult2>(new FunctionWrapper(selector)); - - public SelectEnumerable> Select(TSelector2 selector = default) - where TSelector2 : struct, IFunction - => Select>(source, new SelectorCombination(this.selector, selector)); - } - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ToDictionary.ArraySegment.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ToDictionary.ArraySegment.cs deleted file mode 100644 index da24d7b1b..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/ToDictionary.ArraySegment.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ToDictionary(this in ArraySegment source, Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - { - if (keySelector is null) throw new ArgumentNullException(nameof(keySelector)); - - return ToDictionary>(source, new FunctionWrapper(keySelector), comparer); - } - - public static Dictionary ToDictionary(this in ArraySegment source, TKeySelector keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - { - var dictionary = new Dictionary(source.Count, comparer); - return dictionary; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Dictionary ToDictionary(this in ArraySegment source, Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - { - if (keySelector is null) throw new ArgumentNullException(nameof(keySelector)); - if (elementSelector is null) throw new ArgumentNullException(nameof(elementSelector)); - - return ToDictionary, FunctionWrapper>(source, new FunctionWrapper(keySelector), new FunctionWrapper(elementSelector), comparer); - } - - public static Dictionary ToDictionary(this in ArraySegment source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - where TElementSelector : struct, IFunction - { - var dictionary = new Dictionary(source.Count, comparer); - return dictionary; - } - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs deleted file mode 100644 index 9b5686549..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ArraySegment.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ArrayExtensions - { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] - static ArraySegmentWhereEnumerable> Where(this in ArraySegment source, Func predicate) - => Where(source, new FunctionWrapper(predicate)); - - static ArraySegmentWhereEnumerable Where(this in ArraySegment source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => new(source, predicate); - - public readonly partial struct ArraySegmentWhereEnumerable - : IValueEnumerable.DisposableEnumerator> - where TPredicate : struct, IFunction - { - readonly ArraySegment source; - readonly TPredicate predicate; - - internal ArraySegmentWhereEnumerable(in ArraySegment source, TPredicate predicate) - => (this.source, this.predicate) = (source, predicate); - - public Enumerator GetEnumerator() - => new(); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - public struct Enumerator - { - } - - public struct DisposableEnumerator - : IEnumerator - { - public readonly TSource Current => default!; - readonly TSource IEnumerator.Current => default!; - readonly object? IEnumerator.Current => default; - - public bool MoveNext() - => false; - - public readonly void Reset() - => throw new NotSupportedException(); - - public void Dispose() { } - } - - public bool Any() - => source.Any(predicate); - - public static bool Any(Func predicate) - => default; - - public static bool Any(TPredicate2 predicate = default) - where TPredicate2 : struct, IFunction - => default; - - public ArraySegmentWhereEnumerable, TSource>> Where(Func predicate) - => Where(new FunctionWrapper(predicate)); - - public ArraySegmentWhereEnumerable> Where(TPredicate2 predicate = default) - where TPredicate2 : struct, IFunction - => Where>(source, new PredicateCombination(this.predicate, predicate)); - } - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ValueEnumerable.cs deleted file mode 100644 index 6d5a8dcc0..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/TestData/Source/Where.ValueEnumerable.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] - public static WhereEnumerable> Where(this TEnumerable source, Func predicate) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => Where>(source, new FunctionWrapper(predicate)); - - public static WhereEnumerable Where(this TEnumerable source, TPredicate predicate = default) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunction - => new(source, predicate); - - public readonly partial struct WhereEnumerable - : IValueEnumerable.DisposableEnumerator> - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunction - { - readonly TEnumerable source; - readonly TPredicate predicate; - - internal WhereEnumerable(TEnumerable source, TPredicate predicate) - => (this.source, this.predicate) = (source, predicate); - - public Enumerator GetEnumerator() - => new(); - - DisposableEnumerator IValueEnumerable.GetEnumerator() - => new(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => new DisposableEnumerator(); - - public struct Enumerator - { - } - - public struct DisposableEnumerator - : IEnumerator - { - public readonly TSource Current => default!; - readonly TSource IEnumerator.Current => default!; - readonly object? IEnumerator.Current => default; - - public bool MoveNext() - => false; - - public readonly void Reset() - => throw new NotSupportedException(); - - public void Dispose() { } - } - - public bool Any() - => source.Any(predicate); - - public bool Any(Func predicate) - => Any(new FunctionWrapper(predicate)); - - public bool Any(TPredicate2 predicate = default) - where TPredicate2 : struct, IFunction - => source.Any>(new PredicateCombination(this.predicate, predicate)); - - public WhereEnumerable, TSource>> Where(Func predicate) - => Where(new FunctionWrapper(predicate)); - - public WhereEnumerable> Where(TPredicate2 predicate = default) - where TPredicate2 : struct, IFunction - => Where>(source, new PredicateCombination(this.predicate, predicate)); - } - } -} - diff --git a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/Verifier.cs b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/Verifier.cs index a22381d28..102ea391c 100644 --- a/NetFabric.Hyperlinq.SourceGenerator.UnitTests/Verifier.cs +++ b/NetFabric.Hyperlinq.SourceGenerator.UnitTests/Verifier.cs @@ -2,17 +2,14 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Text; using System.Collections.Generic; +using System.Collections.Immutable; +using System.IO; using System.Linq; namespace NetFabric.Hyperlinq.SourceGenerator.UnitTests { sealed class Verifier { - static readonly MetadataReference corlibReference = MetadataReference.CreateFromFile(typeof(object).Assembly.Location); - static readonly MetadataReference systemCoreReference = MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location); - static readonly MetadataReference cSharpSymbolsReference = MetadataReference.CreateFromFile(typeof(CSharpCompilation).Assembly.Location); - static readonly MetadataReference codeAnalysisReference = MetadataReference.CreateFromFile(typeof(Compilation).Assembly.Location); - static readonly string defaultFilePathPrefix = "Test"; static readonly string testProjectName = "TestProject"; @@ -20,13 +17,23 @@ public static Project CreateProject(IEnumerable sources) { var projectId = ProjectId.CreateNewId(debugName: testProjectName); + var coreLibPath = typeof(object).Assembly.Location; + var coreLibDirectory = Path.GetDirectoryName(coreLibPath)!; + var references = new[] { + MetadataReference.CreateFromFile(coreLibPath), + MetadataReference.CreateFromFile(Path.Combine(coreLibDirectory, "netstandard.dll")), + MetadataReference.CreateFromFile(Path.Combine(coreLibDirectory, "System.Runtime.dll")), + MetadataReference.CreateFromFile(Path.Combine(coreLibDirectory, "System.Collections.dll")), + MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location), + MetadataReference.CreateFromFile(typeof(ImmutableArray<>).Assembly.Location), + MetadataReference.CreateFromFile(typeof(IValueEnumerable<,>).Assembly.Location), + MetadataReference.CreateFromFile(typeof(ValueEnumerableExtensions).Assembly.Location), + }; var solution = new AdhocWorkspace() .CurrentSolution .AddProject(projectId, testProjectName, testProjectName, LanguageNames.CSharp) - .AddMetadataReference(projectId, corlibReference) - .AddMetadataReference(projectId, systemCoreReference) - .AddMetadataReference(projectId, cSharpSymbolsReference) - .AddMetadataReference(projectId, codeAnalysisReference); + .AddMetadataReferences(projectId, references) + .WithProjectCompilationOptions(projectId, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); var count = 0; foreach (var source in sources) diff --git a/NetFabric.Hyperlinq.SourceGenerator/CompilationContext.cs b/NetFabric.Hyperlinq.SourceGenerator/CompilationContext.cs index 7dedf96f5..a2a169618 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/CompilationContext.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/CompilationContext.cs @@ -1,4 +1,5 @@ using Microsoft.CodeAnalysis; +using NetFabric.CodeAnalysis; using System; namespace NetFabric.Hyperlinq.SourceGenerator diff --git a/NetFabric.Hyperlinq.SourceGenerator/Generator.AsValueEnumerable.cs b/NetFabric.Hyperlinq.SourceGenerator/Generator.AsValueEnumerable.cs new file mode 100644 index 000000000..45e8112e4 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator/Generator.AsValueEnumerable.cs @@ -0,0 +1,403 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using NetFabric.CodeAnalysis; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Threading; + +namespace NetFabric.Hyperlinq.SourceGenerator +{ + public partial class Generator + { + static ValueEnumerableType? GenerateAsValueEnumerable(Compilation compilation, SemanticModel semanticModel, TypeSymbolsCache typeSymbolsCache, MemberAccessExpressionSyntax expressionSyntax, CodeBuilder builder, Dictionary generatedMethods, CancellationToken cancellationToken, bool isUnitTest) + { + // Check if the method is already defined in the project source + if (semanticModel.GetSymbolInfo(expressionSyntax, cancellationToken).Symbol is IMethodSymbol { } methodSymbol) + return new ValueEnumerableType( + Name: methodSymbol.ReturnType.Name, + IsCollection: methodSymbol.ReturnType.ImplementsInterface(typeSymbolsCache["NetFabric.Hyperlinq.IValueReadOnlyCollection`2"]!, out var _), + IsList: methodSymbol.ReturnType.ImplementsInterface(typeSymbolsCache["NetFabric.Hyperlinq.IValueReadOnlyList`2"]!, out var _)); + + // Get the type this operator is applied to + var receiverTypeSymbol = semanticModel.GetTypeInfo(expressionSyntax.Expression, cancellationToken).Type; + + // Check if NetFabric.Hyperlinq already contains specific overloads for this type + // This is required for when the 'using NetFabric.Hyperlinq;' statement is missing + if (receiverTypeSymbol is null + or { TypeKind: TypeKind.Array } // is array + || SymbolEqualityComparer.Default.Equals(receiverTypeSymbol.OriginalDefinition, typeSymbolsCache[typeof(ArraySegment<>)]) + || SymbolEqualityComparer.Default.Equals(receiverTypeSymbol.OriginalDefinition, typeSymbolsCache[typeof(Span<>)]) + || SymbolEqualityComparer.Default.Equals(receiverTypeSymbol.OriginalDefinition, typeSymbolsCache[typeof(ReadOnlySpan<>)]) + || SymbolEqualityComparer.Default.Equals(receiverTypeSymbol.OriginalDefinition, typeSymbolsCache[typeof(Memory<>)]) + || SymbolEqualityComparer.Default.Equals(receiverTypeSymbol.OriginalDefinition, typeSymbolsCache[typeof(ReadOnlyMemory<>)]) + || SymbolEqualityComparer.Default.Equals(receiverTypeSymbol.OriginalDefinition, typeSymbolsCache[typeof(List<>)]) + || SymbolEqualityComparer.Default.Equals(receiverTypeSymbol.OriginalDefinition, typeSymbolsCache[typeof(ImmutableArray<>)]) + ) + return null; // Do generate an implementation. The 'using NetFabric.Hyperlinq;' statement should be added instead. + + // Receiver type implements IValueEnumerable<,> + + var valueEnumerableType = AsValueEnumerable(expressionSyntax, compilation, semanticModel, typeSymbolsCache, expressionSyntax, builder, generatedMethods, cancellationToken, isUnitTest); + if (valueEnumerableType is not null) + { + // Check if the method is already defined by this generator + var methodSignature = new MethodSignature("AsValueEnumerable", valueEnumerableType.Name); + if (generatedMethods.TryGetValue(methodSignature, out var returnType)) + return returnType; + + // Receiver instance returns itself + _ = builder + .AppendLine() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public static {valueEnumerableType.Name} AsValueEnumerable(this {valueEnumerableType.Name} source)") + .AppendIdentation().AppendLine($"=> source;"); + + // A new AsValueEnumerable() method has been generated + generatedMethods.Add(methodSignature, valueEnumerableType); + return valueEnumerableType; + } + + // Receiver type is an enumerable + + if (receiverTypeSymbol.IsEnumerable(compilation, out var enumerableSymbols)) + { + var receiverTypeString = receiverTypeSymbol.ToDisplayString(); + + // Check if the method is already defined by this generator + var methodSignature = new MethodSignature("AsValueEnumerable", receiverTypeString); + if (generatedMethods.TryGetValue(methodSignature, out var returnType)) + return returnType; + + // Use an unique identifier to avoid name clashing + var uniqueIdString = isUnitTest + ? receiverTypeString.Replace('.', '_').Replace(',', '_').Replace('<', '_').Replace('>', '_').Replace('`', '_') + : Guid.NewGuid().ToString().Replace('-', '_'); // Use a GUID to avoid naming overflow + + var enumerableTypeString = $"AsValueEnumerable_{uniqueIdString}"; + var itemType = enumerableSymbols.EnumeratorSymbols.Current.Type; + var itemTypeString = itemType.ToDisplayString(); + + // Check if the returned type by GetEnumerator() does not require a wrapper + var getEnumeratorReturnType = enumerableSymbols.GetEnumerator.ReturnType; + var getEnumeratorReturnTypeString = getEnumeratorReturnType.ToDisplayString(); + + // Check what interfaces the enumerable implements, minimizing the calls to ImplementsInterface() + var enumerableImplementsIEnumerable = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_IEnumerable_T, out var _); + var enumerableImplementsICollection = false; + var enumerableImplementsIReadOnlyCollection = false; + var enumerableImplementsIList = false; + var enumerableImplementsIReadOnlyList = false; + if (enumerableImplementsIEnumerable) + { + enumerableImplementsICollection = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_ICollection_T, out var _); + if (enumerableImplementsICollection) + enumerableImplementsIList = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_IList_T, out var _); + + enumerableImplementsIReadOnlyCollection = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_IReadOnlyCollection_T, out var _); + if (enumerableImplementsIReadOnlyCollection) + enumerableImplementsIReadOnlyList = receiverTypeSymbol.ImplementsInterface(SpecialType.System_Collections_Generic_IReadOnlyList_T, out var _); + } + + // Define what value enumerator type will be used + var enumeratorImplementsIEnumerator = getEnumeratorReturnType.ImplementsInterface(SpecialType.System_Collections_Generic_IEnumerator_T, out var _); + var useConstraints = enumerableImplementsIEnumerable; + + var enumeratorTypeString = enumeratorImplementsIEnumerator + ? getEnumeratorReturnType.IsValueType + ? getEnumeratorReturnTypeString + : $"ValueEnumerator<{itemTypeString}>" + : useConstraints + ? $"{enumerableTypeString}.Enumerator" + : $"{enumerableTypeString}.Enumerator"; + + // Generate the method + _ = useConstraints + ? builder + .AppendLine() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public static {enumerableTypeString}<{receiverTypeString}> AsValueEnumerable(this {receiverTypeString} source)") + .AppendIdentation().AppendLine($"=> new(source, source);") + : builder + .AppendLine() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public static {enumerableTypeString} AsValueEnumerable(this {receiverTypeString} source)") + .AppendIdentation().AppendLine($"=> new(source);"); + + // Generate the value enumerable wrapper + string valueEnumerableTypeName; + valueEnumerableTypeName = useConstraints + ? $"{enumerableTypeString}" + : enumerableTypeString; + + _ = builder + .AppendLine() + .AppendLine($"public readonly struct {valueEnumerableTypeName}"); + + // Define what interfaces the wrapper implements + if (enumerableImplementsIList || enumerableImplementsIReadOnlyList) + _ = builder.AppendIdentation().AppendLine($": IValueReadOnlyList<{itemTypeString}, {enumeratorTypeString}>, IList<{itemTypeString}>"); + else if (enumerableImplementsICollection || enumerableImplementsIReadOnlyCollection) + _ = builder.AppendIdentation().AppendLine($": IValueReadOnlyCollection<{itemTypeString}, {enumeratorTypeString}>, ICollection<{itemTypeString}>"); + else + _ = builder.AppendIdentation().AppendLine($": IValueEnumerable<{itemTypeString}, {enumeratorTypeString}>"); + + if (useConstraints) + { + if (enumerableImplementsIList) + _ = builder.AppendIdentation().AppendLine($"where TEnumerable : IList"); + else if (enumerableImplementsIReadOnlyList) + _ = builder.AppendIdentation().AppendLine($"where TEnumerable : IReadOnlyList"); + else if (enumerableImplementsICollection) + _ = builder.AppendIdentation().AppendLine($"where TEnumerable : ICollection"); + else if (enumerableImplementsIReadOnlyCollection) + _ = builder.AppendIdentation().AppendLine($"where TEnumerable : IReadOnlyCollection"); + else if (enumerableImplementsIEnumerable) + _ = builder.AppendIdentation().AppendLine($"where TEnumerable : IEnumerable"); + } + + using (builder.AppendBlock()) + { + // Define fields + _ = builder.AppendLine($"readonly {receiverTypeString} source;"); + if (useConstraints) + _ = builder.AppendLine($"readonly TEnumerable source2;"); + + // Define constructor + _ = useConstraints + ? builder + .AppendLine() + .AppendLine($"internal {enumerableTypeString}({receiverTypeString} source, TEnumerable source2)") + .AppendIdentation().AppendLine($"=> (this.source, this.source2) = (source, source2);") + : builder + .AppendLine() + .AppendLine($"internal {enumerableTypeString}({receiverTypeString} source)") + .AppendIdentation().AppendLine($"=> this.source = source;"); + + // Implement IValueEnumerable<,> + + _ = builder + .AppendLine() + .AppendLine($"// Implement IValueEnumerable<{itemTypeString}, {enumeratorTypeString}>") + .AppendLine(); + + if (enumeratorImplementsIEnumerator) + { + if (getEnumeratorReturnType.IsValueType) + { + // No enumerator wrapper required + _ = builder + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public {enumeratorTypeString} GetEnumerator() => source.GetEnumerator();") + .AppendLine() + .AppendLine($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator() => source2.GetEnumerator();") + .AppendLine() + .AppendLine($"IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator();"); + } + else if (enumerableSymbols.GetEnumerator.ContainingType.IsInterface()) + { + // Use the ValueEnumerator<> enumerator wrapper + _ = builder + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public ValueEnumerator<{itemTypeString}> GetEnumerator() => new(source2.GetEnumerator());") + .AppendLine() + .AppendLine($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator() => source2.GetEnumerator();") + .AppendLine() + .AppendLine($"IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator();"); + } + else + { + // Use the ValueEnumerator<> enumerator wrapper + _ = builder + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public ValueEnumerator<{itemTypeString}> GetEnumerator() => new(source.GetEnumerator());") + .AppendLine() + .AppendLine($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator() => source2.GetEnumerator();") + .AppendLine() + .AppendLine($"IEnumerator IEnumerable.GetEnumerator() => source2.GetEnumerator();"); + } + } + else + { + // A custom enumerator wrapper is required + + _ = builder + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public Enumerator GetEnumerator() => new(source.GetEnumerator());") + .AppendLine() + .AppendLine($"IEnumerator<{itemTypeString}> IEnumerable<{itemTypeString}>.GetEnumerator() => new Enumerator(source.GetEnumerator());") + .AppendLine() + .AppendLine($"IEnumerator IEnumerable.GetEnumerator() => new Enumerator(source.GetEnumerator());") + .AppendLine(); + + using (builder.AppendBlock($"public struct Enumerator : IEnumerator<{itemTypeString}>")) + { + _ = builder + .AppendLine($"readonly {getEnumeratorReturnTypeString} source;") + .AppendLine() + .AppendLine($"internal Enumerator({getEnumeratorReturnTypeString} source)") + .AppendIdentation().AppendLine("=> this.source = source;") + .AppendLine() + .AppendLine($"public {itemTypeString} Current => source.Current;") + .AppendLine() + .AppendLine("object? IEnumerator.Current => source.Current;") + .AppendLine() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine("public bool MoveNext() => source.MoveNext();") + .AppendLine(); + + _ = enumerableSymbols.EnumeratorSymbols.Reset is null + ? builder + .AppendLine("public void Reset() => throw new NotSupportedException();") + : builder + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine("public void Reset() => source.Reset();"); + + _ = enumerableSymbols.EnumeratorSymbols.Dispose is null + ? builder + .AppendLine() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine("public void Dispose() { }") + : builder + .AppendLine() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine("public void Dispose() => source.Dispose();"); + } + } + + // Implement ICollection<> + + if (enumerableImplementsICollection || enumerableImplementsIReadOnlyCollection) + { + _ = builder + .AppendLine() + .AppendLine($"// Implement ICollection<{itemTypeString}>") + .AppendLine() + .AppendLine("public int Count => source2.Count;") + .AppendLine() + .AppendLine("public bool IsReadOnly => true;") + .AppendLine() + .AppendLine($"void ICollection<{itemTypeString}>.Add({itemTypeString} item) => throw new NotSupportedException();") + .AppendLine() + .AppendLine($"bool ICollection<{itemTypeString}>.Remove({itemTypeString} item) => throw new NotSupportedException();") + .AppendLine() + .AppendLine($"void ICollection<{itemTypeString}>.Clear() => throw new NotSupportedException();") + .AppendLine(); + + // Add a CopyTo() that takes a Span<> as parameter + using (builder.AppendBlock($"public void CopyTo(Span<{itemTypeString}> span)")) + { + _ = builder + .AppendLine("if (Count is 0) return;") + .AppendLine("if (span.Length < Count) throw new ArgumentException(\"Destination span was not long enough.\", nameof(span));") + .AppendLine(); + + _ = builder.AppendLine("var index = 0;"); + using (builder.AppendBlock("foreach (var current in this)")) + { + _ = builder + .AppendLine("span[index] = current;") + .AppendLine("checked { index++; }"); + } + } + + if (enumerableImplementsICollection) + { + // Call the methods implemented by the source + _ = builder + .AppendLine() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public bool Contains({itemTypeString} item) => source2.Contains(item);") + .AppendLine() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public void CopyTo({itemTypeString}[] array, int arrayIndex) => source2.CopyTo(array, arrayIndex);"); + } + else + { + // The source does not implement these methods so we have to add an implementation + _ = builder.AppendLine(); + + using (builder.AppendBlock($"public bool Contains({itemTypeString} item)")) + { + using (builder.AppendBlock($"foreach (var current in this)")) + { + _ = builder.AppendLine($"if (EqualityComparer<{itemTypeString}>.Default.Equals(current, item)) return true;"); + } + _ = builder.AppendLine("return true;"); + } + + _ = builder + .AppendLine() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public void CopyTo({itemTypeString}[] array, int arrayIndex) => CopyTo(array.AsSpan(arrayIndex));"); + } + + // Implement ICollection<> + + if (enumerableImplementsIList || enumerableImplementsIReadOnlyList) + { + _ = builder + .AppendLine() + .AppendLine($"// Implement IList<{itemTypeString}>") + .AppendLine() + .AppendLine($"public {itemTypeString} this[int index] => source2[index];") + .AppendLine(); + + using (builder.AppendBlock($"{itemTypeString} IList<{itemTypeString}>.this[int index]")) + { + _ = builder + .AppendLine("get => source2[index];") + .AppendLine("set => throw new NotSupportedException();"); + } + + _ = builder + .AppendLine() + .AppendLine($"void IList<{itemTypeString}>.Insert(int index, {itemTypeString} item) => throw new NotSupportedException();") + .AppendLine() + .AppendLine($"void IList<{itemTypeString}>.RemoveAt(int index) => throw new NotSupportedException();") + .AppendLine(); + + if (enumerableImplementsIList) + { + // Call the methods implemented by the source + _ = builder + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public int IndexOf({itemTypeString} item) => source2.IndexOf(item);"); + } + else + { + // The source does not implement these methods so we have to add an implementation + using (builder.AppendBlock($"public int IndexOf({itemTypeString} item)")) + { + using (builder.AppendBlock($"if (Count is not 0)")) + { + _ = builder.AppendLine("var index = 0;"); + using (builder.AppendBlock($"foreach (var current in this)")) + { + _ = builder + .AppendLine($"if (EqualityComparer<{itemTypeString}>.Default.Equals(current, item)) return index;") + .AppendLine() + .AppendLine("checked { index++; }"); + } + } + _ = builder.AppendLine("return -1;"); + } + } + } + } + + // A new AsValueEnumerable() method has been generated + valueEnumerableType = new ValueEnumerableType( + Name: valueEnumerableTypeName, + IsCollection: enumerableImplementsICollection || enumerableImplementsIReadOnlyCollection, + IsList: enumerableImplementsIList || enumerableImplementsIReadOnlyList); + generatedMethods.Add(methodSignature, valueEnumerableType); + return valueEnumerableType; + } + } + + return null; + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.SourceGenerator/Generator.cs b/NetFabric.Hyperlinq.SourceGenerator/Generator.cs new file mode 100644 index 000000000..337bfaae7 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator/Generator.cs @@ -0,0 +1,234 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Text; +using NetFabric.CodeAnalysis; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading; + +namespace NetFabric.Hyperlinq.SourceGenerator +{ + [Generator] + public partial class Generator + : ISourceGenerator + { + static readonly DiagnosticDescriptor unhandledExceptionError = new( + id: "HPLG001", + title: "Unhandled exception while generating overloads", + messageFormat: "Unhandled exception while generating overloads: {0}", + category: "OverloadsGenerator", + DiagnosticSeverity.Error, + isEnabledByDefault: true); + + internal static readonly ImmutableHashSet methods = ImmutableHashSet.Create(new[] + { + // aggregation + "Count", + "CountAsync", + "Sum", + "SumVector", + "SumAsync", + + // conversion + "AsEnumerable", + "AsAsyncEnumerable", + "AsValueEnumerable", + "AsAsyncValueEnumerable", + "ToArray", + "ToArrayVector", + "ToArrayAsync", + "ToDictionary", + "ToDictionaryAsync", + "ToList", + "ToListVector", + "ToListAsync", + + // element + "ElementAt", + "ElementAtAsync", + "First", + "FirstAsync", + "Single", + "SingleAsync", + + // filtering + "Where", + "WhereAsync", + + // partitioning + "Skip", + "SkipAsync", + "Take", + "TakeAsync", + + // projection + "Select", + "SelectVector", + "SelectAsync", + "SelectMany", + "SelectManyAsync", + + // quantifier + "All", + "AllAsync", + "Any", + "AnyAsync", + "Contains", + "ContainsVector", + "ContainsAsync", + + // quantifier + "Distinct", + "DistinctAsync", + }); + + public void Initialize(GeneratorInitializationContext context) + { +#if DEBUG + if (!Debugger.IsAttached) + _ = Debugger.Launch(); +#endif + + context.RegisterForSyntaxNotifications(() => new SyntaxReceiver(methods)); + } + + public void Execute(GeneratorExecutionContext context) + { + var typeSymbolsCache = new TypeSymbolsCache(context.Compilation); + + // Check if NetFabric.Hyperlinq.Abstractions and NetFabric.Hyperlinq.Abstractions are referenced + if (typeSymbolsCache["NetFabric.Hyperlinq.IValueEnumerable`2"] is null + || typeSymbolsCache["NetFabric.Hyperlinq.ValueEnumerableExtensions"] is null) + return; // TODO: return a Diagnostic? + + if (context.SyntaxReceiver is not SyntaxReceiver receiver) + return; + + try + { + var builder = new CodeBuilder(); + GenerateSource(context.Compilation, typeSymbolsCache, receiver.MemberAccessExpressions, builder, context.CancellationToken); + context.AddSource("ExtensionMethods.g.cs", SourceText.From(builder.ToString(), Encoding.UTF8)); + } + catch (OperationCanceledException) + { + throw; + } + catch (Exception ex) + { + context.ReportDiagnostic(Diagnostic.Create(unhandledExceptionError, Location.None, ex.Message)); + } + } + + internal static void GenerateSource(Compilation compilation, TypeSymbolsCache typeSymbolsCache, List memberAccessExpressions, CodeBuilder builder, CancellationToken cancellationToken, bool isUnitTest = false) + { + var generatedMethods = new Dictionary(); + + _ = builder + .AppendLine("#nullable enable") + .AppendLine() + .AppendLine("using System;") + .AppendLine("using System.Collections;") + .AppendLine("using System.Collections.Generic;") + .AppendLine("using System.Runtime.CompilerServices;") + .AppendLine(); + + using (builder.AppendBlock("namespace NetFabric.Hyperlinq")) + using (builder.AppendBlock("static partial class GeneratedExtensionMethods")) + { + foreach (var expressionSyntax in memberAccessExpressions) + { + cancellationToken.ThrowIfCancellationRequested(); + + var semanticModel = compilation.GetSemanticModel(expressionSyntax.SyntaxTree); + + _ = GenerateSource(compilation, semanticModel, typeSymbolsCache, expressionSyntax, builder, generatedMethods, cancellationToken, isUnitTest); + } + } + } + + static ValueEnumerableType? AsValueEnumerable(MemberAccessExpressionSyntax memberAccessExpressionSyntax, Compilation compilation, SemanticModel semanticModel, TypeSymbolsCache typeSymbolsCache, MemberAccessExpressionSyntax expressionSyntax, CodeBuilder builder, Dictionary generatedMethods, CancellationToken cancellationToken, bool isUnitTest) + { + var typeSymbol = semanticModel.GetTypeInfo(memberAccessExpressionSyntax.Expression, cancellationToken).Type; + if (typeSymbol is null) + return null; + + // Check if the receiver type implements IValueEnumerable<,> + if (typeSymbol.ImplementsInterface(typeSymbolsCache["NetFabric.Hyperlinq.IValueEnumerable`2"]!, out var _)) + return new ValueEnumerableType( + Name: typeSymbol.ToDisplayString(), + IsCollection: typeSymbol.ImplementsInterface(typeSymbolsCache["NetFabric.Hyperlinq.IValueReadOnlyCollection`2"]!, out var _), + IsList: typeSymbol.ImplementsInterface(typeSymbolsCache["NetFabric.Hyperlinq.IValueReadOnlyList`2"]!, out var _)); + + // Go up one layer. Generate method is required. + if (expressionSyntax.Expression is InvocationExpressionSyntax { Expression: MemberAccessExpressionSyntax receiverSyntax }) + { + if (GenerateSource(compilation, semanticModel, typeSymbolsCache, receiverSyntax, builder, generatedMethods, cancellationToken, isUnitTest) is { } valueEnumerableType) + return valueEnumerableType; // Receiver type implements IValueEnumerable<,> + } + + // Receiver type does not implement IValueEnumerable<,> so nothing else needs to be done + return null; + } + + static ValueEnumerableType? GenerateSource(Compilation compilation, SemanticModel semanticModel, TypeSymbolsCache typeSymbolsCache, MemberAccessExpressionSyntax expressionSyntax, CodeBuilder builder, Dictionary generatedMethods, CancellationToken cancellationToken, bool isUnitTest) + => expressionSyntax.Name.ToString() switch + { + "AsValueEnumerable" => GenerateAsValueEnumerable(compilation, semanticModel, typeSymbolsCache, expressionSyntax, builder, generatedMethods, cancellationToken, isUnitTest), + _ => GenerateOperationSource(compilation, semanticModel, typeSymbolsCache, expressionSyntax, builder, generatedMethods, cancellationToken, isUnitTest), + }; + + static ValueEnumerableType? GenerateOperationSource(Compilation compilation, SemanticModel semanticModel, TypeSymbolsCache typeSymbolsCache, MemberAccessExpressionSyntax expressionSyntax, CodeBuilder builder, Dictionary generatedMethods, CancellationToken cancellationToken, bool isUnitTest) + { + var valueEnumerableType = AsValueEnumerable(expressionSyntax, compilation, semanticModel, typeSymbolsCache, expressionSyntax, builder, generatedMethods, cancellationToken, isUnitTest); + if (valueEnumerableType is null) + return null; + + var symbol = semanticModel.GetSymbolInfo(expressionSyntax, cancellationToken).Symbol; + if (symbol is IMethodSymbol methodSymbol) + { + // Check if the generator already generated this method + var parameters = new string[] { valueEnumerableType.Name }.Concat(methodSymbol.Parameters.Select(parameter => parameter.Type.ToDisplayString())).ToArray(); + var methodSignature = new MethodSignature(expressionSyntax.Name.ToString(), parameters); + if (generatedMethods.TryGetValue(methodSignature, out var returnType)) + return returnType; + + // Generate the extension method + var parametersString = string.Join(", ", + new string[] { $"{valueEnumerableType.Name} source" } + .Concat(methodSymbol.Parameters.Select(parameter => $"{parameter.Type.ToDisplayString()} {parameter.Name}"))); + var argumentsString = string.Join(", ", methodSymbol.Parameters.Select(parameter => parameter.Name)); + _ = builder + .AppendLine() + .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]") + .AppendLine($"public static {methodSymbol.ReturnType.ToDisplayString()} {methodSymbol.Name}(this {parametersString})") + .AppendIdentation().AppendLine($"=> source.{methodSymbol.Name}({argumentsString});"); + + generatedMethods.Add(methodSignature, returnType); + return returnType; + } + + + // TODO: when 'using System.Linq;' is not used... + if (expressionSyntax.Parent is InvocationExpressionSyntax invocation) + { + // Check if the source already provides the implementation as an instance method + + // Check if the source already provides the implementation as an extension method + + // Generate the extension method + + _ = builder + .AppendLine() + .AppendLine("// TODO"); + } + + return null; + } + } +} \ No newline at end of file diff --git a/NetFabric.Hyperlinq.SourceGenerator/MethodSignature.cs b/NetFabric.Hyperlinq.SourceGenerator/MethodSignature.cs new file mode 100644 index 000000000..c9769f2d6 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator/MethodSignature.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Immutable; +using System.Linq; + +namespace NetFabric.Hyperlinq.SourceGenerator +{ + readonly struct MethodSignature + : IEquatable + { + public MethodSignature(string name, params string[] parameters) + => (Name, Parameters) = (name, ImmutableArray.Create(parameters)); + + readonly string Name { get; } + readonly ImmutableArray Parameters { get; } + + public bool Equals(MethodSignature other) + => Name == other.Name && Parameters.SequenceEqual(other.Parameters); + + public override bool Equals(object other) + => other is MethodSignature signature && Equals(signature); + + public override int GetHashCode() + { + unchecked + { + const int HashingBase = (int)2166136261; + const int HashingMultiplier = 16777619; + + var hash = HashingBase; + hash = (hash * HashingMultiplier) ^ Name.GetHashCode(); + foreach(var parameter in Parameters) + hash = (hash * HashingMultiplier) ^ parameter.GetHashCode(); + return hash; + } + } + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj b/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj index 538195793..52fb05e19 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj +++ b/NetFabric.Hyperlinq.SourceGenerator/NetFabric.Hyperlinq.SourceGenerator.csproj @@ -2,16 +2,62 @@ netstandard2.0 - true + NetFabric.Hyperlinq.SourceGenerator + NetFabric.Hyperlinq.SourceGenerator + High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, Memory, and Span. + 3.0.0-beta45 + Icon.png + LICENSE + netfabric, hyperlinq, linq, enumeration, extensions, performance + true + true + false + + + + + + + + + + + + - - https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json ;$(RestoreAdditionalProjectSources) - + + + + + true + + + + true + + + + + + - - + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + all runtime; build; native; contentfiles; analyzers diff --git a/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs b/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs deleted file mode 100644 index 1852dbec3..000000000 --- a/NetFabric.Hyperlinq.SourceGenerator/OverloadsGenerator.cs +++ /dev/null @@ -1,409 +0,0 @@ -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Text; -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Diagnostics; -using System.Linq; -using System.Text; - -namespace NetFabric.Hyperlinq.SourceGenerator -{ - [Generator] - public class OverloadsGenerator - : ISourceGenerator - { - static readonly DiagnosticDescriptor unhandledExceptionError = new( - id: "HPLG001", - title: "Unhandled exception while generating overloads", - messageFormat: "Unhandled exception while generating overloads: {0}", - category: "OverloadsGenerator", - DiagnosticSeverity.Error, - isEnabledByDefault: true); - - - public void Initialize(GeneratorInitializationContext context) - { - } - - public void Execute(GeneratorExecutionContext context) - { - //_ = Debugger.Launch(); // uncomment to debug this source generator - - var compilationContext = new CompilationContext(context.Compilation); - - try - { - var collectedExtensionMethods = CollectExtensionMethods(compilationContext); - - var generatedSources = GenerateSource(collectedExtensionMethods, compilationContext); - foreach (var (containerClass, extendingType, generatedSource) in generatedSources) - { - var hitName = $"{containerClass.OriginalDefinition.MetadataName}.{extendingType.OriginalDefinition.MetadataName}.g.cs"; - hitName = hitName.Replace('`', '.'); - context.AddSource(hitName, SourceText.From(generatedSource, Encoding.UTF8)); - } - - } - catch (Exception ex) - { - context.ReportDiagnostic(Diagnostic.Create(unhandledExceptionError, Location.None, ex.Message)); - } - } - - /// - /// Collects all the extension methods defined - /// - /// - /// A dictionary containing collections of the extension methods per type extended. - internal DictionarySet CollectExtensionMethods(CompilationContext context) - { - var collectedExtensionMethods = new DictionarySet(); - - // go through all implemented static types and get all the extension methods implemented - var extensionMethods = context.Compilation.SourceModule.GlobalNamespace - .GetAllTypes() - .Where(typeSymbol => - typeSymbol.IsStatic - && typeSymbol.IsPublic() - ) - .SelectMany(typeSymbol => - typeSymbol.GetMembers() - .OfType() - .Where(methodSymbol => - methodSymbol.IsExtensionMethod - //&& methodSymbol.IsPublic() - && !methodSymbol.ShouldIgnore(context) - ) - ); - - // go through all extension methods - foreach (var extensionMethod in extensionMethods) - { - var extensionType = extensionMethod.Parameters[0].Type; - var generic = extensionMethod.TypeParameters - .FirstOrDefault(typeParameter - => typeParameter.ConstraintTypes.Length > 0 - && typeParameter.Name == extensionType.Name); - if (generic is null) - { - var name = extensionMethod.Parameters[0].Type.OriginalDefinition.MetadataName; - switch (name) - { - case "ArraySegment`1": - case "ReadOnlySpan`1": - case "ReadOnlyMemory`1": - collectedExtensionMethods.Add(name, extensionMethod.GetInfo(context, 1)); - break; - } - } - else - { - // the extended type is a constrained generic parameter - var extendingType = generic.ConstraintTypes[0]; - var name = extendingType.OriginalDefinition.MetadataName; - switch (name) - { - case "IValueEnumerable`2": - case "IValueReadOnlyCollection`2": - case "IValueReadOnlyList`2": - case "IReadOnlyList`1": - case "IAsyncValueEnumerable`2": - collectedExtensionMethods.Add(name, extensionMethod.GetInfo(context, 1)); - break; - } - } - } - - return collectedExtensionMethods; - } - - /// - /// Generates the source for the overloads based on the defined extension methods. - /// - /// - /// A dictionary containing the defined extension methods. - /// The path where to serialize the generated code for debugging. - internal IEnumerable<(INamedTypeSymbol ContainerClass, INamedTypeSymbol ExtendedType, string Source)> GenerateSource(DictionarySet collectedExtensionMethods, CompilationContext context) - { - // go through all candidate types to be extended - // these are inner types of a public static class that are not static and not interfaces - foreach (var extendingType in context.Compilation.SourceModule.GlobalNamespace - .GetAllTypes() - .Where(type => type.IsStatic && type.IsReferenceType && type.IsPublic() && !type.ShouldIgnore(context)) - .SelectMany(containerType => containerType.GetTypeMembers().OfType() - .Where(type => !(type.IsStatic || type.IsInterface() || type.ShouldIgnore(context))))) - { - var bindingAttribute = extendingType.GetBindingsAttribute(context); - foreach (var source in GenerateSource(collectedExtensionMethods, context, extendingType, bindingAttribute)) - yield return source; - } - } - - IEnumerable<(INamedTypeSymbol ContainerClass, INamedTypeSymbol ExtendedType, string Source)> GenerateSource(DictionarySet collectedExtensionMethods, CompilationContext context, INamedTypeSymbol extendingType, GeneratorBindingsAttribute? bindingsAttribute) - { - // check if it's a value enumerable and keep a reference to the implemented interface - var valueEnumerableInterface = extendingType.GetAllInterfaces() - .FirstOrDefault(@interface => @interface.Name is "IValueEnumerable" or "IAsyncValueEnumerable"); - if (valueEnumerableInterface is not null || bindingsAttribute is not null) - { - // get the types of the enumerable, enumerator and source from the generic parameters declaration - var enumerableType = extendingType; - var enumeratorType = valueEnumerableInterface?.TypeArguments[1]; - var sourceType = valueEnumerableInterface?.TypeArguments[0]; - - // get the type mappings from the GeneratorMappingsAttribute, if found. - var typeGenericsMapping = extendingType.GetGenericsMappings(context); - - // get the info of all the instance methods declared in the type to be extended - var implementedInstanceMethods = extendingType.GetMembers().OfType() - .Where(method => method.Name is not ".ctor") // ignore the constructors - .Select(method => method.GetInfo(context)) - .ToArray(); - - // get the extension methods for this type declared in the outter static type - var implementedExtensionMethods = extendingType.ContainingType.GetMembers().OfType() - .Where(method - => method.IsExtensionMethod - && method.Parameters[0].Type.ToDisplayString() == extendingType.ToDisplayString()) - .Select(method => method.GetInfo(context, 1)) - .ToArray(); - - // join the two lists together as these are the implemented methods for this type - var implementedMethods = implementedInstanceMethods.Concat(implementedExtensionMethods) - .ToList(); - - // lists of methods to be generated - var instanceMethodsToBeGenerated = new List(); - var extensionMethodsToBeGenerated = new List(); - - // go through all the implemented interfaces so that - // the overloads are generated based on the extension methods defined for these - var implementedTypes = - bindingsAttribute?.SourceImplements?.Split(',') - ?? extendingType.AllInterfaces.Select(type => type.OriginalDefinition.MetadataName); - - foreach (var implementedType in implementedTypes) - { - // get the extension methods collected for this interface - if (!collectedExtensionMethods.TryGetValue(implementedType, out var overloadingMethods)) - continue; - - // check which ones should be generated - // the method can be already defined by a more performant custom implementation - for (var methodIndex = 0; methodIndex < overloadingMethods.Count; methodIndex++) - { - var overloadingMethod = overloadingMethods[methodIndex]; - - // check if already implemented - var mappedOverloadingMethods = overloadingMethod.ApplyMappings(typeGenericsMapping); - if (!implementedMethods.Any(method => method.IsOverload(mappedOverloadingMethods)) - && !((mappedOverloadingMethods.Name is "Select" || mappedOverloadingMethods.Name is "SelectAt") && (extendingType.Name.EndsWith("SelectEnumerable") || extendingType.Name.EndsWith("SelectAtEnumerable")))) // these cases are hard to fix other way - { - // check if there's a collision with a property - if (extendingType.GetMembers().OfType() - .Any(property => property.Name == mappedOverloadingMethods.Name)) - { - // this method will be generated as an extension method - extensionMethodsToBeGenerated.Add(mappedOverloadingMethods); - } - else - { - // this method will generated as an instance method - instanceMethodsToBeGenerated.Add(mappedOverloadingMethods); - } - - implementedMethods.Add(mappedOverloadingMethods); - } - } - } - - // generate the code for the instance methods and extension methods, if any... - if (instanceMethodsToBeGenerated.Count is not 0 || extensionMethodsToBeGenerated.Count is not 0) - { - var builder = new CodeBuilder(); - _ = builder - .AppendLine("#nullable enable") - .AppendLine() - .AppendLine("using System;") - .AppendLine("using System.CodeDom.Compiler;") - .AppendLine("using System.Diagnostics;") - .AppendLine("using System.Runtime.CompilerServices;") - .AppendLine(); - - using (builder.AppendBlock($"namespace NetFabric.Hyperlinq")) - { - // the generator extends the types by adding partial types - // both the outter and the inner types have to be declared as partial - using (builder.AppendBlock($"public static partial class {extendingType.ContainingType.Name}")) - { - // generate the instance methods in the inner type - if (instanceMethodsToBeGenerated.Count is not 0) - { - var extendingTypeGenericParameters = string.Empty; - if (extendingType.IsGenericType) - { - var parametersDefinition = new StringBuilder(); - _ = parametersDefinition.Append($"<{extendingType.TypeParameters.Select(parameter => parameter.ToDisplayString()).ToCommaSeparated()}>"); - // foreach (var typeParameter in extendingType.TypeParameters.Where(typeParameter => typeParameter.ConstraintTypes.Length is not 0)) - // _ = parametersDefinition.Append($" where {typeParameter.Name} : {typeParameter.AsConstraintsStrings().ToCommaSeparated()}"); - extendingTypeGenericParameters = parametersDefinition.ToString(); - } - - var entity = extendingType.IsValueType - ? "struct" - : "class"; - using (builder.AppendBlock($"public partial {entity} {extendingType.Name}{extendingTypeGenericParameters}")) - { - foreach (var instanceMethod in instanceMethodsToBeGenerated) - { - var methodGenericsMapping = typeGenericsMapping.AddRange(instanceMethod.GenericsMapping); - GenerateMethodSource(builder, context, extendingType, instanceMethod, enumerableType, enumeratorType, sourceType, methodGenericsMapping, false, bindingsAttribute); - } - } - } - _ = builder.AppendLine(); - - // generate the extension methods in the outter type - foreach (var extensionMethod in extensionMethodsToBeGenerated) - { - var methodGenericsMapping = typeGenericsMapping.AddRange(extensionMethod.GenericsMapping); - GenerateMethodSource(builder, context, extendingType, extensionMethod, enumerableType, enumeratorType, sourceType, methodGenericsMapping, true, bindingsAttribute); - } - } - } - - var source = builder.ToString().Replace("TResult, TResult", "TSource, TResult"); - yield return (extendingType.ContainingType, extendingType, source); - } - } - } - - void GenerateMethodSource(CodeBuilder builder, CompilationContext context, INamedTypeSymbol extendingType, MethodInfo methodToGenerate, ITypeSymbol? enumerableType, ITypeSymbol? enumeratorType, ITypeSymbol sourceType, ImmutableArray genericsMapping, bool isExtensionMethod, GeneratorBindingsAttribute? bindingsAttribute) - { - var extendingTypeTypeArguments = extendingType.MappedTypeArguments(genericsMapping) - .ToArray(); - var typeParameters = isExtensionMethod - ? methodToGenerate.TypeParameters - .Where(typeParameter => - !typeParameter.IsConcreteType - && typeParameter.Name is not "TEnumerable" and not "TEnumerator" and not "TList") - .ToArray() - : methodToGenerate.TypeParameters - .Where(typeParameter => - !typeParameter.IsConcreteType - && typeParameter.Name is not "TEnumerable" and not "TEnumerator" and not "TList" - && !extendingTypeTypeArguments.Any(argument => argument.Name == typeParameter.Name)) - .ToArray(); - - var methodReturnType = methodToGenerate.ReturnType.ToDisplayString(); - var genericsIndex = methodReturnType.IndexOf('<'); - if (genericsIndex >= 0) - { - methodReturnType = methodReturnType.Substring(0, genericsIndex); - if (methodToGenerate.ReturnType is INamedTypeSymbol namedMethodReturnType) - { - if (bindingsAttribute is null) - methodReturnType += MapTypeProperties(namedMethodReturnType.TypeArguments.Select(argument => argument.ToDisplayString()), enumerableType!, enumeratorType!, sourceType, genericsMapping); - else - methodReturnType += MapTypeProperties(namedMethodReturnType.TypeArguments.Select(argument => argument.ToDisplayString()), bindingsAttribute); - } - } - if (methodReturnType is "TEnumerable") - methodReturnType = extendingType.ToDisplayString(); - - var methodName = methodToGenerate.Name; - var methodExtensionType = extendingType.ToDisplayString(); - var methodParameters = methodToGenerate.Parameters - .Select(parameter => parameter.DefaultValue is null - ? $"{parameter.Type} {parameter.Name}" - : $"{parameter.Type} {parameter.Name} = {parameter.DefaultValue}") - .ToCommaSeparated(); - var methodGenericParameters = typeParameters - .Select(typeParameter => typeParameter.Name) - .ToCommaSeparated(); - var methodGenericParametersString = methodGenericParameters.Any() - ? $"<{methodGenericParameters}>" - : string.Empty; - - var returnKeyword = string.Empty; - var callContainingType = methodToGenerate.ContainingType; - var callTypeParameters = bindingsAttribute is null - ? MapTypeProperties(methodToGenerate.TypeParameters.Select(parameter => parameter.Name), enumerableType!, enumeratorType!, sourceType, genericsMapping) - : MapTypeProperties(methodToGenerate.TypeParameters.Select(parameter => parameter.Name), bindingsAttribute); - var callParameters = methodToGenerate.Parameters.Select(parameter => parameter.Name).ToCommaSeparated(); - - // generate the source - _ = builder - .AppendLine(context.GeneratedCodeAttribute) - .AppendLine("[DebuggerNonUserCode]") - .AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]"); - - var firstCallParameter = bindingsAttribute?.Source ?? "this"; - - if (isExtensionMethod) - { - var extraMethodParameter = methodParameters is { Length: 0 } - ? string.Empty - : $", {methodParameters}"; - _ = builder.AppendLine($"public static {methodReturnType} {methodName}{methodGenericParametersString}(this {methodExtensionType} source{extraMethodParameter})"); - - firstCallParameter = bindingsAttribute is null - ? "source" - : $"source.{bindingsAttribute.Source}"; - } - else - { - var methodReadonly = extendingType.IsValueType ? "readonly" : string.Empty; - _ = builder.AppendLine($"public {methodReadonly} {methodReturnType} {methodName}{methodGenericParametersString}({methodParameters})"); - } - foreach (var (name, constraints, _) in typeParameters.Where(typeParameter => typeParameter.Constraints.Any())) - _ = builder.AppendLine($"where {name} : {constraints}"); - - callParameters = StringExtensions.CommaSeparateIfNotNullOrEmpty(firstCallParameter, callParameters, bindingsAttribute?.ExtraParameters); - - _ = builder - .AppendLine($"=> {callContainingType}.{methodName}{callTypeParameters}({callParameters});") - .AppendLine(); - } - - string MapTypeProperties(IEnumerable typePropertyNames, ITypeSymbol enumerableType, ITypeSymbol enumeratorType, ITypeSymbol sourceType, ImmutableArray genericsMapping) - { - var str = typePropertyNames.Select(typePropertyName => typePropertyName switch - { - "TEnumerable" or "TList" => enumerableType.ToDisplayString(genericsMapping), - "TEnumerator" => enumeratorType.ToDisplayString(genericsMapping), - "TSource" => sourceType.ToDisplayString(genericsMapping), - _ => typePropertyName.ApplyMappings(genericsMapping, out _), - }) - .ToCommaSeparated(); - - return str switch - { - { Length: 0 } => string.Empty, - _ => $"<{str}>" - }; - } - - string MapTypeProperties(IEnumerable typePropertyNames, GeneratorBindingsAttribute? bindingsAttribute) - { - var str = typePropertyNames.Select(typePropertyName => typePropertyName switch - { - "TEnumerable" or "TList" => bindingsAttribute?.EnumerableType ?? typePropertyName, - "TEnumerator" => bindingsAttribute?.EnumeratorType ?? typePropertyName, - "TSource" => bindingsAttribute?.ElementType ?? typePropertyName, - _ => typePropertyName, - }) - .ToCommaSeparated(); - - str = StringExtensions.CommaSeparateIfNotNullOrEmpty(str, bindingsAttribute?.ExtraTypeParameters); - - return str switch - { - { Length: 0 } => string.Empty, - _ => $"<{str}>" - }; - } - } -} diff --git a/NetFabric.Hyperlinq.SourceGenerator/SyntaxReceiver.cs b/NetFabric.Hyperlinq.SourceGenerator/SyntaxReceiver.cs new file mode 100644 index 000000000..56fd3dd59 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator/SyntaxReceiver.cs @@ -0,0 +1,33 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using System.Collections.Generic; +using System.Collections.Immutable; + +namespace NetFabric.Hyperlinq.SourceGenerator +{ + class SyntaxReceiver : ISyntaxReceiver + { + readonly ImmutableHashSet memberAccessNames; + + public SyntaxReceiver(ImmutableHashSet memberAccessNames) + => this.memberAccessNames = memberAccessNames; + + public List MemberAccessExpressions { get; } = new(); + + public void OnVisitSyntaxNode(SyntaxNode syntaxNode) + { + switch (syntaxNode) + { + case MemberAccessExpressionSyntax { Name: var memberName } memberAccessExpression: + if (memberAccessExpression.Kind() == SyntaxKind.SimpleMemberAccessExpression + && memberAccessNames.Contains(memberName.Identifier.ValueText)) + { + // It's a SimpleMemberAccessExpression and its name is in memberAccessNames collection + MemberAccessExpressions.Add(memberAccessExpression); + } + break; + } + } + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator/TypeSymbolsCache.cs b/NetFabric.Hyperlinq.SourceGenerator/TypeSymbolsCache.cs new file mode 100644 index 000000000..76ff6d584 --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator/TypeSymbolsCache.cs @@ -0,0 +1,50 @@ +using Ben.Collections; +using Microsoft.CodeAnalysis; +using System; +using System.Collections.Generic; + +namespace NetFabric.Hyperlinq.SourceGenerator +{ + class TypeSymbolsCache + { + readonly Compilation compilation; + readonly TypeDictionary cacheByType = new(); + readonly Dictionary cacheByName = new(); + + public TypeSymbolsCache(Compilation compilation) + => this.compilation = compilation; + + public INamedTypeSymbol? this[Type type] + { + get + { + if (cacheByType.TryGetValue(type, out var symbol)) + return symbol; + + if (cacheByName.TryGetValue(type.FullName, out symbol)) + { + cacheByType[type] = symbol; + } + else + { + symbol = compilation.GetTypeByMetadataName(type.FullName); + cacheByType[type] = symbol; + } + return symbol; + } + } + + public INamedTypeSymbol? this[string fullyQualifiedMetadataName] + { + get + { + if (cacheByName.TryGetValue(fullyQualifiedMetadataName, out var symbol)) + return symbol; + + symbol = compilation.GetTypeByMetadataName(fullyQualifiedMetadataName); + cacheByName[fullyQualifiedMetadataName] = symbol; + return symbol; + } + } + } +} diff --git a/NetFabric.Hyperlinq.SourceGenerator/Utils/CodeBuilder.cs b/NetFabric.Hyperlinq.SourceGenerator/Utils/CodeBuilder.cs index 1c57c05b2..01788ea8e 100644 --- a/NetFabric.Hyperlinq.SourceGenerator/Utils/CodeBuilder.cs +++ b/NetFabric.Hyperlinq.SourceGenerator/Utils/CodeBuilder.cs @@ -5,52 +5,61 @@ namespace NetFabric.Hyperlinq.SourceGenerator { class CodeBuilder { - static readonly string tab = " "; + static readonly string identation = " "; readonly StringBuilder builder = new(); int currentLevel = 0; - StringBuilder AppendIndentation() + StringBuilder Indent() { for (var level = 0; level < currentLevel; level++) - _ = builder.Append(tab); + _ = builder.Append(identation); return builder; } + public CodeBuilder AppendIdentation() + { + _ = builder.Append(identation); + return this; + } + public CodeBuilder AppendLine() { _ = builder.AppendLine(); return this; } - public CodeBuilder AppendLine(char line) + public CodeBuilder AppendLine(char text) { - _ = AppendIndentation().Append(line).AppendLine(); + _ = Indent().Append(text).AppendLine(); return this; } - public CodeBuilder AppendLine(string line) + public CodeBuilder AppendLine(string text) { - _ = AppendIndentation().AppendLine(line); + _ = Indent().AppendLine(text); return this; } public CodeBuilder AppendLine(Action line) { - _ = AppendIndentation(); + _ = Indent(); line(builder); _ = AppendLine(); return this; } - public IDisposable AppendBlock(string line) + public IDisposable AppendBlock() { - _ = AppendLine(line).AppendLine('{'); + _ = AppendLine('{'); currentLevel++; return new CloseBlock(this); } + public IDisposable AppendBlock(string text) + => AppendLine(text).AppendBlock(); + class CloseBlock : IDisposable { readonly CodeBuilder builder; diff --git a/NetFabric.Hyperlinq.SourceGenerator/ValueEnumerableType.cs b/NetFabric.Hyperlinq.SourceGenerator/ValueEnumerableType.cs new file mode 100644 index 000000000..3ca2ba90c --- /dev/null +++ b/NetFabric.Hyperlinq.SourceGenerator/ValueEnumerableType.cs @@ -0,0 +1,6 @@ +using System; + +namespace NetFabric.Hyperlinq.SourceGenerator +{ + record ValueEnumerableType(string Name, bool IsCollection, bool IsList); +} diff --git a/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj b/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj index 0158308fc..b32face15 100644 --- a/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj +++ b/NetFabric.Hyperlinq.UnitTests/NetFabric.Hyperlinq.UnitTests.csproj @@ -31,6 +31,7 @@ + diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs index 8579095be..027b9b9ad 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncEnumerable.cs @@ -28,11 +28,7 @@ public AsyncEnumerator GetAsyncEnumerator() IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken _) // ReSharper disable once HeapView.BoxingAllocation => new AsyncEnumerator(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public AsyncEnumerableExtensions.AsyncValueEnumerable, AsyncEnumerator, AsyncEnumerator, T, GetAsyncEnumeratorFunction, GetAsyncEnumeratorFunction> AsAsyncValueEnumerable() - => this.AsAsyncValueEnumerable, AsyncEnumerator, T, GetAsyncEnumeratorFunction>(); - + public readonly struct GetAsyncEnumeratorFunction : IFunction, CancellationToken, AsyncEnumerator> { diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs index cd44977d7..08841b05f 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsAsyncValueEnumerable.cs @@ -31,10 +31,6 @@ AsyncEnumerator IAsyncValueEnumerable>.GetAsyncEnumerat IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken _) // ReSharper disable once HeapView.BoxingAllocation => new AsyncEnumerator(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public AsyncValueEnumerableExtensions.AsyncValueEnumerable, AsyncEnumerator, AsyncEnumerator, T, GetAsyncEnumeratorFunction, GetAsyncEnumeratorFunction> AsAsyncValueEnumerable() - => AsyncValueEnumerableExtensions.AsAsyncValueEnumerable, AsyncEnumerator, T, GetAsyncEnumeratorFunction>(this); public readonly struct GetAsyncEnumeratorFunction : IFunction, CancellationToken, AsyncEnumerator> diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs index 088e62d28..bb738371e 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsEnumerable.cs @@ -31,10 +31,6 @@ IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => GetEnumerator(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public EnumerableExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() - => this.AsValueEnumerable, Enumerator, T, GetEnumeratorFunction>(); public readonly struct GetEnumeratorFunction : IFunction, Enumerator> diff --git a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs index efa262bde..63dff6ba2 100644 --- a/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs +++ b/NetFabric.Hyperlinq.UnitTests/Utils/Wrappers/Wrap.AsValueEnumerable.cs @@ -32,10 +32,6 @@ IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator() // ReSharper disable once HeapView.BoxingAllocation => GetEnumerator(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerableExtensions.ValueEnumerable, Enumerator, Enumerator, T, GetEnumeratorFunction, GetEnumeratorFunction> AsValueEnumerable() - => ValueEnumerableExtensions.AsValueEnumerable, Enumerator, T, GetEnumeratorFunction>(this); public readonly struct GetEnumeratorFunction : IFunction, Enumerator> diff --git a/NetFabric.Hyperlinq.sln b/NetFabric.Hyperlinq.sln index 77877123b..7b78c3d11 100644 --- a/NetFabric.Hyperlinq.sln +++ b/NetFabric.Hyperlinq.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.28516.95 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31423.177 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq", "NetFabric.Hyperlinq\NetFabric.Hyperlinq.csproj", "{EEEAA31B-434E-4849-A3E5-FA9664F5CE9B}" EndProject @@ -30,8 +30,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.SourceG EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.Abstractions", "NetFabric.Hyperlinq.Abstractions\NetFabric.Hyperlinq.Abstractions.csproj", "{6981E761-E698-437D-AF63-0E80844B7D41}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetFabric.Hyperlinq.Immutable", "NetFabric.Hyperlinq.Immutable\NetFabric.Hyperlinq.Immutable.csproj", "{6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -62,10 +60,6 @@ Global {6981E761-E698-437D-AF63-0E80844B7D41}.Debug|Any CPU.Build.0 = Debug|Any CPU {6981E761-E698-437D-AF63-0E80844B7D41}.Release|Any CPU.ActiveCfg = Release|Any CPU {6981E761-E698-437D-AF63-0E80844B7D41}.Release|Any CPU.Build.0 = Release|Any CPU - {6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6CB7E269-91CB-47CC-BF9F-67956D5E0F7E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs index 72c8dc7a5..82bb1a651 100644 --- a/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Aggregation/Count/Count.ReadOnlySpan.cs @@ -6,11 +6,11 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] - static int Count(this ReadOnlySpan source) + public static int Count(ReadOnlySpan source) => source.Length; [MethodImpl(MethodImplOptions.AggressiveInlining)] - static int Count(this ReadOnlySpan source, Func predicate) + public static int Count(ReadOnlySpan source, Func predicate) => source.Count(new FunctionWrapper(predicate)); static int Count(this ReadOnlySpan source, TPredicate predicate = default) diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs index 2712efc14..f0a67cdf8 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.Range.cs @@ -9,7 +9,6 @@ public static partial class ValueEnumerable static int SumRange(int start, int count) => count * (start + start + count) / 2; - [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] static unsafe TResult SumRange(int start, int count, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs index 197420b85..d3e87fe90 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorIgnore] + static TSum Sum(this ReadOnlySpan source) where TSum : struct { @@ -26,7 +26,7 @@ static TSum Sum(this ReadOnlySpan source) return Scalar.Add(sum0, sum1); } - [GeneratorIgnore] + static TSum SumVector(this ReadOnlySpan source) where TSource : struct where TSum : struct @@ -44,7 +44,7 @@ static TSum SumVector(this ReadOnlySpan source) return Scalar.Add(vectorSum.Sum(), Sum(source.Slice(source.Length - count, count))); } - [GeneratorIgnore] + static TSum Sum(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction where TSum : struct @@ -66,7 +66,7 @@ static TSum Sum(this ReadOnlySpan source, TP return Scalar.Add(sum0, sum1); } - [GeneratorIgnore] + static TSum SumAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction where TSum : struct @@ -89,7 +89,7 @@ static TSum SumAt(this ReadOnlySpan source, return Scalar.Add(sum0, sum1); } - [GeneratorIgnore] + static TSum Sum(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction where TSum : struct @@ -110,7 +110,7 @@ static TSum Sum(this ReadOnlySpan so return Scalar.Add(sum0, sum1); } - [GeneratorIgnore] + static TSum SumVector(this ReadOnlySpan source, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction @@ -131,7 +131,7 @@ static TSum SumVector(this R return Scalar.Add(vectorSum.Sum(), Sum(source.Slice(source.Length - count, count), selector)); } - [GeneratorIgnore] + static TSum SumAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction where TSum : struct @@ -153,7 +153,7 @@ static TSum SumAt(this ReadOnlySpan return Scalar.Add(sum0, sum1); } - [GeneratorIgnore] + static TSum Sum(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs index 1cc64d0c4..5da3050d2 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueEnumerable.cs @@ -4,7 +4,7 @@ namespace NetFabric.Hyperlinq { public static partial class ValueEnumerableExtensions { - [GeneratorIgnore] + internal static TSum Sum(this TEnumerable source) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -17,7 +17,7 @@ internal static TSum Sum(this TEnumerab return sum; } - [GeneratorIgnore] + internal static TSum Sum(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -34,7 +34,7 @@ internal static TSum Sum(th return sum; } - [GeneratorIgnore] + internal static TSum SumAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -51,7 +51,7 @@ internal static TSum SumAt( return sum; } - [GeneratorIgnore] + internal static TSum Sum(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -68,7 +68,7 @@ internal static TSum Sum(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -85,7 +85,7 @@ internal static TSum SumAt(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs index be0c80100..0395b5cdb 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/Sum.ValueReadOnlyCollection.cs @@ -4,7 +4,7 @@ namespace NetFabric.Hyperlinq { public static partial class ValueReadOnlyCollectionExtensions { - [GeneratorIgnore] + internal static TSum Sum(this TEnumerable source) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -15,7 +15,7 @@ internal static TSum Sum(this TEnumerab _ => ValueEnumerableExtensions.Sum(source) }; - [GeneratorIgnore] + static TSum Sum(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -27,7 +27,7 @@ static TSum Sum(this TEnume _ => ValueEnumerableExtensions.Sum(source, predicate) }; - [GeneratorIgnore] + static TSum SumAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -39,7 +39,7 @@ static TSum SumAt(this TEnu _ => ValueEnumerableExtensions.SumAt(source, predicate) }; - [GeneratorIgnore] + internal static TSum Sum(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -51,7 +51,7 @@ internal static TSum Sum ValueEnumerableExtensions.Sum(source, selector) }; - [GeneratorIgnore] + internal static TSum SumAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -63,7 +63,7 @@ internal static TSum SumAt ValueEnumerableExtensions.SumAt(source, selector) }; - [GeneratorIgnore] + static TSum Sum(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs index 7727606b0..442427cd2 100644 --- a/NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Aggregation/Sum/SumAsync.AsyncValueEnumerable.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq { public static partial class AsyncValueEnumerableExtensions { - [GeneratorIgnore] + public static async ValueTask SumAsync(this TEnumerable source, CancellationToken cancellationToken = default) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -26,7 +26,7 @@ public static async ValueTask SumAsync SumAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -51,7 +51,7 @@ internal static async ValueTask SumAsync SumAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -76,7 +76,7 @@ internal static async ValueTask SumAtAsync SumAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -100,7 +100,7 @@ internal static async ValueTask SumAsync SumAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -124,7 +124,7 @@ internal static async ValueTask SumAtAsync SumAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs index 09046a183..b0b7bffb5 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'1.AsyncValueEnumerable.cs @@ -14,7 +14,6 @@ public static AsyncValueEnumerable AsAsyncValueEnumerable< where TEnumerator : struct, IAsyncEnumerator => new(source); - [GeneratorBindings(source: "source", sourceImplements: "IAsyncValueEnumerable`2", enumerableType: "IAsyncValueEnumerable")] [StructLayout(LayoutKind.Auto)] public readonly partial struct AsyncValueEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs index c4ae76d5d..1c5b37af1 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncEnumerable.cs @@ -10,14 +10,14 @@ namespace NetFabric.Hyperlinq public static partial class AsyncEnumerableExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsyncValueEnumerable, FunctionWrapper> AsAsyncValueEnumerable(this TEnumerable source, Func getAsyncEnumerator) where TEnumerable : IAsyncEnumerable where TEnumerator : struct, IAsyncEnumerator => AsAsyncValueEnumerable>(source, new FunctionWrapper(getAsyncEnumerator)); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsyncValueEnumerable AsAsyncValueEnumerable(this TEnumerable source, TGetAsyncEnumerator getAsyncEnumerator = default) where TEnumerable : IAsyncEnumerable @@ -25,7 +25,7 @@ public static AsyncValueEnumerable => new(source, getAsyncEnumerator, getAsyncEnumerator); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsyncValueEnumerable, FunctionWrapper> AsAsyncValueEnumerable(this TEnumerable source, Func getAsyncEnumerator, Func getAsyncEnumerator2) where TEnumerable : IAsyncEnumerable @@ -33,7 +33,7 @@ public static AsyncValueEnumerable AsAsyncValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getAsyncEnumerator), new FunctionWrapper(getAsyncEnumerator2)); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsyncValueEnumerable AsAsyncValueEnumerable(this TEnumerable source, TGetAsyncEnumerator getAsyncEnumerator = default, TGetAsyncEnumerator2 getAsyncEnumerator2 = default) where TEnumerable : IAsyncEnumerable @@ -53,8 +53,10 @@ public partial struct AsyncValueEnumerable { readonly TEnumerable source; +#pragma warning disable IDE0044 // Add readonly modifier TGetAsyncEnumerator getAsyncEnumerator; TGetAsyncEnumerator2 getAsyncEnumerator2; +#pragma warning restore IDE0044 // Add readonly modifier internal AsyncValueEnumerable(TEnumerable source, TGetAsyncEnumerator getAsyncEnumerator, TGetAsyncEnumerator2 getAsyncEnumerator2) => (this.source, this.getAsyncEnumerator, this.getAsyncEnumerator2) = (source, getAsyncEnumerator, getAsyncEnumerator2); diff --git a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs index 7fc40740b..c54d790ba 100644 --- a/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/AsAsyncValueEnumerable/AsAsyncValueEnumerable'6.AsyncValueEnumerable.cs @@ -10,14 +10,14 @@ namespace NetFabric.Hyperlinq public static partial class AsyncValueEnumerableExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsyncValueEnumerable, FunctionWrapper> AsAsyncValueEnumerable(this TEnumerable source, Func getAsyncEnumerator) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator => AsAsyncValueEnumerable>(source, new FunctionWrapper(getAsyncEnumerator)); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsyncValueEnumerable AsAsyncValueEnumerable(this TEnumerable source, TGetAsyncEnumerator getAsyncEnumerator = default) where TEnumerable : IAsyncValueEnumerable @@ -25,7 +25,7 @@ public static AsyncValueEnumerable => new(source, getAsyncEnumerator, getAsyncEnumerator); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsyncValueEnumerable, FunctionWrapper> AsAsyncValueEnumerable(this TEnumerable source, Func getAsyncEnumerator, Func getAsyncEnumerator2) where TEnumerable : IAsyncValueEnumerable @@ -33,7 +33,7 @@ public static AsyncValueEnumerable AsAsyncValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getAsyncEnumerator), new FunctionWrapper(getAsyncEnumerator2)); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AsyncValueEnumerable AsAsyncValueEnumerable(this TEnumerable source, TGetAsyncEnumerator getAsyncEnumerator = default, TGetAsyncEnumerator2 getAsyncEnumerator2 = default) where TEnumerable : IAsyncValueEnumerable @@ -43,7 +43,6 @@ public static AsyncValueEnumerable => new(source, getAsyncEnumerator, getAsyncEnumerator2); - [GeneratorBindings(source: "source", sourceImplements: "IAsyncValueEnumerable`2")] [StructLayout(LayoutKind.Auto)] public partial struct AsyncValueEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs deleted file mode 100644 index 2065bd521..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.Enumerable.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class EnumerableExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this IEnumerable source) - => new(source); - - [StructLayout(LayoutKind.Auto)] - public readonly partial struct ValueEnumerable - : IValueEnumerable> - { - readonly IEnumerable source; - - internal ValueEnumerable(IEnumerable source) - => this.source = source; - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerator GetEnumerator() - => new(source.GetEnumerator()); - IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - - #region Conversion - - public ValueEnumerable AsValueEnumerable() - => this; - - public IEnumerable AsEnumerable() - => source; - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, int, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, int?, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, nint, nint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, nint?, nint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, nuint, nuint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, nuint?, nuint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, long, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, long?, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, float, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, float?, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, double, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, double?, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, decimal, decimal>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - => source.Sum, ValueEnumerator, decimal?, decimal>(); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs deleted file mode 100644 index 1cf6cf678..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs +++ /dev/null @@ -1,187 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ReadOnlyCollectionExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this IReadOnlyCollection source) - => new(source); - - [StructLayout(LayoutKind.Auto)] - public readonly partial struct ValueEnumerable - : IValueReadOnlyCollection> - , ICollection - { - readonly IReadOnlyCollection source; - - internal ValueEnumerable(IReadOnlyCollection source) - => this.source = source; - - public int Count - => source.Count; - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerator GetEnumerator() - => new(source.GetEnumerator()); - IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(Span span) - { - if (Count is 0) - return; - - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - - using var enumerator = GetEnumerator(); - checked - { - for (var index = 0; enumerator.MoveNext(); index++) - span[index] = enumerator.Current; - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - { - switch (source) - { - case ICollection collection: - collection.CopyTo(array, arrayIndex); - break; - default: - CopyTo(array.AsSpan(arrayIndex)); - break; - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource item) - => source switch - { - ICollection collection => collection.Contains(item), - _ => Count is not 0 && source.Contains(item), - }; - - [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - - #region Conversion - - public ValueEnumerable AsValueEnumerable() - => this; - - public IReadOnlyCollection AsEnumerable() - => source; - - #endregion - #region Quantifier - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource value, IEqualityComparer? comparer) - => Count is not 0 && source.Contains(value, comparer); - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source) - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this ValueEnumerable source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.CountAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, int, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, int?, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nint, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nint?, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nuint, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nuint?, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, long, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, long?, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, float, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, float?, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, double, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, double?, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, decimal, decimal>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, decimal?, decimal>(source); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs deleted file mode 100644 index cbc18a5b3..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs +++ /dev/null @@ -1,277 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ReadOnlyListExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, TSource> AsValueEnumerable(this IReadOnlyList source) - => new(source); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TList source) - where TList : IReadOnlyList - => new(source); - - [StructLayout(LayoutKind.Auto)] - public readonly partial struct ValueEnumerable - : IValueReadOnlyList> - , IList - where TList : IReadOnlyList - { - readonly TList source; - - internal ValueEnumerable(TList source) - => this.source = source; - - public TSource this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source[index]; - } - - TSource IList.this[int index] - { - get => source[index]; - [DoesNotReturn] - // ReSharper disable once ValueParameterNotUsed - set => Throw.NotSupportedException(); - } - - public int Count - => source.Count; - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerator GetEnumerator() - => new(source.GetEnumerator()); - IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(Span span) - { - if (Count is 0) - return; - - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - - using var enumerator = GetEnumerator(); - checked - { - for (var index = 0; enumerator.MoveNext(); index++) - span[index] = enumerator.Current; - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - { - switch (source) - { - case ICollection collection: - collection.CopyTo(array, arrayIndex); - break; - default: - CopyTo(array.AsSpan(arrayIndex)); - break; - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource item) - => Count is not 0 && source.Contains(item); - - public int IndexOf(TSource item) - { - return source switch - { - IList list => list.IndexOf(item), - _ => IndexOfEnumerable(this, item), - }; - - static int IndexOfEnumerable(ValueEnumerable source, TSource item) - { - using var enumerator = source.GetEnumerator(); - for (var index = 0; enumerator.MoveNext(); index++) - { - if (EqualityComparer.Default.Equals(enumerator.Current, item)) - return index; - } - return -1; - } - } - - [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - void IList.Insert(int index, TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void IList.RemoveAt(int index) - => Throw.NotSupportedException(); - - #region Partitioning - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SkipTakeEnumerable, TSource> Skip(int count) - => this.Skip, TSource>(count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SkipTakeEnumerable, TSource> Take(int count) - => this.Take, TSource>(count); - - #endregion - - #region Conversion - - public ValueEnumerable AsValueEnumerable() - => this; - - public IReadOnlyCollection AsEnumerable() - => source; - - #endregion - - #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueReadOnlyListExtensions.SelectEnumerable, ValueEnumerator, TSource, TResult, FunctionWrapper> Select(Func selector) - => ValueReadOnlyListExtensions.Select, ValueEnumerator, TSource, TResult>(this, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueReadOnlyListExtensions.SelectEnumerable, ValueEnumerator, TSource, TResult, TSelector> Select(TSelector selector = default) - where TSelector : struct, IFunction - => ValueReadOnlyListExtensions.Select, ValueEnumerator, TSource, TResult, TSelector>(this, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueReadOnlyListExtensions.SelectAtEnumerable, ValueEnumerator, TSource, TResult, FunctionWrapper> Select(Func selector) - => ValueReadOnlyListExtensions.Select, ValueEnumerator, TSource, TResult>(this, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueReadOnlyListExtensions.SelectAtEnumerable, ValueEnumerator, TSource, TResult, TSelector> SelectAt(TSelector selector = default) - where TSelector : struct, IFunction - => ValueReadOnlyListExtensions.SelectAt, ValueEnumerator, TSource, TResult, TSelector>(this, selector); - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source) - where TList : IReadOnlyList - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TList : IReadOnlyList - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, TPredicate predicate = default) - where TList : IReadOnlyList - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TList : IReadOnlyList - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this ValueEnumerable source, TPredicate predicate = default) - where TList : IReadOnlyList - where TPredicate : struct, IFunction - => source.CountAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, int, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, int?, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nint, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nint?, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nuint, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, nuint?, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, long, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, long?, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, float, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, float?, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, double, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, double?, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, decimal, decimal>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TList : IReadOnlyList - => ValueReadOnlyCollectionExtensions.Sum, ValueEnumerator, decimal?, decimal>(source); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs deleted file mode 100644 index 20977d65b..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueEnumerable.cs +++ /dev/null @@ -1,120 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this IValueEnumerable source) - where TEnumerator : struct, IEnumerator - => new(source); - - [GeneratorBindings(source: "source", sourceImplements: "IValueEnumerable`2", enumerableType: "IValueEnumerable")] - [StructLayout(LayoutKind.Auto)] - public readonly partial struct ValueEnumerable - : IValueEnumerable - where TEnumerator : struct, IEnumerator - { - readonly IValueEnumerable source; - - internal ValueEnumerable(IValueEnumerable source) - => this.source = source; - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TEnumerator GetEnumerator() - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => source.GetEnumerator(); - - #region Conversion - - public ValueEnumerable AsValueEnumerable() - => this; - - public IEnumerable AsEnumerable() - => source; - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, int, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, int?, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, nint, nint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, nint?, nint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, nuint, nuint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, nuint?, nuint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, long, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, long?, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, float, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, float?, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, double, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, double?, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, decimal, decimal>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Sum, TEnumerator, decimal?, decimal>(); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs deleted file mode 100644 index 470a699b5..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs +++ /dev/null @@ -1,195 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyCollectionExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this IValueReadOnlyCollection source) - where TEnumerator : struct, IEnumerator - => new(source); - - [GeneratorBindings(source: "source", sourceImplements: "IValueReadOnlyCollection`2,IValueEnumerable`2", enumerableType: "IValueReadOnlyCollection")] - [StructLayout(LayoutKind.Auto)] - public readonly partial struct ValueEnumerable - : IValueReadOnlyCollection - , ICollection - where TEnumerator : struct, IEnumerator - { - readonly IValueReadOnlyCollection source; - - internal ValueEnumerable(IValueReadOnlyCollection source) - => this.source = source; - - public int Count - => source.Count; - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TEnumerator GetEnumerator() - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => source.GetEnumerator(); - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(Span span) - { - if (Count is 0) - return; - - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - - using var enumerator = GetEnumerator(); - checked - { - for (var index = 0; enumerator.MoveNext(); index++) - span[index] = enumerator.Current; - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - => CopyTo(array.AsSpan(arrayIndex)); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource item) - => source switch - { - ICollection collection => collection.Contains(item), - _ => Count is not 0 && source.Contains(item), - }; - - [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - - #region Conversion - - public ValueEnumerable AsValueEnumerable() - => this; - - public IReadOnlyCollection AsEnumerable() - => source; - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TEnumerator : struct, IEnumerator - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, TPredicate predicate = default) - where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TEnumerator : struct, IEnumerator - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this ValueEnumerable source, TPredicate predicate = default) - where TEnumerator : struct, IEnumerator - where TPredicate : struct, IFunction - => source.CountAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, int, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, int?, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, nint, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, nint?, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, nuint, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, nuint?, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, long, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, long?, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, float, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, float?, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, double, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, double?, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, decimal, decimal>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerator : struct, IEnumerator - => Sum, TEnumerator, decimal?, decimal>(source); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs deleted file mode 100644 index c13c74c9e..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.Enumerable.cs +++ /dev/null @@ -1,209 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class EnumerableExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - => AsValueEnumerable>(source, new FunctionWrapper(getEnumerator)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TGetEnumerator : struct, IFunction - => new(source, getEnumerator, getEnumerator); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator, Func getEnumerator2) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - => AsValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getEnumerator), new FunctionWrapper(getEnumerator2)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default, TGetEnumerator2 getEnumerator2 = default) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => new(source, getEnumerator, getEnumerator2); - - [StructLayout(LayoutKind.Auto)] - public partial struct ValueEnumerable - : IValueEnumerable - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - { - readonly TEnumerable source; - TGetEnumerator getEnumerator; - TGetEnumerator2 getEnumerator2; - - internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetEnumerator2 getEnumerator2) - => (this.source, this.getEnumerator, this.getEnumerator2) = (source, getEnumerator, getEnumerator2); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TEnumerator2 GetEnumerator() - => getEnumerator2.Invoke(source); - TEnumerator IValueEnumerable.GetEnumerator() - => getEnumerator.Invoke(source); - IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - - #region Conversion - - public ValueEnumerable AsValueEnumerable() - => this; - - public TEnumerable AsEnumerable() - => source; - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, int, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, int?, int>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, nint, nint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, nint?, nint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, nuint, nuint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, nuint?, nuint>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, long, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, long?, long>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, float, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, float?, float>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, double, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, double?, double>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, decimal, decimal>(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Sum, TEnumerator, decimal?, decimal>(); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs deleted file mode 100644 index 64450742e..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs +++ /dev/null @@ -1,308 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ReadOnlyCollectionExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - => AsValueEnumerable>(source, new FunctionWrapper(getEnumerator)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TGetEnumerator : struct, IFunction - => new(source, getEnumerator, getEnumerator); - - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator, Func getEnumerator2) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - => AsValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getEnumerator), new FunctionWrapper(getEnumerator2)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default, TGetEnumerator2 getEnumerator2 = default) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => new(source, getEnumerator, getEnumerator2); - - [StructLayout(LayoutKind.Auto)] - public partial struct ValueEnumerable - : IValueReadOnlyCollection - , ICollection - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - { - readonly TEnumerable source; -#pragma warning disable IDE0044 // Add readonly modifier - TGetEnumerator getEnumerator; - TGetEnumerator2 getEnumerator2; -#pragma warning restore IDE0044 // Add readonly modifier - - internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetEnumerator2 getEnumerator2) - => (this.source, this.getEnumerator, this.getEnumerator2) = (source, getEnumerator, getEnumerator2); - - public readonly int Count - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TEnumerator2 GetEnumerator() - => getEnumerator2.Invoke(source); - TEnumerator IValueEnumerable.GetEnumerator() - => getEnumerator.Invoke(source); - IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - => source.GetEnumerator(); - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(Span span) - { - if (Count is 0) - return; - - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - - if (source.Count is not 0) - { - using var enumerator = getEnumerator.Invoke(source); - checked - { - for (var index = 0; enumerator.MoveNext(); index++) - span[index] = enumerator.Current; - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - => CopyTo(array.AsSpan(arrayIndex)); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource item) - => source switch - { - ICollection collection => collection.Contains(item), - _ => Count is not 0 && source.Contains(item), - }; - - [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - - #region Conversion - - public ValueEnumerable AsValueEnumerable() - => this; - - public TEnumerable AsEnumerable() - => source; - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, TPredicate predicate = default) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this ValueEnumerable source, TPredicate predicate = default) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - where TPredicate : struct, IFunction - => source.CountAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, int, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, int?, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nint, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nint?, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nuint, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nuint?, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, long, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, long?, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, float, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, float?, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, double, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, double?, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, decimal, decimal>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, decimal?, decimal>(source); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs deleted file mode 100644 index 263dc8353..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueEnumerable.cs +++ /dev/null @@ -1,212 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueEnumerableExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - => AsValueEnumerable>(source, new FunctionWrapper(getEnumerator)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TGetEnumerator : struct, IFunction - => new(source, getEnumerator, getEnumerator); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator, Func getEnumerator2) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - => AsValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getEnumerator), new FunctionWrapper(getEnumerator2)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default, TGetEnumerator2 getEnumerator2 = default) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => new(source, getEnumerator, getEnumerator2); - - [GeneratorBindings(source: "source", sourceImplements: "IValueEnumerable`2")] - [StructLayout(LayoutKind.Auto)] - public partial struct ValueEnumerable - : IValueEnumerable - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - { - internal readonly TEnumerable source; - internal TGetEnumerator getEnumerator; - internal TGetEnumerator2 getEnumerator2; - - internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetEnumerator2 getEnumerator2) - => (this.source, this.getEnumerator, this.getEnumerator2) = (source, getEnumerator, getEnumerator2); - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TEnumerator2 GetEnumerator() - => getEnumerator2.Invoke(source); - TEnumerator IValueEnumerable.GetEnumerator() - => getEnumerator.Invoke(source); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.PossibleBoxingAllocation - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.PossibleBoxingAllocation - => source.GetEnumerator(); - - #region Conversion - - public ValueEnumerable AsValueEnumerable() - => this; - - public TEnumerable AsEnumerable() - => source; - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IValueEnumerable - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.source.Sum(); - } -} diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs deleted file mode 100644 index 5d43faa04..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs +++ /dev/null @@ -1,317 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyCollectionExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - => AsValueEnumerable>(source, new FunctionWrapper(getEnumerator)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TGetEnumerator : struct, IFunction - => new(source, getEnumerator, getEnumerator); - - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator, Func getEnumerator2) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - => AsValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getEnumerator), new FunctionWrapper(getEnumerator2)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default, TGetEnumerator2 getEnumerator2 = default) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => new(source, getEnumerator, getEnumerator2); - - [GeneratorBindings(source: "source", sourceImplements: "IValueReadOnlyCollection`2,IValueEnumerable`2")] - [StructLayout(LayoutKind.Auto)] - public partial struct ValueEnumerable - : IValueReadOnlyCollection - , ICollection - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - { - readonly TEnumerable source; -#pragma warning disable IDE0044 // Add readonly modifier - TGetEnumerator getEnumerator; - TGetEnumerator2 getEnumerator2; -#pragma warning restore IDE0044 // Add readonly modifier - - internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetEnumerator2 getEnumerator2) - => (this.source, this.getEnumerator, this.getEnumerator2) = (source, getEnumerator, getEnumerator2); - - public readonly int Count - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TEnumerator2 GetEnumerator() - => getEnumerator2.Invoke(source); - TEnumerator IValueEnumerable.GetEnumerator() - => getEnumerator.Invoke(source); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => source.GetEnumerator(); - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(Span span) - { - if (Count is 0) - return; - - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - - using var enumerator = getEnumerator.Invoke(source); - checked - { - for (var index = 0; enumerator.MoveNext(); index++) - span[index] = enumerator.Current; - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - { - switch (source) - { - case ICollection collection: - collection.CopyTo(array, arrayIndex); - break; - default: - CopyTo(array.AsSpan(arrayIndex)); - break; - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource item) - => source switch - { - ICollection collection => collection.Contains(item), - _ => Count is not 0 && source.Contains(item), - }; - - [ExcludeFromCodeCoverage] - void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - void ICollection.Clear() - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - - #region Conversion - - public ValueEnumerable AsValueEnumerable() - => this; - - public TEnumerable AsEnumerable() - => source; - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, TPredicate predicate = default) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this ValueEnumerable source, TPredicate predicate = default) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - where TPredicate : struct, IFunction - => source.CountAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, int, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, int?, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, nint, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, nint?, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, nuint, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, nuint?, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, long, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, long?, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, float, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, float?, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, double, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, double?, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, decimal, decimal>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyCollection - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => Sum, TEnumerator, decimal?, decimal>(source); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs deleted file mode 100644 index d148e92e7..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs +++ /dev/null @@ -1,384 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static partial class ValueReadOnlyListExtensions - { - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - => AsValueEnumerable>(source, new FunctionWrapper(getEnumerator)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TGetEnumerator : struct, IFunction - => new(source, getEnumerator, getEnumerator); - - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable, FunctionWrapper> AsValueEnumerable(this TEnumerable source, Func getEnumerator, Func getEnumerator2) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - => AsValueEnumerable, FunctionWrapper>(source, new FunctionWrapper(getEnumerator), new FunctionWrapper(getEnumerator2)); - - [GeneratorIgnore] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ValueEnumerable AsValueEnumerable(this TEnumerable source, TGetEnumerator getEnumerator = default, TGetEnumerator2 getEnumerator2 = default) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => new(source, getEnumerator, getEnumerator2); - - [GeneratorBindings(source: "source", sourceImplements: "IValueReadOnlyList`2,IValueEnumerable`2")] - [StructLayout(LayoutKind.Auto)] - public partial struct ValueEnumerable - : IValueReadOnlyList - , IList - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - { - readonly TEnumerable source; -#pragma warning disable IDE0044 // Add readonly modifier - TGetEnumerator getEnumerator; - TGetEnumerator2 getEnumerator2; -#pragma warning restore IDE0044 // Add readonly modifier - - internal ValueEnumerable(TEnumerable source, TGetEnumerator getEnumerator, TGetEnumerator2 getEnumerator2) - => (this.source, this.getEnumerator, this.getEnumerator2) = (source, getEnumerator, getEnumerator2); - - public readonly TSource this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => source[index]; - } - readonly TSource IList.this[int index] - { - get => source[index]; - set => Throw.NotSupportedException(); - } - - public readonly int Count - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TEnumerator2 GetEnumerator() - => getEnumerator2.Invoke(source); - TEnumerator IValueEnumerable.GetEnumerator() - => getEnumerator.Invoke(source); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => source.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - // ReSharper disable once HeapView.BoxingAllocation - => source.GetEnumerator(); - - bool ICollection.IsReadOnly - => true; - - public void CopyTo(Span span) - { - if (Count is 0) - return; - - if (span.Length < Count) - Throw.ArgumentException(Resource.DestinationNotLongEnough, nameof(span)); - - using var enumerator = getEnumerator.Invoke(source); - checked - { - for (var index = 0; enumerator.MoveNext(); index++) - span[index] = enumerator.Current; - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void CopyTo(TSource[] array, int arrayIndex) - { - switch (source) - { - case ICollection collection: - collection.CopyTo(array, arrayIndex); - break; - default: - CopyTo(array.AsSpan(arrayIndex)); - break; - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Contains(TSource item) - => source switch - { - ICollection collection => collection.Contains(item), - _ => Count is not 0 && source.Contains(item), - }; - - public readonly int IndexOf(TSource item) - { - // ReSharper disable once HeapView.PossibleBoxingAllocation - if (source is IList list) - return list.IndexOf(item); - - using var enumerator = getEnumerator.Invoke(source); - for (var index = 0; enumerator.MoveNext(); index++) - { - if (EqualityComparer.Default.Equals(enumerator.Current, item)) - return index; - } - return -1; - } - - [ExcludeFromCodeCoverage] - readonly void ICollection.Add(TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - readonly void ICollection.Clear() - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - readonly bool ICollection.Remove(TSource item) - => Throw.NotSupportedException(); - - [ExcludeFromCodeCoverage] - readonly void IList.Insert(int index, TSource item) - => Throw.NotSupportedException(); - [ExcludeFromCodeCoverage] - readonly void IList.RemoveAt(int index) - => Throw.NotSupportedException(); - - #region Partitioning - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ReadOnlyListExtensions.SkipTakeEnumerable, TSource> Skip(int count) - => this.Skip, TSource>(count); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ReadOnlyListExtensions.SkipTakeEnumerable, TSource> Take(int count) - => this.Take, TSource>(count); - - #endregion - - #region Conversion - - public readonly ValueEnumerable AsValueEnumerable() - => this; - - public readonly TEnumerable AsEnumerable() - => source; - - #endregion - - #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectEnumerable, TEnumerator, TSource, TResult, FunctionWrapper> Select(Func selector) - => Select, TEnumerator, TSource, TResult>(this, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectEnumerable, TEnumerator, TSource, TResult, TSelector> Select(TSelector selector = default) - where TSelector : struct, IFunction - => Select, TEnumerator, TSource, TResult, TSelector>(this, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectAtEnumerable, TEnumerator, TSource, TResult, FunctionWrapper> Select(Func selector) - => Select, TEnumerator, TSource, TResult>(this, selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SelectAtEnumerable, TEnumerator, TSource, TResult, TSelector> SelectAt(TSelector selector = default) - where TSelector : struct, IFunction - => SelectAt, TEnumerator, TSource, TResult, TSelector>(this, selector); - - #endregion - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Count; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, TPredicate predicate = default) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ValueEnumerable source, Func predicate) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this ValueEnumerable source, TPredicate predicate = default) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - where TPredicate : struct, IFunction - => source.CountAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, int, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, int?, int>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nint, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nint Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nint?, nint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nuint, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static nuint Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, nuint?, nuint>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, long, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, long?, long>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, float, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, float?, float>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, double, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, double?, double>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, decimal, decimal>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static decimal Sum(this ValueEnumerable source) - where TEnumerable : IValueReadOnlyList - where TEnumerator : struct, IEnumerator - where TEnumerator2 : struct - where TGetEnumerator : struct, IFunction - where TGetEnumerator2 : struct, IFunction - => ValueReadOnlyCollectionExtensions.Sum, TEnumerator, decimal?, decimal>(source); - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Array.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Array.cs index b9cd3a2dc..318d761c2 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Array.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Array.cs @@ -6,7 +6,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ArraySegmentValueEnumerable AsValueEnumerable(this TSource[] source) => new(new ArraySegment(source)); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs index 1bb92e5bd..1fc7a3d43 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ArraySegment.cs @@ -12,12 +12,10 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ArraySegmentValueEnumerable AsValueEnumerable(this ArraySegment source) => new(source); - [GeneratorBindings(source: "((ReadOnlySpan)source.AsSpan())", sourceImplements: "ReadOnlySpan`1")] [StructLayout(LayoutKind.Auto)] public readonly partial struct ArraySegmentValueEnumerable : IValueReadOnlyList.DisposableEnumerator> @@ -74,7 +72,7 @@ bool ICollection.IsReadOnly [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(Span span) - => ((ReadOnlySpan)source.AsSpan()).CopyTo(span); + => source.AsReadOnlySpan().CopyTo(span); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void CopyTo(TSource[] array, int arrayIndex) @@ -141,84 +139,6 @@ public void Reset() public readonly void Dispose() { } } - #region Aggregation - - #endregion - - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentValueEnumerable AsValueEnumerable() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegment AsEnumerable() - => source; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public TSource[] ToArray() - => source.AsSpan().ToArray(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, elementSelector, comparer); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary ToDictionary(TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer = default) - where TKey : notnull - where TKeySelector : struct, IFunction - where TElementSelector : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, elementSelector, comparer); - - #endregion - - #region Element - - public Option ElementAt(int index) - => ((ReadOnlySpan)source.AsSpan()).ElementAt(index); - - public Option First() - => ((ReadOnlySpan)source.AsSpan()).First(); - - public Option Single() - => ((ReadOnlySpan)source.AsSpan()).Single(); - - #endregion - - #region Filtering - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentWhereEnumerable> Where(Func predicate) - => source.Where(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentWhereEnumerable Where(TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.Where(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentWhereAtEnumerable> Where(Func predicate) - => source.Where(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentWhereAtEnumerable WhereAt(TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.WhereAt(predicate); - - #endregion - #region Partitioning [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -233,194 +153,85 @@ public ArraySegmentValueEnumerable Take(int count) => new(new ArraySegment(source.Array!, source.Offset, Utils.Take(source.Count, count))); #endregion - - #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentSelectEnumerable> Select(Func selector) - => source.Select(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentSelectEnumerable Select(TSelector selector = default) - where TSelector : struct, IFunction - => source.Select(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentSelectAtEnumerable> Select(Func selector) - => source.Select(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentSelectAtEnumerable SelectAt(TSelector selector = default) - where TSelector : struct, IFunction - => source.SelectAt(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentSelectManyEnumerable> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => source.SelectMany(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentSelectManyEnumerable SelectMany(TSelector selector = default) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.SelectMany(selector); - - #endregion - - #region Quantifier - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => All(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(TPredicate predicate) - where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).All(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool All(Func predicate) - => AllAt(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AllAt(TPredicate predicate) - where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).AllAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any() - => ((ReadOnlySpan)source.AsSpan()).Any(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => Any(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(TPredicate predicate) - where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).Any(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Any(Func predicate) - => AnyAt(new FunctionWrapper(predicate)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AnyAt(TPredicate predicate) - where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).AnyAt(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(TSource value, IEqualityComparer? comparer) - => ((ReadOnlySpan)source.AsSpan()).Contains(value, comparer); - - #endregion - - #region Set - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ArraySegmentDistinctEnumerable Distinct(IEqualityComparer? comparer = default) - => source.Distinct(comparer); - - #endregion } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Count(this ArraySegmentValueEnumerable source) => source.Count; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ArraySegmentValueEnumerable source, Func predicate) - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ArraySegmentValueEnumerable source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this ArraySegmentValueEnumerable source, Func predicate) - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this ArraySegmentValueEnumerable source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.CountAt(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); + => source.source.AsReadOnlySpan().SumVector(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); + => source.source.AsReadOnlySpan().Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); + => source.source.AsReadOnlySpan().SumVector(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); + => source.source.AsReadOnlySpan().Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); + => source.source.AsReadOnlySpan().SumVector(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); + => source.source.AsReadOnlySpan().Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); + => source.source.AsReadOnlySpan().SumVector(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); + => source.source.AsReadOnlySpan().Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); + => source.source.AsReadOnlySpan().SumVector(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); + => source.source.AsReadOnlySpan().Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).SumVector(); + => source.source.AsReadOnlySpan().SumVector(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); + => source.source.AsReadOnlySpan().Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); + => source.source.AsReadOnlySpan().Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentValueEnumerable source) - => ((ReadOnlySpan)source.source.AsSpan()).Sum(); + => source.source.AsReadOnlySpan().Sum(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool ContainsVector(this ArraySegmentValueEnumerable source, TSource value) where TSource : struct - => ((ReadOnlySpan)source.source.AsSpan()).ContainsVector(value); + => source.source.AsReadOnlySpan().ContainsVector(value); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SpanSelectVectorContext, Vector>, FunctionWrapper> SelectVector(this ArraySegmentValueEnumerable source, Func, Vector> vectorSelector, Func selector) where TSource : struct where TResult : struct - => ((ReadOnlySpan)source.source.AsSpan()).SelectVector(vectorSelector, selector); + => source.source.AsReadOnlySpan().SelectVector(vectorSelector, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SpanSelectVectorContext SelectVector(this ArraySegmentValueEnumerable source, TSelector selector = default) where TSelector : struct, IFunction, Vector>, IFunction where TSource : struct where TResult : struct - => ((ReadOnlySpan)source.source.AsSpan()).SelectVector(selector, selector); + => source.source.AsReadOnlySpan().SelectVector(selector, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SpanSelectVectorContext SelectVector(this ArraySegmentValueEnumerable source, TVectorSelector vectorSelector = default, TSelector selector = default) @@ -428,6 +239,6 @@ public static SpanSelectVectorContext where TSource : struct where TResult : struct - => ((ReadOnlySpan)source.source.AsSpan()).SelectVector(vectorSelector, selector); + => source.source.AsReadOnlySpan().SelectVector(vectorSelector, selector); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArrayExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ImmutableArray.cs similarity index 100% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArrayExtensions.cs rename to NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ImmutableArray.cs diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.List.cs similarity index 100% rename from NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/ListExtensions.cs rename to NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.List.cs diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Memory.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Memory.cs index ce41542a3..7b25a3c4e 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Memory.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Memory.cs @@ -6,9 +6,8 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static MemoryValueEnumerable AsValueEnumerable(this Memory source) - => ((ReadOnlyMemory)source).AsValueEnumerable(); + => source.AsReadOnlyMemory().AsValueEnumerable(); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs index 554fb5d71..64cb1012c 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlyMemory.cs @@ -11,12 +11,11 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static MemoryValueEnumerable AsValueEnumerable(this ReadOnlyMemory source) => new(source); - [GeneratorBindings(source: "source.Span", sourceImplements: "ReadOnlySpan`1")] [StructLayout(LayoutKind.Auto)] public readonly partial struct MemoryValueEnumerable : IValueReadOnlyList.DisposableEnumerator> diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs index 3d8b97c67..6b3cab620 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.ReadOnlySpan.cs @@ -10,12 +10,10 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SpanValueEnumerable AsValueEnumerable(this ReadOnlySpan source) => new(source); - [GeneratorBindings(source: "source", sourceImplements: "ReadOnlySpan`1")] [StructLayout(LayoutKind.Auto)] public readonly ref partial struct SpanValueEnumerable { @@ -24,6 +22,12 @@ public readonly ref partial struct SpanValueEnumerable internal SpanValueEnumerable(ReadOnlySpan source) => this.source = source; + public ReadOnlySpan Span + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => source; + } + public int Count { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -39,48 +43,6 @@ public TSource this[int index] [MethodImpl(MethodImplOptions.AggressiveInlining)] public SpanEnumerator GetEnumerator() => new(source); - - #region Aggregation - - #endregion - - #region Conversion - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanValueEnumerable AsEnumerable() - => this; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanValueEnumerable AsValueEnumerable() - => this; - - #endregion - - #region Element - - #endregion - - #region Filtering - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanWhereEnumerable> Where(Func predicate) - => source.Where(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanWhereEnumerable Where(TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.Where(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanWhereAtEnumerable> Where(Func predicate) - => source.Where(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanWhereAtEnumerable WhereAt(TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.WhereAt(predicate); - - #endregion #region Partitioning @@ -97,53 +59,6 @@ public SpanValueEnumerable Take(int count) #endregion - #region Projection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanSelectEnumerable> Select(Func selector) - => source.Select(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanSelectEnumerable Select(TSelector selector = default) - where TSelector : struct, IFunction - => source.Select(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanSelectAtEnumerable> Select(Func selector) - => source.Select(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanSelectAtEnumerable SelectAt(TSelector selector = default) - where TSelector : struct, IFunction - => source.SelectAt(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanSelectManyEnumerable> SelectMany(Func selector) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - => source.SelectMany(selector); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanSelectManyEnumerable SelectMany(TSelector selector = default) - where TSubEnumerable : IValueEnumerable - where TSubEnumerator : struct, IEnumerator - where TSelector : struct, IFunction - => source.SelectMany(selector); - - #endregion - - #region Quantifier - - #endregion - - #region Set - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanDistinctEnumerable Distinct(IEqualityComparer? comparer = default) - => source.Distinct(comparer); - - #endregion - public bool SequenceEqual(IEnumerable other, IEqualityComparer? comparer = null) { comparer ??= EqualityComparer.Default; @@ -171,24 +86,6 @@ public bool SequenceEqual(IEnumerable other, IEqualityComparer public static int Count(this SpanValueEnumerable source) => source.Count; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SpanValueEnumerable source, Func predicate) - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SpanValueEnumerable source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Count(this SpanValueEnumerable source, Func predicate) - => source.Count(predicate); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int CountAt(this SpanValueEnumerable source, TPredicate predicate = default) - where TPredicate : struct, IFunction - => source.CountAt(predicate); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this SpanValueEnumerable source) => source.source.SumVector(); diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Span.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Span.cs index 821f8da57..3384b4eac 100644 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Span.cs +++ b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable.Span.cs @@ -6,9 +6,9 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SpanValueEnumerable AsValueEnumerable(this Span source) - => ((ReadOnlySpan)source).AsValueEnumerable(); + => source.AsReadOnlySpan().AsValueEnumerable(); } } \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/DictionaryExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/DictionaryExtensions.cs deleted file mode 100644 index 404d18218..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/DictionaryExtensions.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class DictionaryExtensions - { - // Dictionary is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - // Same for Dictionary.KeyCollection and Dictionary.ValueCollection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, Dictionary.Enumerator, Dictionary.Enumerator, KeyValuePair, GetEnumerator, GetEnumerator> AsValueEnumerable(this Dictionary source) - where TKey : notnull - => ReadOnlyCollectionExtensions.AsValueEnumerable, Dictionary.Enumerator, KeyValuePair, GetEnumerator>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable.KeyCollection, Dictionary.KeyCollection.Enumerator, Dictionary.KeyCollection.Enumerator, TKey, GetEnumerator, GetEnumerator> AsValueEnumerable(this Dictionary.KeyCollection source) - where TKey : notnull - => ReadOnlyCollectionExtensions.AsValueEnumerable.KeyCollection, Dictionary.KeyCollection.Enumerator, TKey, GetEnumerator>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable.ValueCollection, Dictionary.ValueCollection.Enumerator, Dictionary.ValueCollection.Enumerator, TValue, GetEnumerator, GetEnumerator> AsValueEnumerable(this Dictionary.ValueCollection source) - where TKey : notnull - => ReadOnlyCollectionExtensions.AsValueEnumerable.ValueCollection, Dictionary.ValueCollection.Enumerator, TValue, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, Dictionary.Enumerator> - , IFunction.KeyCollection, Dictionary.KeyCollection.Enumerator> - , IFunction.ValueCollection, Dictionary.ValueCollection.Enumerator> - where TKey : notnull - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary.Enumerator Invoke(Dictionary source) - => source.GetEnumerator(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary.KeyCollection.Enumerator Invoke(Dictionary.KeyCollection source) - => source.GetEnumerator(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Dictionary.ValueCollection.Enumerator Invoke(Dictionary.ValueCollection source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSetExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSetExtensions.cs deleted file mode 100644 index 369e75988..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/HashSetExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class HashSetExtensions - { - // HashSet is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, HashSet.Enumerator, HashSet.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this HashSet source) - => ReadOnlyCollectionExtensions.AsValueEnumerable, HashSet.Enumerator, TSource, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, HashSet.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public HashSet.Enumerator Invoke(HashSet source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedListExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedListExtensions.cs deleted file mode 100644 index f14f1d7c7..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/LinkedListExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class LinkedListExtensions - { - // LinkedList is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, LinkedList.Enumerator, LinkedList.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this LinkedList source) - => ReadOnlyCollectionExtensions.AsValueEnumerable, LinkedList.Enumerator, TSource, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, LinkedList.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public LinkedList.Enumerator Invoke(LinkedList source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueueExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueueExtensions.cs deleted file mode 100644 index 292eeb24d..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/PriorityQueueExtensions.cs +++ /dev/null @@ -1,29 +0,0 @@ -#if NET6_0_OR_GREATER - -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - - public static class PriorityQueueExtensions - { - // PriorityQueue.UnorderedItemsCollection is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable.UnorderedItemsCollection, PriorityQueue.UnorderedItemsCollection.Enumerator, PriorityQueue.UnorderedItemsCollection.Enumerator, (TElement Element, TPriority Priority), GetEnumerator, GetEnumerator> AsValueEnumerable(this PriorityQueue.UnorderedItemsCollection source) - => ReadOnlyCollectionExtensions.AsValueEnumerable.UnorderedItemsCollection, PriorityQueue.UnorderedItemsCollection.Enumerator, (TElement Element, TPriority Priority), GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction.UnorderedItemsCollection, PriorityQueue.UnorderedItemsCollection.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public PriorityQueue.UnorderedItemsCollection.Enumerator Invoke(PriorityQueue.UnorderedItemsCollection source) - => source.GetEnumerator(); - } - } -} - -#endif \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/QueueExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/QueueExtensions.cs deleted file mode 100644 index 6080caba0..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/QueueExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class QueueExtensions - { - // Queue is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, Queue.Enumerator, Queue.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this Queue source) - => ReadOnlyCollectionExtensions.AsValueEnumerable, Queue.Enumerator, TSource, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, Queue.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Queue.Enumerator Invoke(Queue source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionaryExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionaryExtensions.cs deleted file mode 100644 index ef820ddcc..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedDictionaryExtensions.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class SortedDictionaryExtensions - { - // SortedDictionary is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - // Same for SortedDictionary.KeyCollection and SortedDictionary.ValueCollection - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, SortedDictionary.Enumerator, SortedDictionary.Enumerator, KeyValuePair, GetEnumerator, GetEnumerator> AsValueEnumerable(this SortedDictionary source) - where TKey : notnull - => ReadOnlyCollectionExtensions.AsValueEnumerable, SortedDictionary.Enumerator, KeyValuePair, GetEnumerator>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable.KeyCollection, SortedDictionary.KeyCollection.Enumerator, SortedDictionary.KeyCollection.Enumerator, TKey, GetEnumerator, GetEnumerator> AsValueEnumerable(this SortedDictionary.KeyCollection source) - where TKey : notnull - => ReadOnlyCollectionExtensions.AsValueEnumerable.KeyCollection, SortedDictionary.KeyCollection.Enumerator, TKey, GetEnumerator>(source); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable.ValueCollection, SortedDictionary.ValueCollection.Enumerator, SortedDictionary.ValueCollection.Enumerator, TValue, GetEnumerator, GetEnumerator> AsValueEnumerable(this SortedDictionary.ValueCollection source) - where TKey : notnull - => ReadOnlyCollectionExtensions.AsValueEnumerable.ValueCollection, SortedDictionary.ValueCollection.Enumerator, TValue, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, SortedDictionary.Enumerator> - , IFunction.KeyCollection, SortedDictionary.KeyCollection.Enumerator> - , IFunction.ValueCollection, SortedDictionary.ValueCollection.Enumerator> - where TKey : notnull - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SortedDictionary.Enumerator Invoke(SortedDictionary source) - => source.GetEnumerator(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SortedDictionary.KeyCollection.Enumerator Invoke(SortedDictionary.KeyCollection source) - => source.GetEnumerator(); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SortedDictionary.ValueCollection.Enumerator Invoke(SortedDictionary.ValueCollection source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSetExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSetExtensions.cs deleted file mode 100644 index c5cedc01b..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/SortedSetExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class SortedSetExtensions - { - // SortedSet is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, SortedSet.Enumerator, SortedSet.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this SortedSet source) - => ReadOnlyCollectionExtensions.AsValueEnumerable, SortedSet.Enumerator, TSource, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, SortedSet.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SortedSet.Enumerator Invoke(SortedSet source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/StackExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/StackExtensions.cs deleted file mode 100644 index ad56d19c5..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/StackExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class StackExtensions - { - // Stack is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, Stack.Enumerator, Stack.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this Stack source) - => ReadOnlyCollectionExtensions.AsValueEnumerable, Stack.Enumerator, TSource, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, Stack.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Stack.Enumerator Invoke(Stack source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionaryExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionaryExtensions.cs deleted file mode 100644 index 2a51d9fa9..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionaryExtensions.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class ImmutableDictionaryExtensions - { - // ImmutableDictionary is reference-type that implements IReadOnlyCollection> and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, ImmutableDictionary.Enumerator, ImmutableDictionary.Enumerator, KeyValuePair, GetEnumerator, GetEnumerator> AsValueEnumerable(this ImmutableDictionary source) - where TKey: notnull - => ReadOnlyCollectionExtensions.AsValueEnumerable, ImmutableDictionary.Enumerator, KeyValuePair, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, ImmutableDictionary.Enumerator> - where TKey: notnull - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ImmutableDictionary.Enumerator Invoke(ImmutableDictionary source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSetExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSetExtensions.cs deleted file mode 100644 index 7f899c11c..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSetExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Immutable; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class ImmutableHashSetExtensions - { - // ImmutableHashSet is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, ImmutableHashSet.Enumerator, ImmutableHashSet.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this ImmutableHashSet source) - => ReadOnlyCollectionExtensions.AsValueEnumerable, ImmutableHashSet.Enumerator, TSource, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, ImmutableHashSet.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ImmutableHashSet.Enumerator Invoke(ImmutableHashSet source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableListExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableListExtensions.cs deleted file mode 100644 index f759387ca..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableListExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Immutable; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class ImmutableListExtensions - { - // ImmutableList is reference-type that implements IReadOnlyCollection and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, ImmutableList.Enumerator, ImmutableList.Enumerator, TSource, GetEnumerator, GetEnumerator> AsValueEnumerable(this ImmutableList source) - => ReadOnlyCollectionExtensions.AsValueEnumerable, ImmutableList.Enumerator, TSource, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, ImmutableList.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ImmutableList.Enumerator Invoke(ImmutableList source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueueExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueueExtensions.cs deleted file mode 100644 index e58289c03..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueueExtensions.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class ImmutableQueueExtensions - { - // ImmutableQueue is reference-type that implements IEnumerable and has two enumerators: - // One that is a value-type and doesn't implement interfaces. - // Another that is a reference-type and implements IEnumerator. - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static EnumerableExtensions.ValueEnumerable, ValueEnumerator, ImmutableQueue.Enumerator, TSource, GetEnumerator, GetEnumerator2> AsValueEnumerable(this ImmutableQueue source) - => source.AsValueEnumerable, ValueEnumerator, ImmutableQueue.Enumerator, TSource, GetEnumerator, GetEnumerator2>(); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, ValueEnumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerator Invoke(ImmutableQueue source) - => new(((IEnumerable)source).GetEnumerator()); - } - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator2 - : IFunction, ImmutableQueue.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ImmutableQueue.Enumerator Invoke(ImmutableQueue source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionaryExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionaryExtensions.cs deleted file mode 100644 index c336609af..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionaryExtensions.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class ImmutableSortedDictionaryExtensions - { - // ImmutableSortedDictionary is reference-type that implements IReadOnlyCollection> and has a value-type enumerator that implements IEnumerator - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlyCollectionExtensions.ValueEnumerable, ImmutableSortedDictionary.Enumerator, ImmutableSortedDictionary.Enumerator, KeyValuePair, GetEnumerator, GetEnumerator> AsValueEnumerable(this ImmutableSortedDictionary source) - where TKey: notnull - => ReadOnlyCollectionExtensions.AsValueEnumerable, ImmutableSortedDictionary.Enumerator, KeyValuePair, GetEnumerator>(source); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, ImmutableSortedDictionary.Enumerator> - where TKey: notnull - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ImmutableSortedDictionary.Enumerator Invoke(ImmutableSortedDictionary source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStackExtensions.cs b/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStackExtensions.cs deleted file mode 100644 index a153a1d07..000000000 --- a/NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStackExtensions.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace NetFabric.Hyperlinq -{ - public static class ImmutableStackExtensions - { - // ImmutableStack is reference-type that implements IEnumerable and has two enumerators: - // One that is a value-type and doesn't implement interfaces. - // Another that is a reference-type and implements IEnumerator. - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static EnumerableExtensions.ValueEnumerable, ValueEnumerator, ImmutableStack.Enumerator, TSource, GetEnumerator, GetEnumerator2> AsValueEnumerable(this ImmutableStack source) - => source.AsValueEnumerable, ValueEnumerator, ImmutableStack.Enumerator, TSource, GetEnumerator, GetEnumerator2>(); - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator - : IFunction, ValueEnumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ValueEnumerator Invoke(ImmutableStack source) - => new(((IEnumerable)source).GetEnumerator()); - } - - [StructLayout(LayoutKind.Auto)] - public readonly struct GetEnumerator2 - : IFunction, ImmutableStack.Enumerator> - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ImmutableStack.Enumerator Invoke(ImmutableStack source) - => source.GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs index af038d46f..16bfdbc5b 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ReadOnlySpan.cs @@ -21,7 +21,7 @@ public static ValueMemoryOwner ToArray(this ReadOnlySpan(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction @@ -39,7 +39,7 @@ static TSource[] BuildArray(ReadOnlySpan source, TPredicate predicate) } } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TPredicate : struct, IFunction @@ -51,7 +51,7 @@ static ValueMemoryOwner ToArray(this ReadOnlySpan< ////////////////////////////////////////////////////////////////////////////////////////////////// - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static TSource[] ToArrayAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction @@ -69,7 +69,7 @@ static TSource[] BuildArray(ReadOnlySpan source, TPredicate predicate) } } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueMemoryOwner ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TPredicate : struct, IFunction @@ -81,7 +81,7 @@ static ValueMemoryOwner ToArrayAt(this ReadOnlySpa ////////////////////////////////////////////////////////////////////////////////////////////////// - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static TResult[] ToArray(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction @@ -100,7 +100,7 @@ static TResult[] BuildArray(ReadOnlySpan source, TSelector selector) } } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static TResult[] ToArrayVector(this ReadOnlySpan source, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> @@ -122,7 +122,7 @@ static TResult[] BuildArray(ReadOnlySpan source, TVectorSelector vector } } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueMemoryOwner ToArrayVector(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> @@ -135,7 +135,7 @@ static ValueMemoryOwner ToArrayVector ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TSelector : struct, IFunction @@ -147,7 +147,7 @@ static ValueMemoryOwner ToArray(this ReadO ////////////////////////////////////////////////////////////////////////////////////////////////// - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static TResult[] ToArrayAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction @@ -166,7 +166,7 @@ static TResult[] BuildArray(ReadOnlySpan source, TSelector selector) } } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueMemoryOwner ToArrayAt(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TSelector : struct, IFunction @@ -179,7 +179,7 @@ static ValueMemoryOwner ToArrayAt(this Rea ////////////////////////////////////////////////////////////////////////////////////////////////// - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static TResult[] ToArray(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction @@ -198,7 +198,7 @@ static TResult[] BuildArray(ReadOnlySpan source, TPredicate predicate, } } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueMemoryOwner ToArray(this ReadOnlySpan source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs index 14544f098..0388d5779 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueEnumerable.cs @@ -53,7 +53,7 @@ public static ValueMemoryOwner ToArray(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -64,7 +64,7 @@ internal static TSource[] ToArray return arrayBuilder.ToArray(); } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -78,7 +78,7 @@ internal static ValueMemoryOwner ToArray(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -89,7 +89,7 @@ internal static TSource[] ToArrayAt ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -103,7 +103,7 @@ internal static ValueMemoryOwner ToArrayAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable @@ -114,7 +114,7 @@ static TResult[] ToArray( return arrayBuilder.ToArray(); } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable @@ -127,7 +127,7 @@ static ValueMemoryOwner ToArray(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable @@ -138,7 +138,7 @@ static TResult[] ToArrayAt ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable @@ -152,7 +152,7 @@ static ValueMemoryOwner ToArrayAt(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable @@ -164,7 +164,7 @@ internal static TResult[] ToArray ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs index 8378eadd4..275e1de0a 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArray.ValueReadOnlyCollection.cs @@ -63,7 +63,7 @@ public static ValueMemoryOwner ToArray(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -75,7 +75,7 @@ static TSource[] ToArray(this TEn _ => ValueEnumerableExtensions.ToArray(source, predicate) }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -85,7 +85,7 @@ static ValueMemoryOwner ToArray(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -97,7 +97,7 @@ static TSource[] ToArrayAt(this T _ => ValueEnumerableExtensions.ToArrayAt(source, predicate) }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueMemoryOwner ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -107,7 +107,7 @@ static ValueMemoryOwner ToArrayAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -129,7 +129,7 @@ static TResult[] BuildArray(TEnumerable source, TSelector selector) } } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -144,7 +144,7 @@ internal static ValueMemoryOwner ToArray(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -166,7 +166,7 @@ static TResult[] BuildArray(TEnumerable source, TSelector selector) } } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static ValueMemoryOwner ToArrayAt(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -180,7 +180,7 @@ internal static ValueMemoryOwner ToArrayAt(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -193,7 +193,7 @@ static TResult[] ToArray ValueEnumerableExtensions.ToArray(source, predicate, selector) }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueMemoryOwner ToArray(this TEnumerable source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs index d4e826a31..d39e37c63 100644 --- a/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToArray/ToArrayAsync.AsyncValueEnumerable.cs @@ -23,7 +23,7 @@ public static async ValueTask> ToArrayAsync ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable @@ -31,7 +31,7 @@ static async ValueTask ToArrayAsync => (await source.ToArrayBuilderAsync(ArrayPool.Shared, false, cancellationToken, predicate).ConfigureAwait(false)).ToArray(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable @@ -41,7 +41,7 @@ static async ValueTask> ToArrayAsync ToArrayAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable @@ -49,7 +49,7 @@ static async ValueTask ToArrayAtAsync => (await source.ToArrayBuilderAtAsync(ArrayPool.Shared, false, cancellationToken, predicate).ConfigureAwait(false)).ToArray(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToArrayAtAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable @@ -59,7 +59,7 @@ static async ValueTask> ToArrayAtAsync ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -67,7 +67,7 @@ static async ValueTask ToArrayAsync => (await source.ToArrayBuilderAsync(ArrayPool.Shared, false, cancellationToken, selector).ConfigureAwait(false)).ToArray(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -77,7 +77,7 @@ static async ValueTask> ToArrayAsync ToArrayAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -85,7 +85,7 @@ static async ValueTask ToArrayAtAsync => (await source.ToArrayBuilderAtAsync(ArrayPool.Shared, false, cancellationToken, selector).ConfigureAwait(false)).ToArray(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToArrayAtAsync(this TEnumerable source, ArrayPool pool, CancellationToken cancellationToken, bool clearOnDispose, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -95,7 +95,7 @@ static async ValueTask> ToArrayAtAsync ToArrayAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -104,7 +104,7 @@ static async ValueTask ToArrayAsync => (await source.ToArrayBuilderAsync(ArrayPool.Shared, false, cancellationToken, predicate, selector).ConfigureAwait(false)).ToArray(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToArrayAsync(this TEnumerable source, ArrayPool pool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs index 5631d82a0..a01acfc42 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ReadOnlySpan.cs @@ -24,7 +24,7 @@ static Dictionary ToDictionary(this return dictionary; } - [GeneratorIgnore] + static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TKey : notnull where TKeySelector : struct, IFunction @@ -40,7 +40,7 @@ static Dictionary ToDictionary ToDictionaryAt(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TKey : notnull where TKeySelector : struct, IFunction @@ -57,7 +57,7 @@ static Dictionary ToDictionaryAt ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TKey : notnull where TKeySelector : struct, IFunction @@ -98,7 +98,7 @@ static Dictionary ToDictionary ToDictionary( this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, @@ -118,7 +118,7 @@ static Dictionary return dictionary; } - [GeneratorIgnore] + static Dictionary ToDictionaryAt( this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, @@ -140,7 +140,7 @@ static Dictionary return dictionary; } - [GeneratorIgnore] + static Dictionary ToDictionary(this ReadOnlySpan source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TKey : notnull where TKeySelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueEnumerable.cs index 7bdd23b00..5843bd32f 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueEnumerable.cs @@ -31,7 +31,7 @@ public static Dictionary ToDictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -51,7 +51,7 @@ internal static Dictionary ToDictionary ToDictionaryAt(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -73,7 +73,7 @@ internal static Dictionary ToDictionaryAt ToDictionary(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -124,7 +124,7 @@ public static Dictionary ToDictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -144,7 +144,7 @@ internal static Dictionary ToDictionary ToDictionaryAt(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -167,7 +167,7 @@ internal static Dictionary ToDictionaryAt ToDictionary(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueReadOnlyCollection.cs index 6d3eb4e85..d9313cc32 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionary.ValueReadOnlyCollection.cs @@ -24,7 +24,7 @@ public static Dictionary ToDictionary() : ValueEnumerableExtensions.ToDictionary(source, keySelector, comparer); - [GeneratorIgnore] + static Dictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -37,7 +37,7 @@ static Dictionary ToDictionary(source, keySelector, comparer, predicate); - [GeneratorIgnore] + static Dictionary ToDictionaryAt(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -49,7 +49,7 @@ static Dictionary ToDictionaryAt() : ValueEnumerableExtensions.ToDictionaryAt(source, keySelector, comparer, predicate); - [GeneratorIgnore] + static Dictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -84,7 +84,7 @@ public static Dictionary ToDictionary(source, keySelector, elementSelector, comparer); - [GeneratorIgnore] + static Dictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -98,7 +98,7 @@ static Dictionary ToDictionary(source, keySelector, elementSelector, comparer, predicate); - [GeneratorIgnore] + static Dictionary ToDictionaryAt(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator @@ -111,7 +111,7 @@ static Dictionary ToDictionaryAt() : ValueEnumerableExtensions.ToDictionaryAt(source, keySelector, elementSelector, comparer, predicate); - [GeneratorIgnore] + static Dictionary ToDictionary(this TEnumerable source, TKeySelector keySelector, TElementSelector elementSelector, IEqualityComparer? comparer, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs index 8dd683283..e1ab61207 100644 --- a/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToDictionary/ToDictionaryAsync.AsyncValueEnumerable.cs @@ -58,7 +58,7 @@ await keySelector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), } - [GeneratorIgnore] + static async ValueTask> ToDictionaryAsync( this TEnumerable source, TKeySelector keySelector, @@ -93,7 +93,7 @@ await keySelector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), } - [GeneratorIgnore] + static async ValueTask> ToDictionaryAtAsync( this TEnumerable source, TKeySelector keySelector, @@ -131,7 +131,7 @@ await keySelector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), } } - [GeneratorIgnore] + static async ValueTask> ToDictionaryAsync( this TEnumerable source, TKeySelector keySelector, @@ -223,7 +223,7 @@ await keySelector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), } - [GeneratorIgnore] + static async ValueTask> ToDictionaryAsync( this TEnumerable source, TKeySelector keySelector, @@ -260,7 +260,7 @@ await keySelector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), } - [GeneratorIgnore] + static async ValueTask> ToDictionaryAtAsync( this TEnumerable source, TKeySelector keySelector, @@ -300,7 +300,7 @@ await keySelector.InvokeAsync(item, cancellationToken).ConfigureAwait(false), } - [GeneratorIgnore] + static async ValueTask> ToDictionaryAsync( this TEnumerable source, TKeySelector keySelector, diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs index ab86e865f..bb4f7dfb4 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ReadOnlySpan.cs @@ -13,25 +13,25 @@ public static partial class ArrayExtensions static List ToList(this ReadOnlySpan source) => source.ToArray().AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction => source.ToArray(predicate).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction => source.ToArrayAt(predicate).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction => source.ToArray(selector).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListVector(this ReadOnlySpan source, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> @@ -40,13 +40,13 @@ static List ToListVector( where TResult : struct => source.ToArrayVector(vectorSelector, selector).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction => source.ToArrayAt(selector).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueEnumerable.cs index 9a42620e6..2b03337c3 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueEnumerable.cs @@ -14,7 +14,7 @@ public static List ToList(this TEnum => source.ToArray().AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -23,7 +23,7 @@ static List ToList(this => source.ToArray(predicate).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -32,7 +32,7 @@ static List ToListAt(thi => source.ToArrayAt(predicate).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable @@ -41,7 +41,7 @@ static List ToList source.ToArray(selector).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable @@ -49,7 +49,7 @@ static List ToListAt => source.ToArrayAt(selector).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs index 73e8947a8..ae60dc6d8 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToList.ValueReadOnlyCollection.cs @@ -17,7 +17,7 @@ public static List ToList(this TEnum _ => ToArray(source).AsList(), }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -25,7 +25,7 @@ static List ToList(this where TPredicate : struct, IFunction => ToArray(source, predicate).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToListAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -33,7 +33,7 @@ static List ToListAt(thi where TPredicate : struct, IFunction => ToArrayAt(source, predicate).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static List ToList(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -41,7 +41,7 @@ internal static List ToList => ToArray(source, selector).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static List ToListAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -49,7 +49,7 @@ internal static List ToListAt => ToArrayAt(source, selector).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static List ToList(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs index 465d62854..3d4a0f681 100644 --- a/NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Conversion/ToList/ToListAsync.AsyncValueEnumerable.cs @@ -16,7 +16,7 @@ public static async ValueTask> ToListAsync (await source.ToArrayAsync(cancellationToken).ConfigureAwait(false)).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToListAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable @@ -25,7 +25,7 @@ static async ValueTask> ToListAsync (await source.ToArrayAsync(cancellationToken, predicate).ConfigureAwait(false)).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToListAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable @@ -34,7 +34,7 @@ static async ValueTask> ToListAtAsync (await source.ToArrayAtAsync(cancellationToken, predicate).ConfigureAwait(false)).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToListAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -43,7 +43,7 @@ static async ValueTask> ToListAsync (await source.ToArrayAsync(cancellationToken, selector).ConfigureAwait(false)).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToListAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -52,7 +52,7 @@ static async ValueTask> ToListAtAsync (await source.ToArrayAtAsync(cancellationToken, selector).ConfigureAwait(false)).AsList(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> ToListAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs index 9a77a2622..371ffb7d7 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlyList.cs @@ -8,7 +8,7 @@ namespace NetFabric.Hyperlinq public static partial class ReadOnlyListExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option ElementAt(this TList source, int index) where TList : struct, IReadOnlyList @@ -17,7 +17,7 @@ static Option ElementAt(this TList source, int index) : Option.Some(source[index]); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Option ElementAt(this TList source, int index, TSelector selector) where TList : struct, IReadOnlyList @@ -27,7 +27,7 @@ internal static Option ElementAt(th : Option.Some(selector.Invoke(source[index])); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Option ElementAtAt(this TList source, int index, TSelector selector) where TList : struct, IReadOnlyList diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs index 60e1dad20..a452d86e8 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ReadOnlySpan.cs @@ -13,7 +13,7 @@ static Option ElementAt(this ReadOnlySpan source, int : Option.Some(source[index]); - [GeneratorIgnore] + static Option ElementAt(this ReadOnlySpan source, int index, TPredicate predicate) where TPredicate : struct, IFunction { @@ -29,7 +29,7 @@ static Option ElementAt(this ReadOnlySpan } - [GeneratorIgnore] + static Option ElementAtAt(this ReadOnlySpan source, int index, TPredicate predicate) where TPredicate : struct, IFunction { @@ -46,7 +46,7 @@ static Option ElementAtAt(this ReadOnlySpan ElementAt(this ReadOnlySpan source, int index, TSelector selector) where TSelector : struct, IFunction => index < 0 || index >= source.Length @@ -54,7 +54,7 @@ static Option ElementAt(this ReadOnlySpan< : Option.Some(selector.Invoke(source[index])); - [GeneratorIgnore] + static Option ElementAtAt(this ReadOnlySpan source, int index, TSelector selector) where TSelector : struct, IFunction => index < 0 || index >= source.Length @@ -62,7 +62,7 @@ static Option ElementAtAt(this ReadOnlySpa : Option.Some(selector.Invoke(source[index], index)); - [GeneratorIgnore] + static Option ElementAt(this ReadOnlySpan source, int index, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueEnumerable.cs index 914a38426..c79dfe2c5 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueEnumerable.cs @@ -23,7 +23,7 @@ public static Option ElementAt(this } - [GeneratorIgnore] + internal static Option ElementAt(this TEnumerable source, int index, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -42,7 +42,7 @@ internal static Option ElementAt ElementAtAt(this TEnumerable source, int index, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -64,7 +64,7 @@ internal static Option ElementAtAt ElementAt(this TEnumerable source, int index, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -84,7 +84,7 @@ internal static Option ElementAt ElementAtAt(this TEnumerable source, int index, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -106,7 +106,7 @@ internal static Option ElementAtAt ElementAt(this TEnumerable source, int index, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueReadOnlyCollection.cs index 68cac0e57..80eb7020b 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAt.ValueReadOnlyCollection.cs @@ -18,7 +18,7 @@ public static Option ElementAt(this : Option.None }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option ElementAt(this TEnumerable source, int index, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -30,7 +30,7 @@ static Option ElementAt( _ => ValueEnumerableExtensions.ElementAt(source, index, predicate) }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option ElementAtAt(this TEnumerable source, int index, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -42,7 +42,7 @@ static Option ElementAtAt ValueEnumerableExtensions.ElementAtAt(source, index, predicate) }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option ElementAt(this TEnumerable source, int index, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -57,7 +57,7 @@ static Option ElementAt ElementAtAt(this TEnumerable source, int index, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -71,7 +71,7 @@ static Option ElementAtAt ElementAt(this TEnumerable source, int index, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs index c9c3f5aca..c073a15ea 100644 --- a/NetFabric.Hyperlinq/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/ElementAt/ElementAtAsync.AsyncValueEnumerable.cs @@ -35,7 +35,7 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } - [GeneratorIgnore] + static ValueTask> ElementAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -65,7 +65,7 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } - [GeneratorIgnore] + static ValueTask> ElementAtAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -98,7 +98,7 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } - [GeneratorIgnore] + static ValueTask> ElementAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -128,7 +128,7 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } - [GeneratorIgnore] + static ValueTask> ElementAtAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -161,7 +161,7 @@ static async ValueTask> ExecuteAsync(TEnumerable source, int ind } - [GeneratorIgnore] + static ValueTask> ElementAtAsync(this TEnumerable source, int index, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs b/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs index 7b9af035e..d2aa13217 100644 --- a/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Element/First/First.ReadOnlyList.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq public static partial class ReadOnlyListExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option First(this TList source) where TList : struct, IReadOnlyList @@ -17,7 +17,7 @@ static Option First(this TList source) _ => Option.Some(source[0]) }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Option First(this TList source, TSelector selector) where TList : struct, IReadOnlyList @@ -29,7 +29,7 @@ internal static Option First(this T }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Option FirstAt(this TList source, TSelector selector) where TList : struct, IReadOnlyList diff --git a/NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs index 2e34346c1..830e8f082 100644 --- a/NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Element/First/First.ReadOnlySpan.cs @@ -14,7 +14,7 @@ static Option First(this ReadOnlySpan source) _ => Option.Some(source[0]) }; - [GeneratorIgnore] + static Option First(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction { @@ -28,7 +28,7 @@ static Option First(this ReadOnlySpan sou } - [GeneratorIgnore] + static Option FirstAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction { @@ -42,7 +42,7 @@ static Option FirstAt(this ReadOnlySpan s } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option First(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction @@ -53,7 +53,7 @@ static Option First(this ReadOnlySpan FirstAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction @@ -64,7 +64,7 @@ static Option FirstAt(this ReadOnlySpan First(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Element/First/First.ValueEnumerable.cs b/NetFabric.Hyperlinq/Element/First/First.ValueEnumerable.cs index 50251b11b..95379dea5 100644 --- a/NetFabric.Hyperlinq/Element/First/First.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/First/First.ValueEnumerable.cs @@ -18,7 +18,7 @@ public static Option First(this TEnu } - [GeneratorIgnore] + internal static Option First(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -36,7 +36,7 @@ internal static Option First FirstAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -56,7 +56,7 @@ internal static Option FirstAt First(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -71,7 +71,7 @@ internal static Option First FirstAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -86,7 +86,7 @@ internal static Option FirstAt First(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Element/First/First.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Element/First/First.ValueReadOnlyCollection.cs index 2f01ff17e..34841d83d 100644 --- a/NetFabric.Hyperlinq/Element/First/First.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Element/First/First.ValueReadOnlyCollection.cs @@ -25,7 +25,7 @@ static Option GetFirst(TEnumerable source) } } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option First(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -37,7 +37,7 @@ static Option First(this _ => ValueEnumerableExtensions.First(source, predicate) }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option FirstAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -49,7 +49,7 @@ static Option FirstAt(th _ => ValueEnumerableExtensions.FirstAt(source, predicate) }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option First(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -71,7 +71,7 @@ static Option GetFirst(TEnumerable source, TSelector selector) } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option FirstAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -93,7 +93,7 @@ static Option GetFirst(TEnumerable source, TSelector selector) } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option First(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Element/First/FirstAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Element/First/FirstAsync.AsyncValueEnumerable.cs index 4ac0040c0..2216e721e 100644 --- a/NetFabric.Hyperlinq/Element/First/FirstAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/First/FirstAsync.AsyncValueEnumerable.cs @@ -28,7 +28,7 @@ public static async ValueTask> FirstAsync> FirstAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -52,7 +52,7 @@ static async ValueTask> FirstAsync> FirstAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -79,7 +79,7 @@ static async ValueTask> FirstAtAsync> FirstAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -102,7 +102,7 @@ static async ValueTask> FirstAsync> FirstAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable @@ -125,7 +125,7 @@ static async ValueTask> FirstAtAsync> FirstAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs b/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs index b121eaf53..45d81b242 100644 --- a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlyList.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class ReadOnlyListExtensions { - [GeneratorIgnore] + static Option Single(this TList source) where TList : struct, IReadOnlyList => source switch @@ -15,7 +15,7 @@ static Option Single(this TList source) _ => Option.None, }; - [GeneratorIgnore] + internal static Option Single(this TList source, TSelector selector) where TList : struct, IReadOnlyList where TSelector : struct, IFunction @@ -26,7 +26,7 @@ internal static Option Single(this }; - [GeneratorIgnore] + internal static Option SingleAt(this TList source, TSelector selector) where TList : struct, IReadOnlyList where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs index 56f05ceee..4042a258f 100644 --- a/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Element/Single/Single.ReadOnlySpan.cs @@ -12,7 +12,6 @@ static Option Single(this ReadOnlySpan source) _ => Option.None, }; - [GeneratorIgnore] static Option Single(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction { @@ -35,7 +34,6 @@ static Option Single(this ReadOnlySpan so } - [GeneratorIgnore] static Option SingleAt(this ReadOnlySpan source, TPredicate predicate) where TPredicate : struct, IFunction { @@ -58,7 +56,6 @@ static Option SingleAt(this ReadOnlySpan } - [GeneratorIgnore] static Option Single(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction => source switch @@ -68,7 +65,6 @@ static Option Single(this ReadOnlySpan SingleAt(this ReadOnlySpan source, TSelector selector) where TSelector : struct, IFunction => source switch @@ -78,7 +74,7 @@ static Option SingleAt(this ReadOnlySpan Single(this ReadOnlySpan source, TPredicate predicate, TSelector selector) where TPredicate : struct, IFunction where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ValueEnumerable.cs b/NetFabric.Hyperlinq/Element/Single/Single.ValueEnumerable.cs index 9ab5eeb54..ae7ac435c 100644 --- a/NetFabric.Hyperlinq/Element/Single/Single.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/Single/Single.ValueEnumerable.cs @@ -13,7 +13,7 @@ public static Option Single(this TEn => source.GetSingle(); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Option Single(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -22,7 +22,7 @@ internal static Option Single source.GetSingle(predicate); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static Option SingleAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable @@ -31,7 +31,7 @@ internal static Option SingleAt source.GetSingleAt(predicate); - [GeneratorIgnore] + static Option Single(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -41,7 +41,7 @@ static Option Single(selector); - [GeneratorIgnore] + static Option SingleAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -63,7 +63,7 @@ public TResult Invoke(TSource item) => selector.Invoke(item, 0); } - [GeneratorIgnore] + internal static Option Single(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -75,7 +75,7 @@ internal static Option Single GetSingle(this TEnumerable source) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -93,7 +93,7 @@ static Option GetSingle(this TEnumer } - [GeneratorIgnore] + static Option GetSingle(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -120,7 +120,7 @@ static Option GetSingle( } - [GeneratorIgnore] + static Option GetSingleAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Element/Single/Single.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Element/Single/Single.ValueReadOnlyCollection.cs index e0a00e1ce..899a89bd4 100644 --- a/NetFabric.Hyperlinq/Element/Single/Single.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Element/Single/Single.ValueReadOnlyCollection.cs @@ -25,7 +25,7 @@ static Option GetSingle(TEnumerable source) } } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option Single(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -37,7 +37,7 @@ static Option Single(thi _ => ValueEnumerableExtensions.Single(source, predicate) }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option SingleAt(this TEnumerable source, TPredicate predicate) where TEnumerable : IValueReadOnlyCollection @@ -49,7 +49,7 @@ static Option SingleAt(t _ => ValueEnumerableExtensions.SingleAt(source, predicate) }; - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option Single(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -70,7 +70,7 @@ static Option GetSingle(TEnumerable source, TSelector selector) } } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option SingleAt(this TEnumerable source, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -92,7 +92,7 @@ static Option GetSingle(TEnumerable source, TSelector selector) } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static Option Single(this TEnumerable source, TPredicate predicate, TSelector selector) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs index e50bfbc0c..3392497e3 100644 --- a/NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Element/Single/SingleAsync.AsyncValueEnumerable.cs @@ -15,7 +15,7 @@ public static ValueTask> SingleAsync source.GetSingleAsync(cancellationToken); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueTask> SingleAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate = default) where TEnumerable : IAsyncValueEnumerable @@ -24,7 +24,7 @@ static ValueTask> SingleAsync source.GetSingleAsync(cancellationToken, predicate); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ValueTask> SingleAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate = default) where TEnumerable : IAsyncValueEnumerable @@ -33,7 +33,7 @@ static ValueTask> SingleAtAsync source.GetSingleAtAsync(cancellationToken, predicate); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> SingleAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector = default) where TEnumerable : IAsyncValueEnumerable @@ -45,7 +45,7 @@ static async ValueTask> SingleAsync> SingleAtAsync(this TEnumerable source, CancellationToken cancellationToken, TSelector selector = default) where TEnumerable : IAsyncValueEnumerable @@ -69,7 +69,7 @@ public ValueTask InvokeAsync(TSource item, CancellationToken cancellati => selector.InvokeAsync(item, 0, cancellationToken); } - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static async ValueTask> SingleAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate, TSelector selector = default) where TEnumerable : IAsyncValueEnumerable @@ -85,7 +85,7 @@ static async ValueTask> SingleAsync> GetSingleAsync(this TEnumerable source, CancellationToken cancellationToken) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -106,7 +106,7 @@ static async ValueTask> GetSingleAsync> GetSingleAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -141,7 +141,7 @@ static async ValueTask> GetSingleAsync> GetSingleAtAsync(this TEnumerable source, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs index a8ff05a86..6b6a86359 100644 --- a/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Equality/SequenceEqual/SequenceEqual.ReadOnlySpan.cs @@ -5,7 +5,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorIgnore] + static bool SequenceEqual(this ReadOnlySpan first, TEnumerable second, IEqualityComparer? comparer = default) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs index 0af210f36..cdae01477 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ArraySegment.cs @@ -10,7 +10,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ArraySegmentWhereEnumerable> Where(this in ArraySegment source, Func predicate) => source.Where(new FunctionWrapper(predicate)); @@ -97,7 +97,7 @@ public readonly void Dispose() { } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count() - => ((ReadOnlySpan)source.AsSpan()).Count(predicate); + => source.AsReadOnlySpan().Count(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(Func predicate) @@ -106,7 +106,7 @@ public int Count(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).Count(new PredicatePredicateCombination(this.predicate, predicate)); + => source.AsReadOnlySpan().Count(new PredicatePredicateCombination(this.predicate, predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(Func predicate) @@ -115,14 +115,14 @@ public int Count(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CountAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).CountAt(new PredicatePredicateAtCombination(this.predicate, predicate)); + => source.AsReadOnlySpan().CountAt(new PredicatePredicateAtCombination(this.predicate, predicate)); #endregion #region Quantifier [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All() - => ((ReadOnlySpan)source.AsSpan()).All(predicate); + => source.AsReadOnlySpan().All(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(Func predicate) @@ -131,7 +131,7 @@ public bool All(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).All(new PredicatePredicateCombination(this.predicate, predicate)); + => source.AsReadOnlySpan().All(new PredicatePredicateCombination(this.predicate, predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(Func predicate) @@ -140,11 +140,11 @@ public bool All(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).AllAt(new PredicatePredicateAtCombination(this.predicate, predicate)); + => source.AsReadOnlySpan().AllAt(new PredicatePredicateAtCombination(this.predicate, predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() - => ((ReadOnlySpan)source.AsSpan()).Any(predicate); + => source.AsReadOnlySpan().Any(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(Func predicate) @@ -153,7 +153,7 @@ public bool Any(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).Any(new PredicatePredicateCombination(this.predicate, predicate)); + => source.AsReadOnlySpan().Any(new PredicatePredicateCombination(this.predicate, predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(Func predicate) @@ -162,7 +162,7 @@ public bool Any(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).AnyAt(new PredicatePredicateAtCombination(this.predicate, predicate)); + => source.AsReadOnlySpan().AnyAt(new PredicatePredicateAtCombination(this.predicate, predicate)); #endregion #region Filtering @@ -202,16 +202,16 @@ public ArraySegmentWhereSelectEnumerable ElementAt(int index) - => ((ReadOnlySpan)source.AsSpan()).ElementAt(index, predicate); + => source.AsReadOnlySpan().ElementAt(index, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option First() - => ((ReadOnlySpan)source.AsSpan()).First(predicate); + => source.AsReadOnlySpan().First(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option Single() #pragma warning disable HLQ005 // Avoid Single() and SingleOrDefault() - => ((ReadOnlySpan)source.AsSpan()).Single(predicate); + => source.AsReadOnlySpan().Single(predicate); #pragma warning restore HLQ005 // Avoid Single() and SingleOrDefault() #endregion @@ -219,15 +219,15 @@ public Option Single() [MethodImpl(MethodImplOptions.AggressiveInlining)] public TSource[] ToArray() - => ((ReadOnlySpan)source.AsSpan()).ToArray(predicate); + => source.AsReadOnlySpan().ToArray(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) - => ((ReadOnlySpan)source.AsSpan()).ToArray(pool, clearOnDispose, predicate); + => source.AsReadOnlySpan().ToArray(pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() - => ((ReadOnlySpan)source.AsSpan()).ToList(predicate); + => source.AsReadOnlySpan().ToList(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) @@ -238,7 +238,7 @@ public Dictionary ToDictionary(Func keySelec public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, comparer, predicate); + => source.AsReadOnlySpan().ToDictionary(keySelector, comparer, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) @@ -250,7 +250,7 @@ public Dictionary ToDictionary where TElementSelector : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, elementSelector, comparer, predicate); + => source.AsReadOnlySpan().ToDictionary(keySelector, elementSelector, comparer, predicate); #endregion } @@ -258,72 +258,72 @@ public Dictionary ToDictionary(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentWhereEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate); + => source.source.AsReadOnlySpan().Sum(source.predicate); } } diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs index 2b945a112..ec79f3df3 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.AsyncValueEnumerable.cs @@ -12,7 +12,6 @@ namespace NetFabric.Hyperlinq public static partial class AsyncValueEnumerableExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.AsyncFunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static WhereEnumerable> Where(this TEnumerable source, Func> predicate) where TEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs index 15018ad65..194ca7a54 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlyMemory.cs @@ -10,7 +10,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemoryWhereEnumerable> Where(this ReadOnlyMemory source, Func predicate) => source.Where(new FunctionWrapper(predicate)); diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs index 83259a241..81d138cba 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ReadOnlySpan.cs @@ -9,7 +9,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanWhereEnumerable> Where(this ReadOnlySpan source, Func predicate) => source.Where(new FunctionWrapper(predicate)); diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs index 04aa70044..05c6817ac 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueEnumerable.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static WhereEnumerable> Where(this TEnumerable source, Func predicate) where TEnumerable : IValueEnumerable diff --git a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs index ee6250540..03f742dbe 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/Where/Where.ValueReadOnlyCollection.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueReadOnlyCollectionExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static WhereEnumerable> Where(this TEnumerable source, Func predicate) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs index 6e6093428..f18f23339 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ArraySegment.cs @@ -10,7 +10,6 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ArraySegmentWhereAtEnumerable> Where(this in ArraySegment source, Func predicate) => source.WhereAt(new FunctionWrapper(predicate)); @@ -103,7 +102,7 @@ public readonly void Dispose() { } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count() - => ((ReadOnlySpan)source.AsSpan()).CountAt(predicate); + => source.AsReadOnlySpan().CountAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(Func predicate) @@ -112,7 +111,7 @@ public int Count(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).CountAt(new PredicatePredicateAtCombination(predicate, this.predicate)); + => source.AsReadOnlySpan().CountAt(new PredicatePredicateAtCombination(predicate, this.predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(Func predicate) @@ -121,7 +120,7 @@ public int Count(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CountAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).CountAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); + => source.AsReadOnlySpan().CountAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); #endregion #region Quantifier @@ -129,7 +128,7 @@ public int CountAt(TPredicate2 predicate = default) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All() - => ((ReadOnlySpan)source.AsSpan()).AllAt(predicate); + => source.AsReadOnlySpan().AllAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(Func predicate) @@ -138,7 +137,7 @@ public bool All(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).AllAt(new PredicatePredicateAtCombination(predicate, this.predicate)); + => source.AsReadOnlySpan().AllAt(new PredicatePredicateAtCombination(predicate, this.predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(Func predicate) @@ -147,11 +146,11 @@ public bool All(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AllAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).AllAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); + => source.AsReadOnlySpan().AllAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() - => ((ReadOnlySpan)source.AsSpan()).AnyAt(predicate); + => source.AsReadOnlySpan().AnyAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(Func predicate) @@ -160,7 +159,7 @@ public bool Any(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).AnyAt(new PredicatePredicateAtCombination(predicate, this.predicate)); + => source.AsReadOnlySpan().AnyAt(new PredicatePredicateAtCombination(predicate, this.predicate)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(Func predicate) @@ -169,7 +168,7 @@ public bool Any(Func predicate) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyAt(TPredicate2 predicate = default) where TPredicate2 : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).AnyAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); + => source.AsReadOnlySpan().AnyAt(new PredicateAtPredicateAtCombination(this.predicate, predicate)); #endregion #region Filtering @@ -200,16 +199,16 @@ public ArraySegmentWhereAtEnumerable ElementAt(int index) - => ((ReadOnlySpan)source.AsSpan()).ElementAtAt(index, predicate); + => source.AsReadOnlySpan().ElementAtAt(index, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option First() - => ((ReadOnlySpan)source.AsSpan()).FirstAt(predicate); + => source.AsReadOnlySpan().FirstAt(predicate); #pragma warning disable HLQ005 // Avoid Single() and SingleOrDefault() [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option Single() - => ((ReadOnlySpan)source.AsSpan()).SingleAt(predicate); + => source.AsReadOnlySpan().SingleAt(predicate); #pragma warning restore HLQ005 // Avoid Single() and SingleOrDefault() #endregion @@ -217,15 +216,15 @@ public Option Single() [MethodImpl(MethodImplOptions.AggressiveInlining)] public TSource[] ToArray() - => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(predicate); + => source.AsReadOnlySpan().ToArrayAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) - => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(pool, clearOnDispose, predicate); + => source.AsReadOnlySpan().ToArrayAt(pool, clearOnDispose, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() - => ((ReadOnlySpan)source.AsSpan()).ToListAt(predicate); + => source.AsReadOnlySpan().ToListAt(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) @@ -236,7 +235,7 @@ public Dictionary ToDictionary(Func keySelec public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).ToDictionaryAt(keySelector, comparer, predicate); + => source.AsReadOnlySpan().ToDictionaryAt(keySelector, comparer, predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) @@ -248,7 +247,7 @@ public Dictionary ToDictionary where TElementSelector : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).ToDictionaryAt(keySelector, elementSelector, comparer, predicate); + => source.AsReadOnlySpan().ToDictionaryAt(keySelector, elementSelector, comparer, predicate); #endregion } @@ -256,72 +255,72 @@ public Dictionary ToDictionary(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentWhereAtEnumerable source) where TPredicate : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).SumAt(source.predicate); + => source.source.AsReadOnlySpan().SumAt(source.predicate); } } diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs index 3100a92c5..04d5196dd 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.AsyncValueEnumerable.cs @@ -12,7 +12,6 @@ namespace NetFabric.Hyperlinq public static partial class AsyncValueEnumerableExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.AsyncFunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static WhereAtEnumerable> Where(this TEnumerable source, Func> predicate) where TEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs index c33057a85..c09cac844 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlyMemory.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemoryWhereAtEnumerable> Where(this ReadOnlyMemory source, Func predicate) => source.WhereAt(new FunctionWrapper(predicate)); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs index a61545c68..fd8998198 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ReadOnlySpan.cs @@ -9,7 +9,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanWhereAtEnumerable> Where(this ReadOnlySpan source, Func predicate) => source.WhereAt(new FunctionWrapper(predicate)); diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs index 81667a8bb..85bf7e29f 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueEnumerable.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static WhereAtEnumerable> Where(this TEnumerable source, Func predicate) where TEnumerable : IValueEnumerable diff --git a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs index 4df20a09f..167c2ed52 100644 --- a/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/Where/WhereAt/WhereAt.ValueReadOnlyCollection.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueReadOnlyCollectionExtensions { - [GeneratorMapping("TPredicate", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static WhereAtEnumerable> Where(this TEnumerable source, Func predicate) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs index 2d9c935a6..9d25a9bd7 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ArraySegment.cs @@ -10,7 +10,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ArraySegmentWhereSelectEnumerable WhereSelect( this in ArraySegment source, @@ -20,7 +20,6 @@ static ArraySegmentWhereSelectEnumerable => new(source, predicate, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct ArraySegmentWhereSelectEnumerable : IValueEnumerable.Enumerator> @@ -101,7 +100,7 @@ public readonly void Dispose() { } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count() - => ((ReadOnlySpan)source.AsSpan()).Count(predicate); + => source.AsReadOnlySpan().Count(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(Func predicate) @@ -127,7 +126,7 @@ public int CountAt(TPredicate2 predicate = default) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All() - => ((ReadOnlySpan)source.AsSpan()).All(predicate); + => source.AsReadOnlySpan().All(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool All(Func predicate) @@ -149,7 +148,7 @@ public bool AllAt(TPredicate2 predicate = default) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() - => ((ReadOnlySpan)source.AsSpan()).Any(predicate); + => source.AsReadOnlySpan().Any(predicate); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any(Func predicate) @@ -220,30 +219,30 @@ public ValueEnumerableExtensions.SelectManyEnumerable ElementAt(int index) - => ((ReadOnlySpan)source.AsSpan()).ElementAt(index, predicate, selector); + => source.AsReadOnlySpan().ElementAt(index, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option First() - => ((ReadOnlySpan)source.AsSpan()).First(predicate, selector); + => source.AsReadOnlySpan().First(predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option Single() - => ((ReadOnlySpan)source.AsSpan()).Single(predicate, selector); + => source.AsReadOnlySpan().Single(predicate, selector); #endregion #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult[] ToArray() - => ((ReadOnlySpan)source.AsSpan()).ToArray(predicate, selector); + => source.AsReadOnlySpan().ToArray(predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) - => ((ReadOnlySpan)source.AsSpan()).ToArray(pool, clearOnDispose, predicate, selector); + => source.AsReadOnlySpan().ToArray(pool, clearOnDispose, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() - => ((ReadOnlySpan)source.AsSpan()).ToList(predicate, selector); + => source.AsReadOnlySpan().ToList(predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, IEqualityComparer? comparer = default) @@ -254,7 +253,7 @@ public Dictionary ToDictionary(Func keySelec public Dictionary ToDictionary(TKeySelector keySelector, IEqualityComparer? comparer = default) where TKey : notnull where TKeySelector : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, comparer, predicate, selector); + => source.AsReadOnlySpan().ToDictionary(keySelector, comparer, predicate, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dictionary ToDictionary(Func keySelector, Func elementSelector, IEqualityComparer? comparer = default) @@ -266,7 +265,7 @@ public Dictionary ToDictionary where TElementSelector : struct, IFunction - => ((ReadOnlySpan)source.AsSpan()).ToDictionary(keySelector, elementSelector, comparer, predicate, selector); + => source.AsReadOnlySpan().ToDictionary(keySelector, elementSelector, comparer, predicate, selector); #endregion } @@ -275,85 +274,85 @@ public Dictionary ToDictionary(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentWhereSelectEnumerable source) where TPredicate : struct, IFunction where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.predicate, source.selector); + => source.source.AsReadOnlySpan().Sum(source.predicate, source.selector); } } diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs index b8b6863a1..ad5236d3d 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.AsyncValueEnumerable.cs @@ -11,7 +11,7 @@ namespace NetFabric.Hyperlinq { public static partial class AsyncValueEnumerableExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static WhereSelectEnumerable WhereSelect( this TEnumerable source, @@ -23,7 +23,6 @@ static WhereSelectEnumerable => new(in source, predicate, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct WhereSelectEnumerable : IAsyncValueEnumerable.Enumerator> diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs index 683c97e93..076a2cb07 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlyMemory.cs @@ -11,7 +11,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemoryWhereSelectEnumerable WhereSelect( this ReadOnlyMemory source, @@ -21,7 +21,6 @@ static MemoryWhereSelectEnumerable Wher where TSelector : struct, IFunction => new(source, predicate, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct MemoryWhereSelectEnumerable : IValueEnumerable.Enumerator> diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs index 133accd8c..d558083b1 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ReadOnlySpan.cs @@ -9,7 +9,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanWhereSelectEnumerable WhereSelect( this ReadOnlySpan source, @@ -19,7 +19,6 @@ static SpanWhereSelectEnumerable WhereS where TSelector : struct, IFunction => new(source, predicate, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly ref struct SpanWhereSelectEnumerable where TPredicate : struct, IFunction diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs index abeda7695..00d3dfd83 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueEnumerable.cs @@ -11,7 +11,7 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static WhereSelectEnumerable WhereSelect( this TEnumerable source, @@ -23,7 +23,6 @@ static WhereSelectEnumerable => new(in source, predicate, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct WhereSelectEnumerable : IValueEnumerable.Enumerator> diff --git a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs index 3a9ee6f62..cc5f4dd70 100644 --- a/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Filtering/WhereSelect/WhereSelect/WhereSelect.ValueReadOnlyCollection.cs @@ -11,7 +11,7 @@ namespace NetFabric.Hyperlinq public static partial class ValueReadOnlyCollectionExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static WhereSelectEnumerable WhereSelect( this TEnumerable source, @@ -23,7 +23,6 @@ static WhereSelectEnumerable => new(in source, predicate, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct WhereSelectEnumerable : IValueEnumerable.Enumerator> diff --git a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs index 4f3b71058..0a570fb5d 100644 --- a/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs +++ b/NetFabric.Hyperlinq/Generation/AsyncValueEnumerable/Range.cs @@ -29,7 +29,6 @@ public static RangeEnumerable Range(int start, int count) return new RangeEnumerable(start, count, end); } - [GeneratorMapping("TSource", "int", true)] [StructLayout(LayoutKind.Auto)] public readonly partial struct RangeEnumerable : IAsyncValueEnumerable diff --git a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs index e8f8cbdff..81d2b7d70 100644 --- a/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs +++ b/NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs @@ -29,7 +29,6 @@ public static RangeEnumerable Range(int start, int count) return new RangeEnumerable(start, count); } - [GeneratorMapping("TSource", "int", true)] [StructLayout(LayoutKind.Auto)] public readonly partial struct RangeEnumerable : IValueReadOnlyList @@ -123,23 +122,20 @@ void IList.RemoveAt(int index) public struct Enumerator { readonly int end; - int current; internal Enumerator(in RangeEnumerable enumerable) { - current = enumerable.start - 1; - end = current + enumerable.Count; + Current = enumerable.start - 1; + end = Current + enumerable.Count; } - public int Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => current; + public int Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] + get; private set; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() - => ++current <= end; + => ++Current <= end; } [StructLayout(LayoutKind.Auto)] @@ -147,26 +143,23 @@ public struct DisposableEnumerator : IEnumerator { readonly int end; - int current; internal DisposableEnumerator(in RangeEnumerable enumerable) { - current = enumerable.start - 1; - end = current + enumerable.Count; + Current = enumerable.start - 1; + end = Current + enumerable.Count; } - public int Current - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => current; + public int Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] + get; private set; } object? IEnumerator.Current // ReSharper disable once HeapView.BoxingAllocation - => current; + => Current; [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() - => ++current <= end; + => ++Current <= end; [ExcludeFromCodeCoverage] [DoesNotReturn] diff --git a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj index 4873c2627..ab622bde9 100644 --- a/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj +++ b/NetFabric.Hyperlinq/NetFabric.Hyperlinq.csproj @@ -23,17 +23,19 @@ - + + + + + - - - + - + - + @@ -43,7 +45,6 @@ - @@ -87,8 +88,4 @@ - - - - diff --git a/NetFabric.Hyperlinq/Option/Option.cs b/NetFabric.Hyperlinq/Option/Option.cs index 6eb50cea1..88744c90d 100644 --- a/NetFabric.Hyperlinq/Option/Option.cs +++ b/NetFabric.Hyperlinq/Option/Option.cs @@ -222,7 +222,6 @@ public List ToList() }; - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct SelectManyEnumerable : IValueEnumerable.Enumerator> diff --git a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ReadOnlyList.cs b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ReadOnlyList.cs index 4e30d7049..132bfd81a 100644 --- a/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Partitioning/Skip/Skip.ReadOnlyList.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq public static partial class ReadOnlyListExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static SkipTakeEnumerable Skip(this TList source, int count) where TList : struct, IReadOnlyList diff --git a/NetFabric.Hyperlinq/Partitioning/Take/Take.ReadOnlyList.cs b/NetFabric.Hyperlinq/Partitioning/Take/Take.ReadOnlyList.cs index c9c2f0361..915fe8bcf 100644 --- a/NetFabric.Hyperlinq/Partitioning/Take/Take.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Partitioning/Take/Take.ReadOnlyList.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class ReadOnlyListExtensions { - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static SkipTakeEnumerable Take(this TList source, int count) where TList : struct, IReadOnlyList diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs index 9c4001f46..64b1e45f2 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ArraySegment.cs @@ -10,7 +10,6 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ArraySegmentSelectEnumerable> Select(this in ArraySegment source, Func selector) => source.Select>(new FunctionWrapper(selector)); @@ -20,7 +19,6 @@ static ArraySegmentSelectEnumerable Select => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public partial struct ArraySegmentSelectEnumerable : IValueReadOnlyList.Enumerator> @@ -92,7 +90,7 @@ void ICollection.Add(TResult item) void ICollection.Clear() => Throw.NotSupportedException(); public bool Contains(TResult item) - => ((ReadOnlySpan)source.AsSpan()).Contains(item, default, selector); + => source.AsReadOnlySpan().Contains(item, default, selector); bool ICollection.Remove(TResult item) => Throw.NotSupportedException(); @@ -194,31 +192,31 @@ public readonly ValueEnumerableExtensions.SelectManyEnumerable ElementAt(int index) - => ((ReadOnlySpan)source.AsSpan()).ElementAt(index, selector); + => source.AsReadOnlySpan().ElementAt(index, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option First() - => ((ReadOnlySpan)source.AsSpan()).First(selector); + => source.AsReadOnlySpan().First(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option Single() - => ((ReadOnlySpan)source.AsSpan()).Single(selector); + => source.AsReadOnlySpan().Single(selector); #endregion #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult[] ToArray() - => ((ReadOnlySpan)source.AsSpan()).ToArray(selector); + => source.AsReadOnlySpan().ToArray(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) - => ((ReadOnlySpan)source.AsSpan()).ToArray(pool, clearOnDispose, selector); + => source.AsReadOnlySpan().ToArray(pool, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() - => ((ReadOnlySpan)source.AsSpan()).ToList(selector); + => source.AsReadOnlySpan().ToList(selector); #endregion } @@ -253,72 +251,72 @@ public static int CountAt(this ArraySeg [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nint Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static nuint Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Sum(this ArraySegmentSelectEnumerable source) where TSelector : struct, IFunction - => ((ReadOnlySpan)source.source.AsSpan()).Sum(source.selector); + => source.source.AsReadOnlySpan().Sum(source.selector); } } diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs index e1c26f312..71f9ccff9 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.AsyncValueEnumerable.cs @@ -12,7 +12,6 @@ namespace NetFabric.Hyperlinq public static partial class AsyncValueEnumerableExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.AsyncFunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SelectEnumerable> Select(this TEnumerable source, Func> selector) where TEnumerable : IAsyncValueEnumerable @@ -26,7 +25,6 @@ public static SelectEnumerable => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct SelectEnumerable : IAsyncValueEnumerable.Enumerator> diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs index fc86272de..8194a5429 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlyMemory.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemorySelectEnumerable> Select(this ReadOnlyMemory source, Func selector) => source.Select>(new FunctionWrapper(selector)); @@ -21,7 +20,6 @@ static MemorySelectEnumerable Select => new(source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public partial struct MemorySelectEnumerable : IValueReadOnlyList.Enumerator> diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs index 210e5ed69..088e9f516 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ReadOnlySpan.cs @@ -9,7 +9,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectEnumerable> Select(this ReadOnlySpan source, Func selector) => source.Select>(new FunctionWrapper(selector)); @@ -19,7 +18,6 @@ static SpanSelectEnumerable Select => new(source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public ref struct SpanSelectEnumerable where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs index 3043a11c3..c8091ed80 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueEnumerable.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SelectEnumerable> Select(this TEnumerable source, Func selector) where TEnumerable : IValueEnumerable @@ -25,7 +24,6 @@ public static SelectEnumerable => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct SelectEnumerable : IValueEnumerable.Enumerator> diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs index c223d31fe..7f9585ff4 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyCollection.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueReadOnlyCollectionExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SelectEnumerable> Select(this TEnumerable source, Func selector) where TEnumerable : IValueReadOnlyCollection @@ -25,7 +24,6 @@ public static SelectEnumerable => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public partial struct SelectEnumerable : IValueReadOnlyCollection.Enumerator> diff --git a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs index 5300c6878..bfbe589f6 100644 --- a/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/Select/Select.ValueReadOnlyList.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueReadOnlyListExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SelectEnumerable> Select(this TEnumerable source, Func selector) where TEnumerable : struct, IValueReadOnlyList @@ -25,7 +24,6 @@ public static SelectEnumerable => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public partial struct SelectEnumerable : IValueReadOnlyList.Enumerator> diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs index a15e1c6d8..20f17188a 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ArraySegment.cs @@ -10,7 +10,7 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static ArraySegmentSelectAtEnumerable> Select(this in ArraySegment source, Func selector) => source.SelectAt>(new FunctionWrapper(selector)); @@ -20,7 +20,6 @@ static ArraySegmentSelectAtEnumerable SelectAt => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public partial struct ArraySegmentSelectAtEnumerable : IValueReadOnlyList.Enumerator> @@ -85,7 +84,7 @@ void ICollection.Add(TResult item) void ICollection.Clear() => Throw.NotSupportedException(); public bool Contains(TResult item) - => ((ReadOnlySpan)source.AsSpan()).ContainsAt(item, default, selector); + => source.AsReadOnlySpan().ContainsAt(item, default, selector); bool ICollection.Remove(TResult item) => Throw.NotSupportedException(); int IList.IndexOf(TResult item) @@ -186,30 +185,30 @@ public readonly ValueEnumerableExtensions.SelectManyEnumerable ElementAt(int index) - => ((ReadOnlySpan)source.AsSpan()).ElementAtAt(index, selector); + => source.AsReadOnlySpan().ElementAtAt(index, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option First() - => ((ReadOnlySpan)source.AsSpan()).FirstAt(selector); + => source.AsReadOnlySpan().FirstAt(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Option Single() - => ((ReadOnlySpan)source.AsSpan()).SingleAt(selector); + => source.AsReadOnlySpan().SingleAt(selector); #endregion #region Conversion [MethodImpl(MethodImplOptions.AggressiveInlining)] public TResult[] ToArray() - => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(selector); + => source.AsReadOnlySpan().ToArrayAt(selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ValueMemoryOwner ToArray(ArrayPool pool, bool clearOnDispose = default) - => ((ReadOnlySpan)source.AsSpan()).ToArrayAt(pool, clearOnDispose, selector); + => source.AsReadOnlySpan().ToArrayAt(pool, clearOnDispose, selector); [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ToList() - => ((ReadOnlySpan)source.AsSpan()).ToListAt(selector); + => source.AsReadOnlySpan().ToListAt(selector); #endregion } diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs index 658feaa60..b5230dda8 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.AsyncValueEnumerable.cs @@ -12,7 +12,6 @@ namespace NetFabric.Hyperlinq public static partial class AsyncValueEnumerableExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.AsyncFunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SelectAtEnumerable> Select(this TEnumerable source, Func> selector) where TEnumerable : IAsyncValueEnumerable @@ -26,7 +25,6 @@ public static SelectAtEnumerable => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct SelectAtEnumerable : IAsyncValueEnumerable.Enumerator> diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs index 64f5d1c20..e60d6600e 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlyMemory.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemorySelectAtEnumerable> Select(this ReadOnlyMemory source, Func selector) => source.SelectAt>(new FunctionWrapper(selector)); @@ -21,7 +20,6 @@ static MemorySelectAtEnumerable SelectAt => new(source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public partial struct MemorySelectAtEnumerable : IValueReadOnlyList.Enumerator> diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs index df4ae147e..7bd3bba3d 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ReadOnlySpan.cs @@ -9,7 +9,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectAtEnumerable> Select(this ReadOnlySpan source, Func selector) => source.SelectAt>(new FunctionWrapper(selector)); @@ -19,7 +18,6 @@ static SpanSelectAtEnumerable SelectAt => new(source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public ref struct SpanSelectAtEnumerable where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs index 7801ac752..607042a2d 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueEnumerable.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SelectAtEnumerable> Select(this TEnumerable source, Func selector) where TEnumerable : IValueEnumerable @@ -25,7 +24,6 @@ public static SelectAtEnumerable => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public readonly partial struct SelectAtEnumerable : IValueEnumerable.Enumerator> diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs index fe2d27d49..96ba52ce3 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyCollection.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueReadOnlyCollectionExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SelectAtEnumerable> Select(this TEnumerable source, Func selector) where TEnumerable : IValueReadOnlyCollection @@ -25,7 +24,6 @@ public static SelectAtEnumerable => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public partial struct SelectAtEnumerable : IValueReadOnlyCollection.Enumerator> diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs index 5e7ac4098..b8fef4581 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectAt/SelectAt.ValueReadOnlyList.cs @@ -11,7 +11,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueReadOnlyListExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SelectAtEnumerable> Select(this TEnumerable source, Func selector) where TEnumerable : struct, IValueReadOnlyList @@ -25,7 +24,6 @@ public static SelectAtEnumerable => new(in source, selector); - [GeneratorMapping("TSource", "TResult")] [StructLayout(LayoutKind.Auto)] public partial struct SelectAtEnumerable : IValueReadOnlyList.Enumerator> diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs index 5ed43848c..62fd9ed5c 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.Range.cs @@ -30,7 +30,7 @@ static RangeSelectVectorContext SelectVecto where TResult : struct => new(start, count, vectorSelector, selector); - [GeneratorIgnore] + [StructLayout(LayoutKind.Auto)] public partial struct RangeSelectVectorContext where TVectorSelector : struct, IFunction, Vector> diff --git a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs index b91d2354f..19a8381e1 100644 --- a/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/Select/SelectVector/SelectVector.ReadOnlySpan.cs @@ -10,14 +10,12 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore(true)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectVectorContext, Vector>, FunctionWrapper> SelectVector(this ReadOnlySpan source, Func, Vector> vectorSelector, Func selector) where TSource : struct where TResult : struct => source.SelectVector, Vector>, FunctionWrapper>(new FunctionWrapper, Vector>(vectorSelector), new FunctionWrapper(selector)); - [GeneratorIgnore(true)] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectVectorContext SelectVector(this ReadOnlySpan source, TSelector selector = default) where TSelector : struct, IFunction, Vector>, IFunction diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs index 0bd25b721..e39a01e78 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ArraySegment.cs @@ -9,7 +9,6 @@ namespace NetFabric.Hyperlinq { public static partial class ArrayExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static ArraySegmentSelectManyEnumerable> SelectMany(this in ArraySegment source, Func selector) where TSubEnumerable : IValueEnumerable @@ -23,7 +22,7 @@ static ArraySegmentSelectManyEnumerable => new(source, selector); - [GeneratorIgnore] + [StructLayout(LayoutKind.Auto)] public readonly partial struct ArraySegmentSelectManyEnumerable : IValueEnumerable.Enumerator> diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs index 5fa18194b..09cb860b1 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlyMemory.cs @@ -10,7 +10,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static MemorySelectManyEnumerable> SelectMany(this in ReadOnlyMemory source, Func selector) where TSubEnumerable : IValueEnumerable @@ -24,7 +23,7 @@ static MemorySelectManyEnumerable => new(source, selector); - [GeneratorIgnore] + [StructLayout(LayoutKind.Auto)] public readonly partial struct MemorySelectManyEnumerable : IValueEnumerable.Enumerator> diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs index 6f7bff87a..32ba6343b 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ReadOnlySpan.cs @@ -9,7 +9,6 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] static SpanSelectManyEnumerable> SelectMany(this ReadOnlySpan source, Func selector) where TSubEnumerable : IValueEnumerable @@ -23,7 +22,7 @@ static SpanSelectManyEnumerable => new(source, selector); - [GeneratorIgnore] + [StructLayout(LayoutKind.Auto)] public readonly ref struct SpanSelectManyEnumerable where TSubEnumerable : IValueEnumerable diff --git a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs index bc5c33140..291282600 100644 --- a/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Projection/SelectMany/SelectMany/SelectMany.ValueEnumerable.cs @@ -10,7 +10,6 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { - [GeneratorMapping("TSelector", "NetFabric.Hyperlinq.FunctionWrapper")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SelectManyEnumerable> SelectMany(this TEnumerable source, Func selector) where TEnumerable : IValueEnumerable @@ -28,7 +27,7 @@ public static SelectManyEnumerable => new(source, selector); - [GeneratorIgnore] + [StructLayout(LayoutKind.Auto)] public readonly partial struct SelectManyEnumerable : IValueEnumerable.Enumerator> diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs index 87cbe3e94..e8c6b5f25 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.Enumerable.cs @@ -4,7 +4,7 @@ namespace NetFabric.Hyperlinq { public static partial class EnumerableExtensions { - [GeneratorIgnore] + internal static bool Contains(this TEnumerable source, TSource value, IEqualityComparer? comparer = default) where TEnumerable : IEnumerable { @@ -44,7 +44,7 @@ static bool ComparerContains(TEnumerable source, TSource value, IEqualityCompare } } - [GeneratorIgnore] + internal static bool Contains(this TEnumerable source, TEnumeratorGenerator getEnumerator, TSource value, IEqualityComparer? comparer = default) where TEnumerable : IEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs index 078f638c1..82115013a 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ReadOnlySpan.cs @@ -37,7 +37,7 @@ static bool ReferenceContains(ReadOnlySpan source, TSource value, IEqua } } - [GeneratorIgnore] + static bool Contains(this ReadOnlySpan source, TResult value, IEqualityComparer? comparer, TSelector selector) where TSelector : struct, IFunction { @@ -71,7 +71,7 @@ static bool ReferenceContains(ReadOnlySpan source, TResult value, IEqua } } - [GeneratorIgnore] + static bool ContainsAt(this ReadOnlySpan source, TResult value, IEqualityComparer? comparer, TSelector selector) where TSelector : struct, IFunction { diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs index 24ee9d08b..f6132a947 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueEnumerable.cs @@ -45,7 +45,7 @@ static bool ComparerContains(TEnumerable source, TSource value, IEqualityCompare } - [GeneratorIgnore] + internal static bool Contains(this TEnumerable source, TResult value, IEqualityComparer? comparer, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -80,7 +80,7 @@ static bool ReferenceContains(TEnumerable source, TResult value, IEqualityCompar } } - [GeneratorIgnore] + internal static bool ContainsAt(this TEnumerable source, TResult value, IEqualityComparer? comparer, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs index 080b9a4f3..4c4e1e62e 100644 --- a/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs +++ b/NetFabric.Hyperlinq/Quantifier/Contains/Contains.ValueReadOnlyCollection.cs @@ -11,7 +11,7 @@ public static bool Contains(this TEnumerable where TEnumerator : struct, IEnumerator => source.Count is not 0 && ValueEnumerableExtensions.Contains(source, value, comparer); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static bool Contains(this TEnumerable source, TResult value, IEqualityComparer? comparer, TSelector selector) where TEnumerable : IValueReadOnlyCollection @@ -19,7 +19,7 @@ internal static bool Contains => source.Count is not 0 && ValueEnumerableExtensions.Contains(source, value, comparer, selector); - [GeneratorIgnore] + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static bool ContainsAt(this TEnumerable source, TResult value, IEqualityComparer? comparer, TSelector selector) where TEnumerable : IValueReadOnlyCollection diff --git a/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs index 516503ef2..11c7e6beb 100644 --- a/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.ReadOnlySpan.cs @@ -34,7 +34,7 @@ static bool ContainsVector(this ReadOnlySpan source, TSource v return false; } - [GeneratorIgnore] + static bool ContainsVector(this ReadOnlySpan source, TResult value, TVectorSelector vectorSelector, TSelector selector) where TVectorSelector : struct, IFunction, Vector> where TSelector : struct, IFunction diff --git a/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.Span.cs b/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.Span.cs index 9dbfc7401..0bfe618fe 100644 --- a/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.Span.cs +++ b/NetFabric.Hyperlinq/Quantifier/ContainsVector/ContainsVector.Span.cs @@ -9,7 +9,7 @@ public static partial class ArrayExtensions [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool ContainsVector(this Span source, TSource value) where TSource : struct - => ((ReadOnlySpan)source).ContainsVector(value); + => source.AsReadOnlySpan().ContainsVector(value); } } diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs index 9688f9b18..585f4adc3 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlyList.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class ReadOnlyListExtensions { - [GeneratorIgnore] + static LargeArrayBuilder ToArrayBuilder(in TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate: struct, IFunction @@ -22,7 +22,7 @@ static LargeArrayBuilder ToArrayBuilder(in return builder; } - [GeneratorIgnore] + static LargeArrayBuilder ToArrayBuilderAt(in TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, int offset, int count) where TList : struct, IReadOnlyList where TPredicate: struct, IFunction @@ -50,7 +50,7 @@ static LargeArrayBuilder ToArrayBuilderAt(i return builder; } - [GeneratorIgnore] + static LargeArrayBuilder ToArrayBuilder(in TList source, ArrayPool pool, bool clearOnDispose, TPredicate predicate, TSelector selector, int offset, int count) where TList : struct, IReadOnlyList where TSelector: struct, IFunction diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs index 4bf675d81..558e23fff 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ReadOnlySpan.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class ArrayExtensions { - [GeneratorIgnore] + static LargeArrayBuilder ToArrayBuilder(ReadOnlySpan source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate) where TPredicate: struct, IFunction { @@ -19,7 +19,7 @@ static LargeArrayBuilder ToArrayBuilder(ReadOnlySp return builder; } - [GeneratorIgnore] + static LargeArrayBuilder ToArrayBuilderAt(ReadOnlySpan source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate) where TPredicate: struct, IFunction { @@ -33,7 +33,7 @@ static LargeArrayBuilder ToArrayBuilderAt(ReadOnly return builder; } - [GeneratorIgnore] + static LargeArrayBuilder ToArrayBuilder(ReadOnlySpan source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TPredicate: struct, IFunction where TSelector: struct, IFunction diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs index fc060df38..e0ba9ec3d 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilder.ValueEnumerable.cs @@ -6,7 +6,7 @@ namespace NetFabric.Hyperlinq public static partial class ValueEnumerableExtensions { - [GeneratorIgnore] + static LargeArrayBuilder ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -18,7 +18,7 @@ static LargeArrayBuilder ToArrayBuilder ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -35,7 +35,7 @@ static LargeArrayBuilder ToArrayBuilder ToArrayBuilderAt(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -52,7 +52,7 @@ static LargeArrayBuilder ToArrayBuilderAt ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -65,7 +65,7 @@ static LargeArrayBuilder ToArrayBuilder ToArrayBuilderAt(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator @@ -81,7 +81,7 @@ static LargeArrayBuilder ToArrayBuilderAt ToArrayBuilder(TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, TPredicate predicate, TSelector selector) where TEnumerable : IValueEnumerable where TEnumerator : struct, IEnumerator diff --git a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs index 4faaf8995..f4e6689a5 100644 --- a/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs +++ b/NetFabric.Hyperlinq/Utils/ArrayBuilder/ToArrayBuilderAsync.AsyncValueEnumerable.cs @@ -7,7 +7,7 @@ namespace NetFabric.Hyperlinq { public static partial class AsyncValueEnumerableExtensions { - [GeneratorIgnore] + static async ValueTask> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -29,7 +29,7 @@ static async ValueTask> ToArrayBuilderAsync> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -55,7 +55,7 @@ static async ValueTask> ToArrayBuilderAsync> ToArrayBuilderAtAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -84,7 +84,7 @@ static async ValueTask> ToArrayBuilderAtAsync> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -108,7 +108,7 @@ static async ValueTask> ToArrayBuilderAsync> ToArrayBuilderAtAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator @@ -135,7 +135,7 @@ static async ValueTask> ToArrayBuilderAtAsync> ToArrayBuilderAsync(this TEnumerable source, ArrayPool arrayPool, bool clearOnDispose, CancellationToken cancellationToken, TPredicate predicate, TSelector selector) where TEnumerable : IAsyncValueEnumerable where TEnumerator : struct, IAsyncEnumerator diff --git a/NetFabric.Hyperlinq/Utils/ArrayExtensions.cs b/NetFabric.Hyperlinq/Utils/ArrayExtensions.cs new file mode 100644 index 000000000..bdaa467ae --- /dev/null +++ b/NetFabric.Hyperlinq/Utils/ArrayExtensions.cs @@ -0,0 +1,16 @@ +using System; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static class InternalArrayExtensions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlySpan AsReadOnlySpan(this T[] source) + => source; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlyMemory AsReadOnlyMemory(this T[] source) + => source; + } +} diff --git a/NetFabric.Hyperlinq/Utils/ArraySegmentExtensions.cs b/NetFabric.Hyperlinq/Utils/ArraySegmentExtensions.cs index 30acec5f6..69fed9d4a 100644 --- a/NetFabric.Hyperlinq/Utils/ArraySegmentExtensions.cs +++ b/NetFabric.Hyperlinq/Utils/ArraySegmentExtensions.cs @@ -12,7 +12,10 @@ public static bool IsEmpty(this in ArraySegment source) // NOTE: Inner array can only be null if length is zero. Should validate before calling this method. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWhole(this in ArraySegment source) - => source.Count == source.Array!.Length; + => source.Count == source.Array!.Length; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlySpan AsReadOnlySpan(this in ArraySegment source) + => source.AsSpan(); } } diff --git a/NetFabric.Hyperlinq/Utils/MemoryExtensions.cs b/NetFabric.Hyperlinq/Utils/MemoryExtensions.cs new file mode 100644 index 000000000..99cfc73b2 --- /dev/null +++ b/NetFabric.Hyperlinq/Utils/MemoryExtensions.cs @@ -0,0 +1,12 @@ +using System; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static class MemoryExtensions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlyMemory AsReadOnlyMemory(this Memory source) + => source; + } +} diff --git a/NetFabric.Hyperlinq/Utils/SpanExtensions.cs b/NetFabric.Hyperlinq/Utils/SpanExtensions.cs new file mode 100644 index 000000000..07b150b9e --- /dev/null +++ b/NetFabric.Hyperlinq/Utils/SpanExtensions.cs @@ -0,0 +1,12 @@ +using System; +using System.Runtime.CompilerServices; + +namespace NetFabric.Hyperlinq +{ + static class SpanExtensions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ReadOnlySpan AsReadOnlySpan(this Span source) + => source; + } +} diff --git a/README.md b/README.md index 6888bf44f..8ff0fce39 100644 --- a/README.md +++ b/README.md @@ -426,6 +426,7 @@ The following open-source projects are used to build and test this project: - [.NET](https://github.com/dotnet) - [BenchmarkDotNet](https://benchmarkdotnet.org/) +- [Ben.TypeDictionary](https://github.com/benaadams/Ben.TypeDictionary) - [coveralls](https://coveralls.io) - [coverlet](https://github.com/tonerdo/coverlet) - [ILRepack](https://github.com/gluck/il-repack) @@ -434,6 +435,7 @@ The following open-source projects are used to build and test this project: - [NetFabric.Hyperlinq.Analyzer](https://github.com/NetFabric/NetFabric.Hyperlinq.Analyzer) - [Nullable](https://github.com/manuelroemer/Nullable) - [Source Link](https://github.com/dotnet/sourcelink) +- [UnoptimizedAssemblyDetector](https://github.com/bruno-garcia/unoptimized-assembly-detector) - [xUnit.net](https://xunit.net/) ## License