From ad4d1f7b54f50f92aea8a1d91ad884c53a7a6570 Mon Sep 17 00:00:00 2001 From: Yufei Huang Date: Sun, 17 Sep 2023 22:18:27 +0800 Subject: [PATCH] feat: support csharp 12 --- .github/workflows/ci.yml | 10 ++-- .github/workflows/release.yml | 6 +-- Directory.Packages.props | 3 +- NuGet.config | 5 -- samples/csharp/src/CSharp.csproj | 4 +- samples/csharp/src/CSharp12.cs | 78 ++++++++++++++++++++++++++++++++ 6 files changed, 90 insertions(+), 16 deletions(-) create mode 100644 samples/csharp/src/CSharp12.cs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 847d8f5fbfa..18fe14053ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,9 +31,9 @@ jobs: if: matrix.os == 'windows-latest' - run: dotnet test -c Release -f net8.0 --no-build --collect:"XPlat Code Coverage" - if: matrix.os == 'ubuntu-latest' - run: dotnet test -c Release -f net7.0 --no-build --collect:"XPlat Code Coverage" + if: matrix.os == 'ubuntu-latest' - run: dotnet test -c Release -f net6.0 --no-build --collect:"XPlat Code Coverage" if: matrix.os == 'ubuntu-latest' @@ -41,10 +41,10 @@ jobs: - uses: codecov/codecov-action@v3 if: matrix.os == 'ubuntu-latest' - - run: dotnet run -c Release --no-build -f net7.0 --project src/docfx -- docs/docfx.json + - run: dotnet run -c Release --no-build -f net8.0 --project src/docfx -- docs/docfx.json - - run: dotnet run -c Release --no-build -f net7.0 --project src/docfx -- metadata samples/seed/docfx.json - - run: dotnet run -c Release --no-build -f net7.0 --project src/docfx -- build samples/seed/docfx.json --output docs/_site/seed + - run: dotnet run -c Release --no-build -f net8.0 --project src/docfx -- metadata samples/seed/docfx.json + - run: dotnet run -c Release --no-build -f net8.0 --project src/docfx -- build samples/seed/docfx.json --output docs/_site/seed - uses: actions/upload-artifact@v3 if: matrix.os == 'ubuntu-latest' @@ -64,7 +64,7 @@ jobs: - uses: ./.github/actions/build - run: dotnet build -c Release samples/extensions/build - - run: dotnet test -c Release -f net7.0 --no-build --filter Stage=Snapshot + - run: dotnet test -c Release -f net8.0 --no-build --filter Stage=Snapshot working-directory: test/docfx.Snapshot.Tests env: SNAPSHOT_TEST: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b01dd5673b3..0cb3c8eceba 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,9 +32,9 @@ jobs: - name: dotnet publish run: | - dotnet publish src/docfx -f net7.0 -c Release /p:Version=${GITHUB_REF_NAME#v} --self-contained -r win-x64 -o drop/publish/win-x64 - dotnet publish src/docfx -f net7.0 -c Release /p:Version=${GITHUB_REF_NAME#v} --self-contained -r linux-x64 -o drop/publish/linux-x64 - dotnet publish src/docfx -f net7.0 -c Release /p:Version=${GITHUB_REF_NAME#v} --self-contained -r osx-x64 -o drop/publish/osx-x64 + dotnet publish src/docfx -f net8.0 -c Release /p:Version=${GITHUB_REF_NAME#v} --self-contained -r win-x64 -o drop/publish/win-x64 + dotnet publish src/docfx -f net8.0 -c Release /p:Version=${GITHUB_REF_NAME#v} --self-contained -r linux-x64 -o drop/publish/linux-x64 + dotnet publish src/docfx -f net8.0 -c Release /p:Version=${GITHUB_REF_NAME#v} --self-contained -r osx-x64 -o drop/publish/osx-x64 mkdir -p drop/bin - run: zip -r ../../bin/docfx-win-x64-${GITHUB_REF_NAME}.zip . diff --git a/Directory.Packages.props b/Directory.Packages.props index da9df9ba66f..5ffd4b54d7c 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -41,7 +41,8 @@ - + + diff --git a/NuGet.config b/NuGet.config index 1f3f6656670..a7cb980c956 100644 --- a/NuGet.config +++ b/NuGet.config @@ -5,9 +5,4 @@ - - - - - diff --git a/samples/csharp/src/CSharp.csproj b/samples/csharp/src/CSharp.csproj index 6cd3eb3da1c..d7878789ae8 100644 --- a/samples/csharp/src/CSharp.csproj +++ b/samples/csharp/src/CSharp.csproj @@ -1,8 +1,8 @@ - net7.0 - latest + net8.0 + preview enable enable true diff --git a/samples/csharp/src/CSharp12.cs b/samples/csharp/src/CSharp12.cs new file mode 100644 index 00000000000..717847227e6 --- /dev/null +++ b/samples/csharp/src/CSharp12.cs @@ -0,0 +1,78 @@ +namespace CSharp12; + +using Markdown = string; + +public class PrimaryConstructors +{ + public readonly struct Distance(double dx, double dy) + { + public readonly double Magnitude = Math.Sqrt(dx * dx + dy * dy); + public readonly double Direction = Math.Atan2(dy, dx); + } + + public class BankAccount(string accountID, string owner) + { + public string AccountID { get; } = accountID; + public string Owner { get; } = owner; + + public override string ToString() => $"Account ID: {AccountID}, Owner: {Owner}"; + } + + public class CheckAccount(string accountID, string owner, decimal overdraftLimit = 0) : BankAccount(accountID, owner) + { + public decimal CurrentBalance { get; private set; } = 0; + + public void Deposit(decimal amount) + { + if (amount < 0) + { + throw new ArgumentOutOfRangeException(nameof(amount), "Deposit amount must be positive"); + } + CurrentBalance += amount; + } + + public void Withdrawal(decimal amount) + { + if (amount < 0) + { + throw new ArgumentOutOfRangeException(nameof(amount), "Withdrawal amount must be positive"); + } + if (CurrentBalance - amount < -overdraftLimit) + { + throw new InvalidOperationException("Insufficient funds for withdrawal"); + } + CurrentBalance -= amount; + } + + public override string ToString() => $"Account ID: {AccountID}, Owner: {Owner}, Balance: {CurrentBalance}"; + } +} + +public class CollectionExpressions +{ + public static int[] a = [1, 2, 3, 4, 5, 6, 7, 8]; + + public static Span b => ['a', 'b', 'c', 'd', 'e', 'f', 'h', 'i']; + + public static int[][] twoD = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; +} + +public class DefaultLambdaParameters +{ + public void Foo() + { + var addWithDefault = (int addTo = 2) => addTo + 1; + addWithDefault(); // 3 + addWithDefault(5); // 6 + + var counter = (params int[] xs) => xs.Length; + counter(); // 0 + counter(1, 2, 3); // 3 + } +} + +[System.Runtime.CompilerServices.InlineArray(10)] +public struct InlineArrays +{ + private int _element0; +}