diff --git a/languages/csharp/Infisical.Sdk/DateTimeTypeForwarding.cs b/languages/csharp/Infisical.Sdk/DateTimeTypeForwarding.cs new file mode 100644 index 0000000..a60d261 --- /dev/null +++ b/languages/csharp/Infisical.Sdk/DateTimeTypeForwarding.cs @@ -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 \ No newline at end of file diff --git a/languages/csharp/Infisical.Sdk/Infisical.Sdk.csproj b/languages/csharp/Infisical.Sdk/Infisical.Sdk.csproj index 3cd160f..e34cd93 100644 --- a/languages/csharp/Infisical.Sdk/Infisical.Sdk.csproj +++ b/languages/csharp/Infisical.Sdk/Infisical.Sdk.csproj @@ -1,10 +1,12 @@ - net8.0 + netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0 enable enable Infisical.Sdk + 10.0 + Infisical SDK Infisical @@ -30,6 +32,21 @@ + + + + + + $(DefineConstants);NETSTANDARD2_0_OR_GREATER + + + + + + + + + diff --git a/support/scripts/schemas.ts b/support/scripts/schemas.ts index ae41242..3533967 100644 --- a/support/scripts/schemas.ts +++ b/support/scripts/schemas.ts @@ -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");