Skip to content

Commit

Permalink
Merge pull request #49 from Infisical/daniel/dotnet-more-versions
Browse files Browse the repository at this point in the history
Feat: More .NET versions support
  • Loading branch information
DanielHougaard authored Aug 31, 2024
2 parents 57a84dd + d056402 commit 347c7aa
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
70 changes: 70 additions & 0 deletions languages/csharp/Infisical.Sdk/DateTimeTypeForwarding.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#if NETSTANDARD2_0 || NETSTANDARD2_1
using System;
using System.Globalization;

namespace System
{
public struct DateOnly
{
private readonly DateTime _date;

public DateOnly(int year, int month, int day)
{
_date = new DateTime(year, month, day);
}

public static DateOnly Parse(string s)
{
return new DateOnly(DateTime.Parse(s).Ticks);
}

public string ToString(string format)
{
return _date.ToString(format);
}

public override string ToString()
{
return _date.ToString("yyyy-MM-dd");
}

public static implicit operator DateTime(DateOnly dateOnly) => dateOnly._date;
public static explicit operator DateOnly(DateTime dateTime) => new DateOnly(dateTime.Year, dateTime.Month, dateTime.Day);

// Additional constructor for ticks
public DateOnly(long ticks)
{
_date = new DateTime(ticks);
}
}

public struct TimeOnly
{
private readonly TimeSpan _timeSpan;

public TimeOnly(int hour, int minute, int second = 0)
{
_timeSpan = new TimeSpan(hours: hour, minutes: minute, seconds: second);
}

public static TimeOnly Parse(string s)
{
var time = DateTime.Parse(s).TimeOfDay;
return new TimeOnly(time.Hours, time.Minutes, time.Seconds);
}

public string ToString(string format)
{
return DateTime.Today.Add(_timeSpan).ToString(format);
}

public override string ToString()
{
return _timeSpan.ToString(@"hh\:mm\:ss");
}

public static implicit operator TimeSpan(TimeOnly timeOnly) => timeOnly._timeSpan;
public static explicit operator TimeOnly(TimeSpan timeSpan) => new TimeOnly(timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
}
}
#endif
19 changes: 18 additions & 1 deletion languages/csharp/Infisical.Sdk/Infisical.Sdk.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Infisical.Sdk</RootNamespace>
<LangVersion>10.0</LangVersion>


<Title>Infisical SDK</Title>
<Authors>Infisical</Authors>
Expand All @@ -30,6 +32,21 @@
<None Include="../LICENSE.txt" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'netstandard2.1'">
<DefineConstants>$(DefineConstants);NETSTANDARD2_0_OR_GREATER</DefineConstants>
</PropertyGroup>

<!-- Remove files from compilation for non-netstandard targets -->
<ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.0' And '$(TargetFramework)' != 'netstandard2.1'">
<Compile Remove="DateTimeCompatibility.cs" />
</ItemGroup>



<PropertyGroup>
<!--Debugonly-->
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion support/scripts/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async function main() {
rendererOptions: {
namespace: "Infisical.Sdk",
framework: "SystemTextJson",
"csharp-version": "6"
"csharp-version": "5"
}
});
await ensureDir("./languages/csharp/Infisical.Sdk");
Expand Down

0 comments on commit 347c7aa

Please sign in to comment.