Skip to content

Commit 2a18f7e

Browse files
authored
Expanded coverage of AspNetCore minimal API surface. (#59)
1 parent 7018fa3 commit 2a18f7e

File tree

226 files changed

+10441
-948
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

226 files changed

+10441
-948
lines changed

.github/workflows/develop.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ jobs:
1515
contents: read
1616
security-events: write
1717

18-
strategy:
19-
fail-fast: false
20-
2118
steps:
2219
- name: Checkout repository
2320
uses: actions/checkout@v4
@@ -27,10 +24,10 @@ jobs:
2724
with:
2825
languages: 'csharp'
2926

30-
- name: Setup .NET 9.0
27+
- name: Setup .NET 10.0
3128
uses: actions/setup-dotnet@v4
3229
with:
33-
dotnet-version: 9.x
30+
dotnet-version: 10.x
3431

3532
- name: Restore dependencies
3633
run: dotnet restore
@@ -39,7 +36,7 @@ jobs:
3936
run: dotnet build --configuration Release --no-restore
4037

4138
- name: Test
42-
run: dotnet test ./tests/GeneratedEndpoints.Tests/GeneratedEndpoints.Tests.csproj --configuration Release --no-build --verbosity normal --framework net9.0
39+
run: dotnet test ./tests/GeneratedEndpoints.Tests/GeneratedEndpoints.Tests.csproj --configuration Release --no-build --verbosity normal --framework net10.0
4340

4441
- name: Perform CodeQL analysis
4542
uses: github/codeql-action/analyze@v3

.github/workflows/publish.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@ jobs:
1313
contents: read
1414
security-events: write
1515

16-
strategy:
17-
fail-fast: false
18-
1916
steps:
2017
- name: Checkout repository
2118
uses: actions/checkout@v4
2219

23-
- name: Setup .NET 9.0
20+
- name: Setup .NET 10.0
2421
uses: actions/setup-dotnet@v4
2522
with:
26-
dotnet-version: 9.x
23+
dotnet-version: 10.x
2724

2825
- name: Restore dependencies
2926
run: dotnet restore

GeneratedEndpoints.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeneratedEndpoints.Tests",
66
EndProject
77
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeneratedEndpoints", "src\GeneratedEndpoints\GeneratedEndpoints.csproj", "{2F54865E-0F46-416B-A18D-C6C2ACF912B2}"
88
EndProject
9+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeneratedEndpoints.Tests.Lab", "tests\GeneratedEndpoints.Tests.Lab\GeneratedEndpoints.Tests.Lab.csproj", "{2E39D0D0-B4C7-4A28-94E0-067E3B0902E2}"
10+
EndProject
911
Global
1012
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1113
Debug|Any CPU = Debug|Any CPU
@@ -20,8 +22,13 @@ Global
2022
{2F54865E-0F46-416B-A18D-C6C2ACF912B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
2123
{2F54865E-0F46-416B-A18D-C6C2ACF912B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
2224
{2F54865E-0F46-416B-A18D-C6C2ACF912B2}.Release|Any CPU.Build.0 = Release|Any CPU
25+
{2E39D0D0-B4C7-4A28-94E0-067E3B0902E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26+
{2E39D0D0-B4C7-4A28-94E0-067E3B0902E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
27+
{2E39D0D0-B4C7-4A28-94E0-067E3B0902E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{2E39D0D0-B4C7-4A28-94E0-067E3B0902E2}.Release|Any CPU.Build.0 = Release|Any CPU
2329
EndGlobalSection
2430
GlobalSection(NestedProjects) = preSolution
2531
{01E8E43A-EA5C-4F28-BAAE-A3EB7861B57E} = {F1E3D1D7-B9E4-4EFF-8FD5-2A735A4695B4}
32+
{2E39D0D0-B4C7-4A28-94E0-067E3B0902E2} = {F1E3D1D7-B9E4-4EFF-8FD5-2A735A4695B4}
2633
EndGlobalSection
2734
EndGlobal

README.md

Lines changed: 115 additions & 93 deletions
Large diffs are not rendered by default.

global.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"sdk": {
3+
"version": "10.0.0",
4+
"rollForward": "latestMajor",
5+
"allowPrerelease": false
6+
}
7+
}

src/GeneratedEndpoints/Common/EquatableImmutableArray.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ public static EquatableImmutableArray<T> ToEquatableImmutableArray<T>(this Immut
2626
/// <returns>An <see cref="EquatableImmutableArray{T}"/> containing the same elements as the original enumerable.</returns>
2727
public static EquatableImmutableArray<T> ToEquatableImmutableArray<T>(this IEnumerable<T> enumerable)
2828
{
29-
return new EquatableImmutableArray<T>(enumerable.ToImmutableArray());
29+
return new EquatableImmutableArray<T>([..enumerable]);
3030
}
3131
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Text;
2+
3+
namespace GeneratedEndpoints.Common;
4+
5+
/// <summary>Provides a simple per-thread cache for <see cref="StringBuilder"/> instances.</summary>
6+
internal static class StringBuilderPool
7+
{
8+
private const int MaxBuilderCapacity = 128 * 1024;
9+
10+
[ThreadStatic]
11+
private static StringBuilder? _cachedInstance;
12+
13+
/// <summary>Gets a <see cref="StringBuilder"/> with at least the requested capacity.</summary>
14+
public static StringBuilder Get(int capacity = 16)
15+
{
16+
var builder = _cachedInstance;
17+
if (builder is null)
18+
return new StringBuilder(capacity);
19+
20+
_cachedInstance = null;
21+
builder.Clear();
22+
if (builder.Capacity < capacity)
23+
builder.EnsureCapacity(capacity);
24+
25+
return builder;
26+
}
27+
28+
/// <summary>Returns the <see cref="StringBuilder"/> to the pool if it is below the maximum retention size.</summary>
29+
public static void Return(StringBuilder builder)
30+
{
31+
if (builder.Capacity > MaxBuilderCapacity)
32+
return;
33+
34+
builder.Clear();
35+
if (_cachedInstance is null)
36+
_cachedInstance = builder;
37+
}
38+
39+
/// <summary>Converts the builder to a string and returns it to the pool.</summary>
40+
public static string ToStringAndReturn(StringBuilder builder)
41+
{
42+
var result = builder.ToString();
43+
Return(builder);
44+
return result;
45+
}
46+
}

src/GeneratedEndpoints/Common/TypeSymbolExtensions.cs

Lines changed: 0 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -2,194 +2,8 @@
22

33
namespace GeneratedEndpoints.Common;
44

5-
/// <summary>Provides extension methods for working with type symbols.</summary>
65
internal static class TypeSymbolExtensions
76
{
8-
public static bool IsFromRouteAttribute(this ITypeSymbol symbol)
9-
{
10-
return symbol is INamedTypeSymbol
11-
{
12-
MetadataName: "FromRouteAttribute",
13-
ContainingNamespace:
14-
{
15-
Name: "Mvc",
16-
ContainingNamespace:
17-
{
18-
Name: "AspNetCore",
19-
ContainingNamespace:
20-
{
21-
Name: "Microsoft",
22-
ContainingNamespace.IsGlobalNamespace: true,
23-
},
24-
},
25-
},
26-
};
27-
}
28-
29-
public static bool IsFromQueryAttribute(this ITypeSymbol symbol)
30-
{
31-
return symbol is INamedTypeSymbol
32-
{
33-
MetadataName: "FromQueryAttribute",
34-
ContainingNamespace:
35-
{
36-
Name: "Mvc",
37-
ContainingNamespace:
38-
{
39-
Name: "AspNetCore",
40-
ContainingNamespace:
41-
{
42-
Name: "Microsoft",
43-
ContainingNamespace.IsGlobalNamespace: true,
44-
},
45-
},
46-
},
47-
};
48-
}
49-
50-
public static bool IsFromHeaderAttribute(this ITypeSymbol symbol)
51-
{
52-
return symbol is INamedTypeSymbol
53-
{
54-
MetadataName: "FromHeaderAttribute",
55-
ContainingNamespace:
56-
{
57-
Name: "Mvc",
58-
ContainingNamespace:
59-
{
60-
Name: "AspNetCore",
61-
ContainingNamespace:
62-
{
63-
Name: "Microsoft",
64-
ContainingNamespace.IsGlobalNamespace: true,
65-
},
66-
},
67-
},
68-
};
69-
}
70-
71-
public static bool IsFromBodyAttribute(this ITypeSymbol symbol)
72-
{
73-
return symbol is INamedTypeSymbol
74-
{
75-
MetadataName: "FromBodyAttribute",
76-
ContainingNamespace:
77-
{
78-
Name: "Mvc",
79-
ContainingNamespace:
80-
{
81-
Name: "AspNetCore",
82-
ContainingNamespace:
83-
{
84-
Name: "Microsoft",
85-
ContainingNamespace.IsGlobalNamespace: true,
86-
},
87-
},
88-
},
89-
};
90-
}
91-
92-
public static bool IsFromFormAttribute(this ITypeSymbol symbol)
93-
{
94-
return symbol is INamedTypeSymbol
95-
{
96-
MetadataName: "FromFormAttribute",
97-
ContainingNamespace:
98-
{
99-
Name: "Mvc",
100-
ContainingNamespace:
101-
{
102-
Name: "AspNetCore",
103-
ContainingNamespace:
104-
{
105-
Name: "Microsoft",
106-
ContainingNamespace.IsGlobalNamespace: true,
107-
},
108-
},
109-
},
110-
};
111-
}
112-
113-
public static bool IsFromServicesAttribute(this ITypeSymbol symbol)
114-
{
115-
return symbol is INamedTypeSymbol
116-
{
117-
MetadataName: "FromServicesAttribute",
118-
ContainingNamespace:
119-
{
120-
Name: "Mvc",
121-
ContainingNamespace:
122-
{
123-
Name: "AspNetCore",
124-
ContainingNamespace:
125-
{
126-
Name: "Microsoft",
127-
ContainingNamespace.IsGlobalNamespace: true,
128-
},
129-
},
130-
},
131-
};
132-
}
133-
134-
public static bool IsFromKeyedServicesAttribute(this ITypeSymbol symbol)
135-
{
136-
return symbol is INamedTypeSymbol
137-
{
138-
MetadataName: "FromKeyedServicesAttribute",
139-
ContainingNamespace:
140-
{
141-
Name: "Mvc",
142-
ContainingNamespace:
143-
{
144-
Name: "AspNetCore",
145-
ContainingNamespace:
146-
{
147-
Name: "Microsoft",
148-
ContainingNamespace.IsGlobalNamespace: true,
149-
},
150-
},
151-
},
152-
};
153-
}
154-
155-
public static bool IsAsParametersAttribute(this ITypeSymbol symbol)
156-
{
157-
return symbol is INamedTypeSymbol
158-
{
159-
MetadataName: "AsParametersAttribute",
160-
ContainingNamespace:
161-
{
162-
Name: "Http",
163-
ContainingNamespace:
164-
{
165-
Name: "AspNetCore",
166-
ContainingNamespace:
167-
{
168-
Name: "Microsoft",
169-
ContainingNamespace.IsGlobalNamespace: true,
170-
},
171-
},
172-
},
173-
};
174-
}
175-
176-
public static bool IsCancellationToken(this ITypeSymbol symbol)
177-
{
178-
return symbol is INamedTypeSymbol
179-
{
180-
MetadataName: "CancellationToken",
181-
ContainingNamespace:
182-
{
183-
Name: "Threading",
184-
ContainingNamespace:
185-
{
186-
Name: "System",
187-
ContainingNamespace.IsGlobalNamespace: true,
188-
},
189-
},
190-
};
191-
}
192-
1937
public static bool IsValueTask(this ITypeSymbol symbol, out INamedTypeSymbol valueTaskSymbol)
1948
{
1959
if (symbol is INamedTypeSymbol

src/GeneratedEndpoints/GeneratedEndpoints.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<!-- References -->
2222
<ItemGroup>
23-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.1" PrivateAssets="all"/>
23+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" PrivateAssets="all" />
2424
<PackageReference Include="PolySharp" Version="1.15.0">
2525
<PrivateAssets>all</PrivateAssets>
2626
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -36,9 +36,9 @@
3636
<!-- Output -->
3737
<PropertyGroup>
3838
<AssemblyName>GeneratedEndpoints</AssemblyName>
39-
<Version>9.0.0-preview.1</Version>
40-
<AssemblyVersion>9.0.0.0</AssemblyVersion>
41-
<FileVersion>9.0.0.0</FileVersion>
39+
<Version>10.0.0</Version>
40+
<AssemblyVersion>10.0.0.0</AssemblyVersion>
41+
<FileVersion>10.0.0.0</FileVersion>
4242
<NeutralLanguage>en-US</NeutralLanguage>
4343
<IncludeBuildOutput>false</IncludeBuildOutput>
4444
</PropertyGroup>

0 commit comments

Comments
 (0)