-
-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathCoreControllerInfo.cs
More file actions
33 lines (27 loc) · 1.46 KB
/
CoreControllerInfo.cs
File metadata and controls
33 lines (27 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using Microsoft.CodeAnalysis;
namespace JsonApiDotNetCore.SourceGenerators;
/// <summary>
/// Basic outcome from the code analysis.
/// </summary>
internal readonly record struct CoreControllerInfo(
TypeInfo ResourceType, TypeInfo IdType, string ControllerNamespace, JsonApiEndpointsCopy Endpoints, bool WriteNullableEnable)
{
// Using readonly fields, so they can be passed by reference (using 'in' modifier, to avoid making copies) during code generation.
public readonly TypeInfo ResourceType = ResourceType;
public readonly TypeInfo IdType = IdType;
public readonly string ControllerNamespace = ControllerNamespace;
public readonly JsonApiEndpointsCopy Endpoints = Endpoints;
public readonly bool WriteNullableEnable = WriteNullableEnable;
public static CoreControllerInfo? TryCreate(INamedTypeSymbol resourceTypeSymbol, ITypeSymbol idTypeSymbol, JsonApiEndpointsCopy endpoints,
string controllerNamespace)
{
TypeInfo? resourceTypeInfo = TypeInfo.CreateFromQualified(resourceTypeSymbol);
TypeInfo? idTypeInfo = TypeInfo.TryCreateFromQualifiedOrPossiblyNullableKeyword(idTypeSymbol);
if (idTypeInfo == null)
{
return null;
}
bool writeNullableEnable = idTypeSymbol is { IsReferenceType: true, NullableAnnotation: NullableAnnotation.Annotated };
return new CoreControllerInfo(resourceTypeInfo.Value, idTypeInfo.Value, controllerNamespace, endpoints, writeNullableEnable);
}
}