Skip to content

Commit a13a7da

Browse files
feat(client): support .NET Standard 2.0
1 parent 47ee157 commit a13a7da

26 files changed

+855
-179
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ insert_final_newline = true
2424
dotnet_diagnostic.IDE0060.severity = none # Caused by resource with no methods and no subresources
2525
dotnet_diagnostic.IDE1006.severity = none # Some names may not match up with C# conventions
2626
dotnet_diagnostic.IDE0290.severity = none # Don't prefer primary constructors
27+
28+
# For .NET Standard 2.0 support
29+
dotnet_diagnostic.IDE0057.severity = none # Caused by use of `.Substring(...)`
30+
dotnet_diagnostic.CA1866.severity = none # Caused by use of `.StartsWith(...)` with single character string
31+
dotnet_diagnostic.CA1847.severity = none # Caused by use of `.Contains(...)` with single character string

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
- uses: actions/checkout@v4
5959

6060
- name: Set up .NET
61-
uses: actions/setup-dotnet@v3
61+
uses: actions/setup-dotnet@v5
6262
with:
6363
dotnet-version: '8.0.x'
6464

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ dotnet add reference orb-csharp/src/Orb
2020

2121
## Requirements
2222

23-
This library requires .NET 8 or later.
24-
25-
> [!NOTE]
26-
> The library is currently in **beta**. The requirements will be lowered in the future.
23+
This library requires .NET Standard 2.0 or later.
2724

2825
## Usage
2926

src/Orb.Tests/Orb.Tests.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<!-- Run tests on net8.0, which will use the SDK's net8.0 DLL, and on net462, which will use the
5+
SDK's netstandard2.0 DLL. -->
6+
<TargetFrameworks>net8.0;net462</TargetFrameworks>
7+
<LangVersion>latest</LangVersion>
58

69
<Nullable>enable</Nullable>
710

src/Orb.Tests/Services/CreditNoteServiceTest.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,20 @@ public async Task Create_Works()
1818
{
1919
Amount = "amount",
2020
InvoiceLineItemID = "4khy3nwzktxv7",
21-
EndDate = DateOnly.Parse("2023-09-22"),
22-
StartDate = DateOnly.Parse("2023-09-22"),
21+
EndDate =
22+
#if NET
23+
DateOnly
24+
#else
25+
DateTimeOffset
26+
#endif
27+
.Parse("2023-09-22"),
28+
StartDate =
29+
#if NET
30+
DateOnly
31+
#else
32+
DateTimeOffset
33+
#endif
34+
.Parse("2023-09-22"),
2335
},
2436
],
2537
Reason = Reason.Duplicate,

src/Orb.Tests/Services/Customers/Credits/LedgerServiceTest.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,20 @@ public async Task CreateEntry_Works()
4040
InvoiceSettings = new()
4141
{
4242
AutoCollection = true,
43-
CustomDueDate = DateOnly.Parse("2019-12-27"),
44-
InvoiceDate = DateOnly.Parse("2019-12-27"),
43+
CustomDueDate =
44+
#if NET
45+
DateOnly
46+
#else
47+
DateTimeOffset
48+
#endif
49+
.Parse("2019-12-27"),
50+
InvoiceDate =
51+
#if NET
52+
DateOnly
53+
#else
54+
DateTimeOffset
55+
#endif
56+
.Parse("2019-12-27"),
4557
ItemID = "item_id",
4658
Memo = "memo",
4759
NetTerms = 0,
@@ -81,8 +93,20 @@ public async Task CreateEntryByExternalID_Works()
8193
InvoiceSettings = new()
8294
{
8395
AutoCollection = true,
84-
CustomDueDate = DateOnly.Parse("2019-12-27"),
85-
InvoiceDate = DateOnly.Parse("2019-12-27"),
96+
CustomDueDate =
97+
#if NET
98+
DateOnly
99+
#else
100+
DateTimeOffset
101+
#endif
102+
.Parse("2019-12-27"),
103+
InvoiceDate =
104+
#if NET
105+
DateOnly
106+
#else
107+
DateTimeOffset
108+
#endif
109+
.Parse("2019-12-27"),
86110
ItemID = "item_id",
87111
Memo = "memo",
88112
NetTerms = 0,

src/Orb.Tests/Services/InvoiceLineItemServiceTest.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,22 @@ public async Task Create_Works()
1212
new()
1313
{
1414
Amount = "12.00",
15-
EndDate = DateOnly.Parse("2023-09-22"),
15+
EndDate =
16+
#if NET
17+
DateOnly
18+
#else
19+
DateTimeOffset
20+
#endif
21+
.Parse("2023-09-22"),
1622
InvoiceID = "4khy3nwzktxv7",
1723
Quantity = 1,
18-
StartDate = DateOnly.Parse("2023-09-22"),
24+
StartDate =
25+
#if NET
26+
DateOnly
27+
#else
28+
DateTimeOffset
29+
#endif
30+
.Parse("2023-09-22"),
1931
}
2032
);
2133
invoiceLineItem.Validate();

src/Orb.Tests/Services/InvoiceServiceTest.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,24 @@ public async Task Create_Works()
1818
[
1919
new()
2020
{
21-
EndDate = DateOnly.Parse("2023-09-22"),
21+
EndDate =
22+
#if NET
23+
DateOnly
24+
#else
25+
DateTimeOffset
26+
#endif
27+
.Parse("2023-09-22"),
2228
ItemID = "4khy3nwzktxv7",
2329
ModelType = ModelType.Unit,
2430
Name = "Line Item Name",
2531
Quantity = 1,
26-
StartDate = DateOnly.Parse("2023-09-22"),
32+
StartDate =
33+
#if NET
34+
DateOnly
35+
#else
36+
DateTimeOffset
37+
#endif
38+
.Parse("2023-09-22"),
2739
UnitConfig = new() { UnitAmount = "unit_amount", Prorated = true },
2840
},
2941
],
@@ -74,7 +86,13 @@ public async Task MarkPaid_Works()
7486
{
7587
var invoice = await this.client.Invoices.MarkPaid(
7688
"invoice_id",
77-
new() { PaymentReceivedDate = DateOnly.Parse("2023-09-22") }
89+
new() { PaymentReceivedDate =
90+
#if NET
91+
DateOnly
92+
#else
93+
DateTimeOffset
94+
#endif
95+
.Parse("2023-09-22") }
7896
);
7997
invoice.Validate();
8098
}

src/Orb/Core/ApiEnum.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public readonly TEnum Value() =>
1919

2020
public readonly void Validate()
2121
{
22-
if (!Enum.IsDefined(Value()))
22+
if (!Enum.IsDefined(typeof(TEnum), Value()))
2323
{
2424
throw new OrbInvalidDataException("Invalid enum value");
2525
}

src/Orb/Core/FreezableDictionary.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Frozen;
33
using System.Collections.Generic;
44
using System.Diagnostics.CodeAnalysis;
5+
using System.Linq;
56
using Collections = System.Collections;
67

78
namespace Orb.Core;
@@ -34,7 +35,7 @@ public FreezableDictionary() { }
3435

3536
public FreezableDictionary(IReadOnlyDictionary<K, V> dictionary)
3637
{
37-
_dictionary = new Dictionary<K, V>(dictionary);
38+
_dictionary = Enumerable.ToDictionary(dictionary, e => e.Key, e => e.Value);
3839
}
3940

4041
public FreezableDictionary(FrozenDictionary<K, V> frozen)
@@ -126,7 +127,12 @@ public bool Remove(KeyValuePair<K, V> item)
126127
return _mutableDictionary.Remove(item.Key);
127128
}
128129

129-
public bool TryGetValue(K key, [MaybeNullWhenAttribute(false)] out V value)
130+
public bool TryGetValue(K key,
131+
#if NET
132+
[MaybeNullWhen(false)]
133+
#endif
134+
135+
out V value)
130136
{
131137
return _dictionary.TryGetValue(key, out value);
132138
}

0 commit comments

Comments
 (0)