Skip to content

Commit b28d6ff

Browse files
committed
fix: readd netstandard target to ensure source generator compat
also added polyfills for language features missing in netstandard2.0
1 parent 12825a4 commit b28d6ff

7 files changed

Lines changed: 41 additions & 8 deletions

File tree

Common.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!-- Common Properties used by all assemblies -->
33
<PropertyGroup>
44
<LangVersion>10</LangVersion>
5-
<TargetFrameworks>netstandard2.1;net8</TargetFrameworks>
5+
<TargetFrameworks>netstandard2.0;netstandard2.1;net8</TargetFrameworks>
66
<ImplicitUsings>disable</ImplicitUsings>
77
<Company>ByteBard</Company>
88
<PackageProjectUrl>https://github.com/ByteBardOrg/AsyncAPI.NET</PackageProjectUrl>

src/ByteBard.AsyncAPI.Readers/ByteBard.AsyncAPI.Readers.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>
17-
<PackageReference Include="System.Text.Json" Version="9.0.1" Condition="'$(TargetFramework)' == 'netstandard2.1'" />
17+
<PackageReference Include="System.Text.Json" Version="9.0.1" Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1'" />
1818
<PackageReference Include="YamlDotNet" Version="13.0.1" />
1919
</ItemGroup>
2020

src/ByteBard.AsyncAPI.Readers/V2/AsyncApiDocumentDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private static void SetOperations(ParsingContext context, AsyncApiDocument docum
8888
if (operation.Value.Channel != null)
8989
{
9090
var messages = context.GetFromTempStorage<Dictionary<string, AsyncApiMessageReference>>(TempStorageKeys.OperationMessageReferences, operation.Value);
91-
var operationChannelFragmentKey = operation.Value.Channel.Reference.Reference.Split("/")[^1];
91+
var operationChannelFragmentKey = operation.Value.Channel.Reference.Reference.Split('/').Last();
9292
var channel = document.Channels.FirstOrDefault(channel => channel.Key == operationChannelFragmentKey);
9393
if (channel.Value == null)
9494
{

src/ByteBard.AsyncAPI.Readers/V2/AsyncApiOperationDeserializer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace ByteBard.AsyncAPI.Readers
22
{
33
using System.Collections.Generic;
4+
using System.Linq;
45
using System.Threading;
56
using ByteBard.AsyncAPI.Extensions;
67
using ByteBard.AsyncAPI.Models;
@@ -47,7 +48,7 @@ private static KeyValuePair<string, AsyncApiMessage> GetMessage(ParseNode node)
4748
var message = LoadMessage(node);
4849
if (message is AsyncApiMessageReference reference)
4950
{
50-
key = reference.Reference.Reference.Split("/")[^1];
51+
key = reference.Reference.Reference.Split('/').Last();
5152
}
5253
else if (messageNode["messageId"] != null)
5354
{

src/ByteBard.AsyncAPI/ByteBard.AsyncAPI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<PrivateAssets>all</PrivateAssets>
1313
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1414
</PackageReference>
15-
<PackageReference Include="System.Text.Json" Version="9.0.1" Condition="'$(TargetFramework)' == 'netstandard2.1'" />
15+
<PackageReference Include="System.Text.Json" Version="9.0.1" Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1'" />
1616

1717
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
1818
<_Parameter1>$(MSBuildProjectName).Tests</_Parameter1>

src/ByteBard.AsyncAPI/Models/References/AsyncApiSecuritySchemeReference.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ public void SerializeAsSecurityRequirement(IAsyncApiWriter writer)
8888
this.Reference.Workspace = writer.Workspace;
8989

9090
writer.WriteStartObject();
91-
92-
writer.WritePropertyName(this.Reference.FragmentId.Split("/")[^1]);
93-
91+
writer.WritePropertyName(this.Reference.FragmentId.Split('/').Last());
9492
writer.WriteStartArray();
9593

9694
if (this.Scopes.Any())

src/ByteBard.AsyncAPI/Polyfill.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespace ByteBard.AsyncAPI;
2+
3+
using System.Collections.Generic;
4+
5+
public static class PolyfillExtensions
6+
{
7+
#if NETSTANDARD2_0
8+
public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source)
9+
{
10+
return new HashSet<T>(source);
11+
}
12+
13+
public static bool TryAdd<TKey, TValue>(this IDictionary<TKey, TValue> source, TKey key, TValue value)
14+
{
15+
if (source.ContainsKey(key))
16+
{
17+
return false;
18+
}
19+
20+
source.Add(key, value);
21+
return true;
22+
}
23+
24+
public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> source, TKey key)
25+
{
26+
if (source.ContainsKey(key))
27+
{
28+
return source[key];
29+
}
30+
31+
return default(TValue);
32+
}
33+
#endif
34+
}

0 commit comments

Comments
 (0)