From f8faee0135bd5fa14434967da0259de2ac69290d Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 13 Sep 2024 08:21:28 +1000 Subject: [PATCH] respect LangVersion for preview features (#219) --- src/Consume/Consume.cs | 13 ++++++++ src/ConsumeCs12/ConsumeCs12.csproj | 18 +++++++++++ src/ConsumeCs13/ConsumeCs13.csproj | 18 +++++++++++ src/ConsumeCsDefault/ConsumeCsDefault.csproj | 18 +++++++++++ src/ConsumeCsLatest/ConsumeCsLatest.csproj | 18 +++++++++++ .../ConsumeCsLatestMajor.csproj | 18 +++++++++++ src/Directory.Build.props | 2 +- src/Polyfill.sln | 30 +++++++++++++++++++ src/Polyfill/Polyfill.targets | 7 +++++ src/Polyfill/Polyfill_Memory_SpanSplit.cs | 4 +++ 10 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 src/ConsumeCs12/ConsumeCs12.csproj create mode 100644 src/ConsumeCs13/ConsumeCs13.csproj create mode 100644 src/ConsumeCsDefault/ConsumeCsDefault.csproj create mode 100644 src/ConsumeCsLatest/ConsumeCsLatest.csproj create mode 100644 src/ConsumeCsLatestMajor/ConsumeCsLatestMajor.csproj diff --git a/src/Consume/Consume.cs b/src/Consume/Consume.cs index 1623d793..a1c370a3 100644 --- a/src/Consume/Consume.cs +++ b/src/Consume/Consume.cs @@ -111,6 +111,8 @@ void UsePreviewFeature() { } +#if LangVersion13 + [OverloadResolutionPriority(1)] void Method(int x) { @@ -126,7 +128,10 @@ void Method(object x) { } +#endif + #if FeatureMemory + void CollectionBuilderAttribute() { MyCollection myCollection = [1, 2, 3, 4, 5]; @@ -140,9 +145,11 @@ class MyCollection(ReadOnlySpan initValues) public static MyCollection Create(ReadOnlySpan values) => new(values); } + #endif #if FeatureValueTuple + void Ranges() { var range = "value"[1..]; @@ -154,6 +161,7 @@ void Ranges() // "value2" // }[..1]; } + #endif #endregion @@ -326,6 +334,7 @@ void Random_Methods() } #if FeatureMemory + void ReadOnlySpan_Methods() { var readOnlySpan = "value".AsSpan(); @@ -340,18 +349,22 @@ void ReadOnlySpan_Methods() result = readOnlySpan.StartsWith("value", StringComparison.Ordinal); var split = readOnlySpan.Split('a'); split = readOnlySpan.Split("a".AsSpan()); +#if LangVersion13 split = readOnlySpan.SplitAny('a'); split = readOnlySpan.SplitAny("a".AsSpan()); +#endif } #endif #if FeatureMemory + void Regex_Methods() { var regex = new Regex("result"); regex.IsMatch("value".AsSpan()); } + #endif void SByte_Methods() diff --git a/src/ConsumeCs12/ConsumeCs12.csproj b/src/ConsumeCs12/ConsumeCs12.csproj new file mode 100644 index 00000000..ab831fc1 --- /dev/null +++ b/src/ConsumeCs12/ConsumeCs12.csproj @@ -0,0 +1,18 @@ + + + $(NoWarn);PolyfillTargetsForNuget + true + 12.0 + net461;net462;net47;net471;net472;net48;net481;net6.0-windows + $(TargetFrameworks);netstandard2.0;netstandard2.1;netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0 + + + + + + + + + + + \ No newline at end of file diff --git a/src/ConsumeCs13/ConsumeCs13.csproj b/src/ConsumeCs13/ConsumeCs13.csproj new file mode 100644 index 00000000..a4048ccf --- /dev/null +++ b/src/ConsumeCs13/ConsumeCs13.csproj @@ -0,0 +1,18 @@ + + + $(NoWarn);PolyfillTargetsForNuget + true + 13.0 + net461;net462;net47;net471;net472;net48;net481;net6.0-windows + $(TargetFrameworks);netstandard2.0;netstandard2.1;netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0 + + + + + + + + + + + \ No newline at end of file diff --git a/src/ConsumeCsDefault/ConsumeCsDefault.csproj b/src/ConsumeCsDefault/ConsumeCsDefault.csproj new file mode 100644 index 00000000..1294e54a --- /dev/null +++ b/src/ConsumeCsDefault/ConsumeCsDefault.csproj @@ -0,0 +1,18 @@ + + + $(NoWarn);PolyfillTargetsForNuget + true + default + net461;net462;net47;net471;net472;net48;net481;net6.0-windows + $(TargetFrameworks);netstandard2.0;netstandard2.1;netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0 + + + + + + + + + + + \ No newline at end of file diff --git a/src/ConsumeCsLatest/ConsumeCsLatest.csproj b/src/ConsumeCsLatest/ConsumeCsLatest.csproj new file mode 100644 index 00000000..7c4a27a7 --- /dev/null +++ b/src/ConsumeCsLatest/ConsumeCsLatest.csproj @@ -0,0 +1,18 @@ + + + $(NoWarn);PolyfillTargetsForNuget + true + latest + net461;net462;net47;net471;net472;net48;net481;net6.0-windows + $(TargetFrameworks);netstandard2.0;netstandard2.1;netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0 + + + + + + + + + + + \ No newline at end of file diff --git a/src/ConsumeCsLatestMajor/ConsumeCsLatestMajor.csproj b/src/ConsumeCsLatestMajor/ConsumeCsLatestMajor.csproj new file mode 100644 index 00000000..9808bcd5 --- /dev/null +++ b/src/ConsumeCsLatestMajor/ConsumeCsLatestMajor.csproj @@ -0,0 +1,18 @@ + + + $(NoWarn);PolyfillTargetsForNuget + true + latestMajor + net461;net462;net47;net471;net472;net48;net481;net6.0-windows + $(TargetFrameworks);netstandard2.0;netstandard2.1;netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0 + + + + + + + + + + + \ No newline at end of file diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 4d74f177..61ceb85c 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,7 +1,7 @@ - 6.6.1 + 6.6.2 1.0.0 Polyfill true diff --git a/src/Polyfill.sln b/src/Polyfill.sln index 7c3565f4..51092d54 100644 --- a/src/Polyfill.sln +++ b/src/Polyfill.sln @@ -43,6 +43,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TargetFrameworkUsage", "Tar EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsumeMemoryWithNoTask", "ConsumeMemoryWithNoTask\ConsumeMemoryWithNoTask.csproj", "{1BDDA7F0-0D45-418C-B3DB-BBA39C29FD77}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsumeCs12", "ConsumeCs12\ConsumeCs12.csproj", "{4ACF4760-B3C5-4D07-9D92-2B8225BA8881}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsumeCs13", "ConsumeCs13\ConsumeCs13.csproj", "{EE99F818-0D49-434F-B787-348CA34051EF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsumeCsLatest", "ConsumeCsLatest\ConsumeCsLatest.csproj", "{684570FB-7049-44F0-9DCC-32F73F242694}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsumeCsLatestMajor", "ConsumeCsLatestMajor\ConsumeCsLatestMajor.csproj", "{9BB64345-DE4F-4396-9320-AAA712D7E3CE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsumeCsDefault", "ConsumeCsDefault\ConsumeCsDefault.csproj", "{86AA1F8D-4081-4D31-812E-866C0951415D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -96,6 +106,26 @@ Global {1BDDA7F0-0D45-418C-B3DB-BBA39C29FD77}.Debug|Any CPU.Build.0 = Debug|Any CPU {1BDDA7F0-0D45-418C-B3DB-BBA39C29FD77}.Release|Any CPU.ActiveCfg = Release|Any CPU {1BDDA7F0-0D45-418C-B3DB-BBA39C29FD77}.Release|Any CPU.Build.0 = Release|Any CPU + {4ACF4760-B3C5-4D07-9D92-2B8225BA8881}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4ACF4760-B3C5-4D07-9D92-2B8225BA8881}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4ACF4760-B3C5-4D07-9D92-2B8225BA8881}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4ACF4760-B3C5-4D07-9D92-2B8225BA8881}.Release|Any CPU.Build.0 = Release|Any CPU + {EE99F818-0D49-434F-B787-348CA34051EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EE99F818-0D49-434F-B787-348CA34051EF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EE99F818-0D49-434F-B787-348CA34051EF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EE99F818-0D49-434F-B787-348CA34051EF}.Release|Any CPU.Build.0 = Release|Any CPU + {684570FB-7049-44F0-9DCC-32F73F242694}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {684570FB-7049-44F0-9DCC-32F73F242694}.Debug|Any CPU.Build.0 = Debug|Any CPU + {684570FB-7049-44F0-9DCC-32F73F242694}.Release|Any CPU.ActiveCfg = Release|Any CPU + {684570FB-7049-44F0-9DCC-32F73F242694}.Release|Any CPU.Build.0 = Release|Any CPU + {9BB64345-DE4F-4396-9320-AAA712D7E3CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9BB64345-DE4F-4396-9320-AAA712D7E3CE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9BB64345-DE4F-4396-9320-AAA712D7E3CE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9BB64345-DE4F-4396-9320-AAA712D7E3CE}.Release|Any CPU.Build.0 = Release|Any CPU + {86AA1F8D-4081-4D31-812E-866C0951415D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {86AA1F8D-4081-4D31-812E-866C0951415D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {86AA1F8D-4081-4D31-812E-866C0951415D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {86AA1F8D-4081-4D31-812E-866C0951415D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Polyfill/Polyfill.targets b/src/Polyfill/Polyfill.targets index b321771e..4276b5ee 100644 --- a/src/Polyfill/Polyfill.targets +++ b/src/Polyfill/Polyfill.targets @@ -4,6 +4,13 @@ $(TargetFramework.ToLower()) $(TargetFrameworks.ToLower()) + + $(DefineConstants);LangVersion13 + $(DefineConstants);LangVersion13 + $(DefineConstants);LangVersion13 + $(DefineConstants);LangVersion13 + $(DefineConstants);LangVersion13 + $(DefineConstants);AllowUnsafeBlocks diff --git a/src/Polyfill/Polyfill_Memory_SpanSplit.cs b/src/Polyfill/Polyfill_Memory_SpanSplit.cs index af9be8b9..654446ba 100644 --- a/src/Polyfill/Polyfill_Memory_SpanSplit.cs +++ b/src/Polyfill/Polyfill_Memory_SpanSplit.cs @@ -43,6 +43,8 @@ public static SpanSplitEnumerator Split(this ReadOnlySpan source, ReadO where T : IEquatable => new SpanSplitEnumerator(source, separator, treatAsSingleSeparator: true); +#if LangVersion13 + /// /// Returns a type that allows for enumeration of each element within a split span /// using any of the provided elements. @@ -63,6 +65,8 @@ public static SpanSplitEnumerator SplitAny(this ReadOnlySpan source, [U where T : IEquatable => new SpanSplitEnumerator(source, separators); +#endif + #if NET8_0 ///