Skip to content

Commit e621ce1

Browse files
committed
Multi-target Annotations against .NET Standard 1.0
1 parent 6b69ed3 commit e621ce1

19 files changed

+180
-2
lines changed

Diff for: JsonApiDotNetCore.sln

+15
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JsonApiDotNetCore.Annotatio
5252
EndProject
5353
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DatabasePerTenantExample", "src\Examples\DatabasePerTenantExample\DatabasePerTenantExample.csproj", "{60334658-BE51-43B3-9C4D-F2BBF56C89CE}"
5454
EndProject
55+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AnnotationTests", "test\AnnotationTests\AnnotationTests.csproj", "{24B0C12F-38CD-4245-8785-87BEFAD55B00}"
56+
EndProject
5557
Global
5658
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5759
Debug|Any CPU = Debug|Any CPU
@@ -266,6 +268,18 @@ Global
266268
{60334658-BE51-43B3-9C4D-F2BBF56C89CE}.Release|x64.Build.0 = Release|Any CPU
267269
{60334658-BE51-43B3-9C4D-F2BBF56C89CE}.Release|x86.ActiveCfg = Release|Any CPU
268270
{60334658-BE51-43B3-9C4D-F2BBF56C89CE}.Release|x86.Build.0 = Release|Any CPU
271+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
272+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Debug|Any CPU.Build.0 = Debug|Any CPU
273+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Debug|x64.ActiveCfg = Debug|Any CPU
274+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Debug|x64.Build.0 = Debug|Any CPU
275+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Debug|x86.ActiveCfg = Debug|Any CPU
276+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Debug|x86.Build.0 = Debug|Any CPU
277+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Release|Any CPU.ActiveCfg = Release|Any CPU
278+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Release|Any CPU.Build.0 = Release|Any CPU
279+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Release|x64.ActiveCfg = Release|Any CPU
280+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Release|x64.Build.0 = Release|Any CPU
281+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Release|x86.ActiveCfg = Release|Any CPU
282+
{24B0C12F-38CD-4245-8785-87BEFAD55B00}.Release|x86.Build.0 = Release|Any CPU
269283
EndGlobalSection
270284
GlobalSection(SolutionProperties) = preSolution
271285
HideSolutionNode = FALSE
@@ -288,6 +302,7 @@ Global
288302
{0E0B5C51-F7E2-4F40-A4E4-DED0E9731DC9} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
289303
{83FF097C-C8C6-477B-9FAB-DF99B84978B5} = {7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF}
290304
{60334658-BE51-43B3-9C4D-F2BBF56C89CE} = {026FBC6C-AF76-4568-9B87-EC73457899FD}
305+
{24B0C12F-38CD-4245-8785-87BEFAD55B00} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
291306
EndGlobalSection
292307
GlobalSection(ExtensibilityGlobals) = postSolution
293308
SolutionGuid = {A2421882-8F0A-4905-928F-B550B192F9A4}

Diff for: src/JsonApiDotNetCore.Annotations/JsonApiDotNetCore.Annotations.csproj

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>$(TargetFrameworkName)</TargetFramework>
3+
<TargetFrameworks>$(TargetFrameworkName);netstandard1.0</TargetFrameworks>
44
<IsPackable>true</IsPackable>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
66
<RootNamespace>JsonApiDotNetCore</RootNamespace>
7+
<LangVersion>latest</LangVersion>
78
</PropertyGroup>
89

910
<PropertyGroup>
@@ -27,4 +28,21 @@
2728
<PackagePath></PackagePath>
2829
</None>
2930
</ItemGroup>
31+
32+
<!-- We multi-target against NetStandard solely to enable consumers to share their models project with .NET Framework code. -->
33+
34+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.0' ">
35+
<Using Remove="System.Net.Http" />
36+
</ItemGroup>
37+
38+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.0' ">
39+
<Compile Remove="**/*.cs" />
40+
<Compile Include="**/*.shared.cs" />
41+
<Compile Include="**/*.netstandard.cs" />
42+
</ItemGroup>
43+
44+
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard1.0' ">
45+
<Compile Remove="**/*.netstandard.cs" />
46+
<None Include="**/*.netstandard.cs" />
47+
</ItemGroup>
3048
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using JetBrains.Annotations;
2+
3+
namespace JsonApiDotNetCore.Resources.Annotations;
4+
5+
/// <summary>
6+
/// A simplified version, provided for convenience to multi-target against NetStandard. Does not actually work with JsonApiDotNetCore.
7+
/// </summary>
8+
[PublicAPI]
9+
[AttributeUsage(AttributeTargets.Property)]
10+
public sealed class AttrAttribute : ResourceFieldAttribute
11+
{
12+
/// <summary />
13+
public AttrCapabilities Capabilities { get; set; }
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using JetBrains.Annotations;
2+
3+
namespace JsonApiDotNetCore.Resources.Annotations;
4+
5+
/// <summary>
6+
/// A simplified version, provided for convenience to multi-target against NetStandard. Does not actually work with JsonApiDotNetCore.
7+
/// </summary>
8+
[PublicAPI]
9+
[AttributeUsage(AttributeTargets.Property)]
10+
public sealed class EagerLoadAttribute : Attribute
11+
{
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using JetBrains.Annotations;
2+
3+
namespace JsonApiDotNetCore.Resources.Annotations;
4+
5+
/// <summary>
6+
/// A simplified version, provided for convenience to multi-target against NetStandard. Does not actually work with JsonApiDotNetCore.
7+
/// </summary>
8+
[PublicAPI]
9+
[AttributeUsage(AttributeTargets.Property)]
10+
public sealed class HasManyAttribute : RelationshipAttribute
11+
{
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using JetBrains.Annotations;
2+
3+
namespace JsonApiDotNetCore.Resources.Annotations;
4+
5+
/// <summary>
6+
/// A simplified version, provided for convenience to multi-target against NetStandard. Does not actually work with JsonApiDotNetCore.
7+
/// </summary>
8+
[PublicAPI]
9+
[AttributeUsage(AttributeTargets.Property)]
10+
public sealed class HasOneAttribute : RelationshipAttribute
11+
{
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using JetBrains.Annotations;
2+
3+
namespace JsonApiDotNetCore.Resources.Annotations;
4+
5+
/// <summary>
6+
/// A simplified version, provided for convenience to multi-target against NetStandard. Does not actually work with JsonApiDotNetCore.
7+
/// </summary>
8+
[PublicAPI]
9+
public abstract class RelationshipAttribute : ResourceFieldAttribute
10+
{
11+
/// <summary />
12+
public LinkTypes Links { get; set; } = LinkTypes.NotConfigured;
13+
14+
/// <summary />
15+
public bool CanInclude { get; set; } = true;
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using JetBrains.Annotations;
2+
3+
namespace JsonApiDotNetCore.Resources.Annotations;
4+
5+
/// <summary>
6+
/// A simplified version, provided for convenience to multi-target against NetStandard. Does not actually work with JsonApiDotNetCore.
7+
/// </summary>
8+
[PublicAPI]
9+
public abstract class ResourceFieldAttribute : Attribute
10+
{
11+
/// <summary />
12+
public string PublicName { get; set; } = null!;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace JsonApiDotNetCore.Resources;
2+
3+
/// <summary>
4+
/// A simplified version, provided for convenience to multi-target against NetStandard. Does not actually work with JsonApiDotNetCore.
5+
/// </summary>
6+
public abstract class Identifiable<TId> : IIdentifiable<TId>
7+
{
8+
/// <summary />
9+
public virtual TId Id { get; set; } = default!;
10+
11+
/// <summary />
12+
public string? StringId { get; set; }
13+
14+
/// <summary />
15+
public string? LocalId { get; set; }
16+
}

Diff for: test/AnnotationTests/AnnotationTests.csproj

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>$(TargetFrameworkName);netstandard2.0</TargetFrameworks>
4+
<LangVersion>latest</LangVersion>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<None Update="xunit.runner.json">
9+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
10+
</None>
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\..\src\JsonApiDotNetCore.Annotations\JsonApiDotNetCore.Annotations.csproj" />
15+
</ItemGroup>
16+
</Project>

Diff for: test/AnnotationTests/Models/HiddenNode.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using JetBrains.Annotations;
2+
using JsonApiDotNetCore.Resources;
3+
using JsonApiDotNetCore.Resources.Annotations;
4+
5+
namespace AnnotationTests.Models;
6+
7+
[PublicAPI]
8+
[NoResource]
9+
[ResourceLinks(TopLevelLinks = LinkTypes.None, ResourceLinks = LinkTypes.None, RelationshipLinks = LinkTypes.None)]
10+
public sealed class HiddenNode : Identifiable<Guid>
11+
{
12+
[EagerLoad]
13+
public HiddenNode? Parent { get; set; }
14+
}

Diff for: test/AnnotationTests/Models/TreeNode.cs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using JetBrains.Annotations;
2+
using JsonApiDotNetCore.Controllers;
3+
using JsonApiDotNetCore.Resources;
4+
using JsonApiDotNetCore.Resources.Annotations;
5+
6+
namespace AnnotationTests.Models;
7+
8+
[PublicAPI]
9+
[Resource(PublicName = "tree-node", ControllerNamespace = "Models", GenerateControllerEndpoints = JsonApiEndpoints.Query)]
10+
public sealed class TreeNode : Identifiable<long>
11+
{
12+
[Attr(PublicName = "name", Capabilities = AttrCapabilities.AllowSort)]
13+
public string? DisplayName { get; set; }
14+
15+
[HasOne(PublicName = "orders", CanInclude = true, Links = LinkTypes.All)]
16+
public TreeNode? Parent { get; set; }
17+
18+
[HasMany(PublicName = "orders", CanInclude = true, Links = LinkTypes.All)]
19+
public ISet<TreeNode> Children { get; set; } = new HashSet<TreeNode>();
20+
}

0 commit comments

Comments
 (0)